diff options
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/rtl/malformeduriexception.hxx | 18 | ||||
-rw-r--r-- | sal/inc/sal/types.h | 14 | ||||
-rw-r--r-- | sal/osl/unx/mutex.c | 280 |
3 files changed, 49 insertions, 263 deletions
diff --git a/sal/inc/rtl/malformeduriexception.hxx b/sal/inc/rtl/malformeduriexception.hxx index 4f8075684b6c..97cb82bda043 100644 --- a/sal/inc/rtl/malformeduriexception.hxx +++ b/sal/inc/rtl/malformeduriexception.hxx @@ -39,7 +39,7 @@ namespace rtl { <P>Used when parsing (part of) a URI fails for syntactical reasons.</P> */ -class MalformedUriException +class SAL_EXCEPTION_DLLPUBLIC_EXPORT MalformedUriException { public: /** Create a MalformedUriException. @@ -47,8 +47,17 @@ public: @param rMessage A message containing any details about the exception. */ - inline MalformedUriException(rtl::OUString const & rMessage): - m_aMessage(rMessage) {} + inline SAL_EXCEPTION_DLLPRIVATE MalformedUriException( + rtl::OUString const & rMessage): m_aMessage(rMessage) {} + + inline SAL_EXCEPTION_DLLPRIVATE MalformedUriException( + MalformedUriException const & other): m_aMessage(other.m_aMessage) {} + + inline SAL_EXCEPTION_DLLPRIVATE ~MalformedUriException() {} + + inline SAL_EXCEPTION_DLLPRIVATE MalformedUriException operator =( + MalformedUriException const & other) + { m_aMessage = other.m_aMessage; return *this; } /** Get the message. @@ -56,7 +65,8 @@ public: A reference to the message. The reference is valid for the lifetime of this MalformedUriException. */ - inline rtl::OUString const & getMessage() const { return m_aMessage; } + inline SAL_EXCEPTION_DLLPRIVATE rtl::OUString const & getMessage() const + { return m_aMessage; } private: rtl::OUString m_aMessage; diff --git a/sal/inc/sal/types.h b/sal/inc/sal/types.h index 099f5405df34..23c7529eed26 100644 --- a/sal/inc/sal/types.h +++ b/sal/inc/sal/types.h @@ -281,6 +281,20 @@ typedef void * sal_Handle; # error("unknown platform") #endif +/** + Exporting the symbols necessary for exception handling on GCC. + + These macros are used for inline declarations of exception classes, as in + rtl/malformeduriexception.hxx. +*/ +#if defined __GNUC__ +#define SAL_EXCEPTION_DLLPUBLIC_EXPORT SAL_DLLPUBLIC_EXPORT +#define SAL_EXCEPTION_DLLPRIVATE SAL_DLLPRIVATE +#else +#define SAL_EXCEPTION_DLLPUBLIC_EXPORT +#define SAL_EXCEPTION_DLLPRIVATE +#endif + /** Use this for pure virtual classes, e.g. class SAL_NO_VTABLE Foo { ... This hinders the compiler from setting a generic vtable stating that a pure virtual function was called and thus slightly reduces code size. diff --git a/sal/osl/unx/mutex.c b/sal/osl/unx/mutex.c index 298ad010ded9..4504891339e1 100644 --- a/sal/osl/unx/mutex.c +++ b/sal/osl/unx/mutex.c @@ -34,6 +34,13 @@ #include <osl/diagnose.h> #include <pthread.h> +#include <stdlib.h> + +#if defined LINUX /* bad hack */ +int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int); +#define pthread_mutexattr_settype pthread_mutexattr_setkind_np +#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP +#endif /* Implementation notes: @@ -42,19 +49,6 @@ */ - -/*#if defined(PTHREAD_MUTEX_RECURSIVE) && defined(USE_RECURSIVE_MUTEX)*/ -#ifdef LINUX - -// The obsolete pthread_mutex_setkind_np (used below in osl_createMutex) seems -// to be missing from pthread.h on LINUX: -int pthread_mutexattr_setkind_np(pthread_mutexattr_t *, int); - -/* - * Linux fully supports recursive mutexes, but only with - * a non-standard function. So we linux, we use system recursive mutexes. - */ - typedef struct _oslMutexImpl { pthread_mutex_t mutex; @@ -79,8 +73,7 @@ oslMutex SAL_CALL osl_createMutex() pthread_mutexattr_init(&aMutexAttr); -// nRet = pthread_mutexattr_settype(&aMutexAttr, PTHREAD_MUTEX_RECURSIVE); - nRet = pthread_mutexattr_setkind_np( &aMutexAttr, PTHREAD_MUTEX_RECURSIVE_NP ); + nRet = pthread_mutexattr_settype(&aMutexAttr, PTHREAD_MUTEX_RECURSIVE); nRet = pthread_mutex_init(&(pMutex->mutex), &aMutexAttr); if ( nRet != 0 ) @@ -204,259 +197,28 @@ sal_Bool SAL_CALL osl_releaseMutex(oslMutex Mutex) /* osl_getGlobalMutex */ /*****************************************************************************/ -oslMutex * SAL_CALL osl_getGlobalMutex() -{ - /* the static global mutex instance */ - static oslMutexImpl globalMutexImpl = { - PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP - }; - - /* necessary to get a "oslMutex *" */ - static oslMutex globalMutex = (oslMutex) &globalMutexImpl; - - return &globalMutex; -} - -#else /* SOLARIS and all other platforms, use an own implementation of - resursive mutexes */ -/* - * jbu: Currently not used for solaris. The default implementation is buggy, - * the system needs to be patched to - * SPARC X86 - * Solaris 7: 106980-17 106981-18 - * Solaris 8: 108827-11 108828-11 - * - * As the performace advantage is not too high, it was decided to wait - * some more time. Note also, that solaris 2.6 does not support - * them at all. - */ - -#ifdef PTHREAD_NONE_INIT -static pthread_t _pthread_none_ = PTHREAD_NONE_INIT; -#endif - -typedef struct _oslMutexImpl -{ - pthread_mutex_t mutex; - pthread_t owner; - sal_uInt32 locks; -} oslMutexImpl; - - -/*****************************************************************************/ -/* osl_createMutex */ -/*****************************************************************************/ -oslMutex SAL_CALL osl_createMutex() -{ - oslMutexImpl* pMutex = (oslMutexImpl*) malloc(sizeof(oslMutexImpl)); - int nRet=0; - - OSL_ASSERT(pMutex); - - if ( pMutex == 0 ) - { - return 0; - } - - nRet = pthread_mutex_init(&(pMutex->mutex), PTHREAD_MUTEXATTR_DEFAULT); - if ( nRet != 0 ) - { - OSL_TRACE("osl_createMutex : mutex init failed. Errno: %d; %s\n", - nRet, strerror(nRet)); - - free(pMutex); - return 0; - } - - pMutex->owner = PTHREAD_NONE; - pMutex->locks = 0; - - return (oslMutex) pMutex; -} - -/*****************************************************************************/ -/* osl_destroyMutex */ -/*****************************************************************************/ -void SAL_CALL osl_destroyMutex(oslMutex Mutex) -{ - oslMutexImpl* pMutex = (oslMutexImpl*) Mutex; - - OSL_ASSERT(pMutex); - - if ( pMutex != NULL ) - { - int nRet=0; - - nRet = pthread_mutex_destroy(&(pMutex->mutex)); - if ( nRet != 0 ) - { - OSL_TRACE("osl_destroyMutex : mutex destroy failed. Errno: %d; %s\n", - nRet, strerror(nRet)); - } - - free(pMutex); - } - - return; -} - -/*****************************************************************************/ -/* osl_acquireMutex */ -/*****************************************************************************/ -sal_Bool SAL_CALL osl_acquireMutex(oslMutex Mutex) -{ - oslMutexImpl* pMutex = (oslMutexImpl*) Mutex; - - OSL_ASSERT(pMutex); - - if ( pMutex ) - { - int nRet=0; - - pthread_t thread_id = pthread_self(); - - if ( pthread_equal(pMutex->owner, thread_id ) ) - { - pMutex->locks++; -/* fprintf(stderr,"osl_acquireMutex 0x%08X (locks == %i) from %i to thread %i (lock inc)\n", - pMutex,pMutex->locks,pMutex->owner,pthread_self());*/ - } - else - { - nRet = pthread_mutex_lock(&(pMutex->mutex)); - if ( nRet != 0 ) - { - OSL_TRACE("osl_acquireMutex : mutex lock failed. Errno: %d; %s\n", - nRet, strerror(nRet)); - } - -/* fprintf(stderr,"osl_acquireMutex 0x%08X (locks == %i) from %i to thread %i\n", - pMutex,pMutex->locks,pMutex->owner,thread_id);*/ - OSL_ASSERT( pMutex->locks == 0 ); - - pMutex->owner = thread_id; - } - - return sal_True; - } - - /* not initialized */ - return sal_False; -} - -/*****************************************************************************/ -/* osl_tryToAcquireMutex */ -/*****************************************************************************/ -sal_Bool SAL_CALL osl_tryToAcquireMutex(oslMutex Mutex) -{ - oslMutexImpl* pMutex = (oslMutexImpl*) Mutex; - - OSL_ASSERT(pMutex); - - if ( pMutex ) - { - int nRet = 0; - if ( pthread_equal(pMutex->owner, pthread_self()) ) - { - pMutex->locks++; - } - else - { - nRet = pthread_mutex_trylock(&(pMutex->mutex)); - if ( nRet != 0 ) - { - OSL_TRACE("osl_tryToacquireMutex : mutex trylock failed. Errno: %d; %s\n", - nRet, strerror(nRet)); - return sal_False; - } - - OSL_ASSERT( pMutex->locks == 0 ); - - pMutex->owner = pthread_self(); - } - return sal_True; - } - - /* not initialized */ - return sal_False; -} - -/*****************************************************************************/ -/* osl_releaseMutex */ -/*****************************************************************************/ -sal_Bool SAL_CALL osl_releaseMutex(oslMutex Mutex) -{ - oslMutexImpl* pMutex = (oslMutexImpl*) Mutex; - int nRet=0; - - OSL_ASSERT(pMutex); +static oslMutexImpl globalMutexImpl; - if ( pMutex ) +static void globalMutexInitImpl(void) { + pthread_mutexattr_t attr; + if (pthread_mutexattr_init(&attr) != 0 || + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE) || + pthread_mutex_init(&globalMutexImpl.mutex, &attr) != 0 || + pthread_mutexattr_destroy(&attr) != 0) { - if ( pthread_equal( pMutex->owner, pthread_self()) ) - { - if ( pMutex->locks > 0 ) - { - pMutex->locks--; -/* fprintf(stderr,"osl_releaseMutex 0x%08X (locks == %i) from %i to thread %i (lock dec)\n", - pMutex,pMutex->locks,pMutex->owner,pthread_self());*/ - } - else - { -/* fprintf(stderr,"osl_releaseMutex 0x%08X (locks == %i) from %i to thread %i\n", - pMutex,pMutex->locks,pMutex->owner,pthread_self());*/ - - pMutex->owner = PTHREAD_NONE; - nRet = pthread_mutex_unlock(&(pMutex->mutex)); - if ( nRet != 0 ) - { - OSL_TRACE("osl_releaseMutex : mutex unlock failed. Errno: %d; %s\n", - nRet, strerror(nRet)); - } - } - - return (sal_True); - } - else - { -/* fprintf(stderr,"osl_releaseMutex 0x%08X (locks == %i) from %i to thread %i (not owner)\n", - pMutex,pMutex->locks,pMutex->owner,pthread_self());*/ - - nRet = pthread_mutex_unlock(&(pMutex->mutex)); - if ( nRet != 0 ) - { - OSL_TRACE("osl_releaseMutex : mutex unlock failed. Errno: %d; %s\n", - nRet, strerror(nRet)); - return sal_False; - } - - return sal_True; - } + abort(); } - - /* not initialized */ - return sal_False; } -/*****************************************************************************/ -/* osl_getGlobalMutex */ -/*****************************************************************************/ - oslMutex * SAL_CALL osl_getGlobalMutex() { - /* the static global mutex instance */ - static oslMutexImpl globalMutexImpl = { - PTHREAD_MUTEX_INITIALIZER, - PTHREAD_NONE_INIT, - 0 - }; - /* necessary to get a "oslMutex *" */ static oslMutex globalMutex = (oslMutex) &globalMutexImpl; + static pthread_once_t once = PTHREAD_ONCE_INIT; + if (pthread_once(&once, &globalMutexInitImpl) != 0) { + abort(); + } + return &globalMutex; } - - -#endif /* #ifndef LINUX */ - |