+ err = pthread_mutex_init(&m_mutex, &attr);
+ }
+#elif defined(HAVE_PTHREAD_RECURSIVE_MUTEX_INITIALIZER)
+ // we can use this only as initializer so we have to assign it
+ // first to a temp var - assigning directly to m_mutex wouldn't
+ // even compile
+ {
+ pthread_mutex_t mutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+ m_mutex = mutex;
+ }
+#else // no recursive mutexes
+ err = EINVAL;
+#endif // HAVE_PTHREAD_MUTEXATTR_T/...
+ break;
+
+ default:
+ wxFAIL_MSG( _T("unknown mutex type") );
+ // fall through
+
+ case wxMUTEX_DEFAULT:
+ err = pthread_mutex_init(&m_mutex, NULL);
+ break;
+ }
+
+ m_isOk = err == 0;
+ if ( !m_isOk )
+ {
+ wxLogApiError( wxT("pthread_mutex_init()"), err);
+ }
+}
+
+wxMutexInternal::~wxMutexInternal()
+{
+ if ( m_isOk )
+ {
+ int err = pthread_mutex_destroy(&m_mutex);
+ if ( err != 0 )
+ {
+ wxLogApiError( wxT("pthread_mutex_destroy()"), err);
+ }
+ }
+}
+
+wxMutexError wxMutexInternal::Lock()
+{
+ return HandleLockResult(pthread_mutex_lock(&m_mutex));
+}
+
+wxMutexError wxMutexInternal::Lock(unsigned long ms)
+{
+#ifdef HAVE_PTHREAD_MUTEX_TIMEDLOCK
+ static const long MSEC_IN_SEC = 1000;
+ static const long NSEC_IN_MSEC = 1000000;
+ static const long NSEC_IN_USEC = 1000;
+ static const long NSEC_IN_SEC = MSEC_IN_SEC * NSEC_IN_MSEC;
+
+ time_t seconds = ms/MSEC_IN_SEC;
+ long nanoseconds = (ms % MSEC_IN_SEC) * NSEC_IN_MSEC;
+ timespec ts = { 0, 0 };
+
+ // normally we should use clock_gettime(CLOCK_REALTIME) here but this
+ // function is in librt and we don't link with it currently, so use
+ // gettimeofday() instead -- if it turns out that this is really too
+ // imprecise, we should modify configure to check if clock_gettime() is
+ // available and whether it requires -lrt and use it instead
+#if 0
+ if ( clock_gettime(CLOCK_REALTIME, &ts) == 0 )
+ {
+ }