26 #if defined (HAVE_CONFIG_H)
33 #if defined (OCTAVE_USE_WINDOWS_API)
35 #elif defined (HAVE_PTHREAD_H)
44 (*current_liboctave_error_handler) (
"mutex not supported on this platform");
50 (*current_liboctave_error_handler) (
"mutex not supported on this platform");
56 (*current_liboctave_error_handler) (
"mutex not supported on this platform");
61 #if defined (OCTAVE_USE_WINDOWS_API)
70 InitializeCriticalSection (&cs);
75 DeleteCriticalSection (&cs);
80 EnterCriticalSection (&cs);
85 LeaveCriticalSection (&cs);
90 return (TryEnterCriticalSection (&cs) != 0);
97 static DWORD thread_id = 0;
102 thread_id = GetCurrentThreadId ();
108 return (GetCurrentThreadId () == thread_id);
111 #elif defined (HAVE_PTHREAD_H)
114 pthread_mutex :
public base_mutex
118 : base_mutex (), m_pm ()
120 pthread_mutexattr_t attr;
122 pthread_mutexattr_init (&attr);
123 pthread_mutexattr_settype (&attr, PTHREAD_MUTEX_RECURSIVE);
124 pthread_mutex_init (&m_pm, &attr);
125 pthread_mutexattr_destroy (&attr);
128 ~pthread_mutex (
void)
130 pthread_mutex_destroy (&m_pm);
135 pthread_mutex_lock (&m_pm);
140 pthread_mutex_unlock (&m_pm);
145 return (pthread_mutex_trylock (&m_pm) == 0);
149 pthread_mutex_t m_pm;
152 static pthread_t thread_id = 0;
157 thread_id = pthread_self ();
163 return (pthread_equal (thread_id, pthread_self ()) != 0);
171 #if defined (OCTAVE_USE_WINDOWS_API)
172 return new w32_mutex ();
173 #elif defined (HAVE_PTHREAD_H)
174 return new pthread_mutex ();
virtual bool try_lock(void)
virtual void unlock(void)
static bool is_thread(void)
static base_mutex * init_rep(void)