30 #if defined (__WIN32__) && ! defined (__CYGWIN__)
32 #elif defined (HAVE_PTHREAD_H)
39 (*current_liboctave_error_handler) (
"mutex not supported on this platform");
45 (*current_liboctave_error_handler) (
"mutex not supported on this platform");
51 (*current_liboctave_error_handler) (
"mutex not supported on this platform");
56 #if defined (__WIN32__) && ! defined (__CYGWIN__)
62 octave_w32_mutex (
void)
65 InitializeCriticalSection (&cs);
68 ~octave_w32_mutex (
void)
70 DeleteCriticalSection (&cs);
75 EnterCriticalSection (&cs);
80 LeaveCriticalSection (&cs);
85 return (TryEnterCriticalSection (&cs) != 0);
92 static DWORD octave_thread_id = 0;
97 octave_thread_id = GetCurrentThreadId ();
103 return (GetCurrentThreadId () == octave_thread_id);
106 #elif defined (HAVE_PTHREAD_H)
112 octave_pthread_mutex (
void)
115 pthread_mutexattr_t attr;
117 pthread_mutexattr_init (&attr);
118 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
119 pthread_mutex_init (&pm, &attr);
120 pthread_mutexattr_destroy (&attr);
123 ~octave_pthread_mutex (
void)
125 pthread_mutex_destroy (&pm);
130 pthread_mutex_lock (&pm);
135 pthread_mutex_unlock (&pm);
140 return (pthread_mutex_trylock (&pm) == 0);
147 static pthread_t octave_thread_id = 0;
152 octave_thread_id = pthread_self ();
158 return (pthread_equal (octave_thread_id, pthread_self ()) != 0);
166 #if defined (__WIN32__) && ! defined (__CYGWIN__)
167 return new octave_w32_mutex ();
168 #elif defined (HAVE_PTHREAD_H)
169 return new octave_pthread_mutex ();