[Libreoffice-commits] .: 2 commits - salhelper/source sal/osl
Stephan Bergmann
sbergmann at kemper.freedesktop.org
Thu Feb 23 23:21:36 PST 2012
sal/osl/unx/thread.c | 70 +-------------------------------------------
salhelper/source/thread.cxx | 11 +++++-
2 files changed, 11 insertions(+), 70 deletions(-)
New commits:
commit fd7912d0b58c71dd15d23d99aa7b8ca157d2aeb1
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Fri Feb 24 08:20:01 2012 +0100
We never call pthread_cancel, so no need to guard against it
diff --git a/sal/osl/unx/thread.c b/sal/osl/unx/thread.c
index 59a0514..d978558 100644
--- a/sal/osl/unx/thread.c
+++ b/sal/osl/unx/thread.c
@@ -133,14 +133,11 @@ static Thread_Impl* osl_thread_construct_Impl (void);
static void osl_thread_destruct_Impl (Thread_Impl ** ppImpl);
static void* osl_thread_start_Impl (void * pData);
-static void osl_thread_cleanup_Impl (void * pData);
+static void osl_thread_cleanup_Impl (Thread_Impl * pImpl);
static oslThread osl_thread_create_Impl (
oslWorkerFunction pWorker, void * pThreadData, short nFlags);
-static void osl_thread_join_cleanup_Impl (void * opaque);
-static void osl_thread_wait_cleanup_Impl (void * opaque);
-
/* @@@ see TODO @@@ */
static sal_uInt16 insertThreadId (pthread_t hThread);
static sal_uInt16 lookupThreadId (pthread_t hThread);
@@ -156,24 +153,6 @@ static void osl_thread_init_Impl (void)
}
/*****************************************************************************/
-/* osl_thread_join_cleanup_Impl */
-/*****************************************************************************/
-static void osl_thread_join_cleanup_Impl (void * opaque)
-{
- pthread_t hThread = (pthread_t)(opaque);
- pthread_detach (hThread);
-}
-
-/*****************************************************************************/
-/* osl_thread_wait_cleanup_Impl */
-/*****************************************************************************/
-static void osl_thread_wait_cleanup_Impl (void * opaque)
-{
- pthread_mutex_t * pMutex = (pthread_mutex_t*)(opaque);
- pthread_mutex_unlock (pMutex);
-}
-
-/*****************************************************************************/
/* osl_thread_construct_Impl */
/*****************************************************************************/
Thread_Impl* osl_thread_construct_Impl (void)
@@ -208,12 +187,11 @@ static void osl_thread_destruct_Impl (Thread_Impl ** ppImpl)
/*****************************************************************************/
/* osl_thread_cleanup_Impl */
/*****************************************************************************/
-static void osl_thread_cleanup_Impl (void* pData)
+static void osl_thread_cleanup_Impl (Thread_Impl * pImpl)
{
pthread_t thread;
int attached;
int destroyed;
- Thread_Impl* pImpl= (Thread_Impl*)pData;
pthread_mutex_lock (&(pImpl->m_Lock));
@@ -241,14 +219,6 @@ static void osl_thread_cleanup_Impl (void* pData)
/*****************************************************************************/
/* osl_thread_start_Impl */
/*****************************************************************************/
-#if defined __GNUC__
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
-#pragma GCC diagnostic push
-#endif
-#pragma GCC diagnostic ignored "-Wshadow"
-#endif
-#endif
static void* osl_thread_start_Impl (void* pData)
{
int terminate;
@@ -258,9 +228,6 @@ static void* osl_thread_start_Impl (void* pData)
pthread_mutex_lock (&(pImpl->m_Lock));
- /* install cleanup handler */
- pthread_cleanup_push (osl_thread_cleanup_Impl, pData);
-
/* request oslThreadIdentifier @@@ see TODO @@@ */
pImpl->m_Ident = insertThreadId (pImpl->m_hThread);
@@ -272,17 +239,8 @@ static void* osl_thread_start_Impl (void* pData)
/* Check if thread is started in SUSPENDED state */
while (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
{
-#ifdef ANDROID
-/* Avoid compiler warning: declaration of '__cleanup' shadows a previous local */
-#define __cleanup __cleanup_2
-#endif
/* wait until SUSPENDED flag is cleared */
- pthread_cleanup_push (osl_thread_wait_cleanup_Impl, &(pImpl->m_Lock));
pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
- pthread_cleanup_pop (0);
-#ifdef ANDROID
-#undef __cleanup
-#endif
}
/* check for SUSPENDED to TERMINATE state change */
@@ -310,15 +268,9 @@ static void* osl_thread_start_Impl (void* pData)
#endif
}
- /* call cleanup handler and leave */
- pthread_cleanup_pop (1);
+ osl_thread_cleanup_Impl (pImpl);
return (0);
}
-#if defined __GNUC__
-#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
-#pragma GCC diagnostic pop
-#endif
-#endif
/*****************************************************************************/
/* osl_thread_create_Impl */
@@ -381,9 +333,7 @@ static oslThread osl_thread_create_Impl (
while (pImpl->m_Flags & THREADIMPL_FLAGS_STARTUP)
{
/* wait until STARTUP flag is cleared */
- pthread_cleanup_push (osl_thread_wait_cleanup_Impl, &(pImpl->m_Lock));
pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
- pthread_cleanup_pop (0);
}
pthread_mutex_unlock (&(pImpl->m_Lock));
@@ -480,9 +430,7 @@ void SAL_CALL osl_suspendThread(oslThread Thread)
while (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
{
/* wait until SUSPENDED flag is cleared */
- pthread_cleanup_push (osl_thread_wait_cleanup_Impl, &(pImpl->m_Lock));
pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
- pthread_cleanup_pop (0);
}
}
@@ -536,15 +484,7 @@ void SAL_CALL osl_joinWithThread(oslThread Thread)
if (attached)
{
- /* install cleanup handler to ensure consistent flags and state */
- pthread_cleanup_push (
- osl_thread_join_cleanup_Impl, (void*)thread);
-
- /* join */
pthread_join (thread, NULL);
-
- /* remove cleanup handler */
- pthread_cleanup_pop (0);
}
}
@@ -589,21 +529,17 @@ sal_Bool SAL_CALL osl_scheduleThread(oslThread Thread)
if (!(pthread_equal (pthread_self(), pImpl->m_hThread)))
return sal_False; /* EINVAL */
- pthread_testcancel();
pthread_mutex_lock (&(pImpl->m_Lock));
while (pImpl->m_Flags & THREADIMPL_FLAGS_SUSPENDED)
{
/* wait until SUSPENDED flag is cleared */
- pthread_cleanup_push (osl_thread_wait_cleanup_Impl, &(pImpl->m_Lock));
pthread_cond_wait (&(pImpl->m_Cond), &(pImpl->m_Lock));
- pthread_cleanup_pop (0);
}
terminate = ((pImpl->m_Flags & THREADIMPL_FLAGS_TERMINATE) > 0);
pthread_mutex_unlock(&(pImpl->m_Lock));
- pthread_testcancel();
return (terminate == 0);
}
commit ebf3bb71c325fb23b4519ce6478e9186d4e82927
Author: Stephan Bergmann <sbergman at redhat.com>
Date: Fri Feb 24 08:18:51 2012 +0100
salhelper::Thread::launch: check create() failure
The assumption in the comment is clearly wrong, as osl::Thread::create
returns a boolean result to indicate failure.
Slight modification of a patch by Michael Stahl <mstahl at redhat.com>.
diff --git a/salhelper/source/thread.cxx b/salhelper/source/thread.cxx
index bf7c1f1..aaad063 100644
--- a/salhelper/source/thread.cxx
+++ b/salhelper/source/thread.cxx
@@ -29,6 +29,9 @@
#include "sal/config.h"
+#include <stdexcept>
+#include <string>
+
#include "sal/log.hxx"
#include "salhelper/thread.hxx"
@@ -36,11 +39,13 @@ salhelper::Thread::Thread(char const * name): name_(name) {}
void salhelper::Thread::launch() {
SAL_INFO("salhelper.thread", "launch " << name_);
- // Assumption is that osl::Thread::create returns normally iff it causes
- // osl::Thread::run to start executing:
+ // Assumption is that osl::Thread::create returns normally with a true
+ // return value iff it causes osl::Thread::run to start executing:
acquire();
try {
- create();
+ if (!create()) {
+ throw std::runtime_error("osl::Thread::create failed");
+ }
} catch (...) {
release();
throw;
More information about the Libreoffice-commits
mailing list