summaryrefslogtreecommitdiff
path: root/test/threads.h
diff options
context:
space:
mode:
authorMichael R Sweet <michael.r.sweet@gmail.com>2001-12-17 14:52:27 +0000
committerMichael R Sweet <michael.r.sweet@gmail.com>2001-12-17 14:52:27 +0000
commit5dd762509295268a7d6c825bbd02161c461f5569 (patch)
tree34b72524a478134b1ae13acbaa23b2e50242b10b /test/threads.h
parent8408e863de860ef75a58be303b488b7c44701f9d (diff)
Remove Fl_Mutex and Fl_Signal_Mutex from threads.h - not portable, and
not used... git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1861 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'test/threads.h')
-rw-r--r--test/threads.h96
1 files changed, 2 insertions, 94 deletions
diff --git a/test/threads.h b/test/threads.h
index 31230e8ef..72d2fe144 100644
--- a/test/threads.h
+++ b/test/threads.h
@@ -1,5 +1,5 @@
//
-// "$Id: threads.h,v 1.1.2.3 2001/12/14 21:02:24 easysw Exp $"
+// "$Id: threads.h,v 1.1.2.4 2001/12/17 14:52:27 easysw Exp $"
//
// Simple threading API for the Fast Light Tool Kit (FLTK).
//
@@ -53,71 +53,6 @@ static int fl_create_thread(Fl_Thread& t, void *(*f) (void *), void* p)
return pthread_create((pthread_t*)&t, 0, f, p);
}
-// Linux supports recursive locks, use them directly, with some cheating:
-# ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
-
-extern pthread_mutexattr_t Fl_Mutex_attrib;
-
-class Fl_Mutex {
- friend class Fl_SignalMutex;
- pthread_mutex_t mutex;
- Fl_Mutex(const Fl_Mutex&);
- Fl_Mutex& operator=(const Fl_Mutex&);
-public:
- Fl_Mutex() {pthread_mutex_init(&mutex, &Fl_Mutex_attrib);}
- void lock() {pthread_mutex_lock(&mutex);}
- void unlock() {pthread_mutex_unlock(&mutex);}
- ~Fl_Mutex() {pthread_mutex_destroy(&mutex);}
-};
-
-class Fl_SignalMutex : public Fl_Mutex {
- pthread_cond_t cond;
-public:
- Fl_SignalMutex() : Fl_Mutex() {pthread_cond_init(&cond, 0);}
- void signal() {pthread_cond_broadcast(&cond);}
- void wait() {
- int save_counter = mutex.m_count; mutex.m_count = 1;
- pthread_cond_wait(&cond, &mutex);
- mutex.m_count = save_counter;
- }
-};
-
-# else // standard pthread mutexes need a bit of work to be recursive:
-
-class Fl_Mutex {
- friend class Fl_SignalMutex;
- pthread_mutex_t mutex;
- pthread_t owner;
- int counter;
- Fl_Mutex(const Fl_Mutex&);
- Fl_Mutex& operator=(const Fl_Mutex&);
-public:
- Fl_Mutex() : counter(0) {pthread_mutex_init(&mutex, 0);}
- void lock() {
- if (!counter || owner != pthread_self()) {
- pthread_mutex_lock(&mutex); owner = pthread_self();
- }
- counter++;
- }
- void unlock() {if (!--counter) pthread_mutex_unlock(&mutex);}
- ~Fl_Mutex() {pthread_mutex_destroy(&mutex);}
-};
-
-class Fl_SignalMutex : public Fl_Mutex {
- pthread_cond_t cond;
-public:
- Fl_SignalMutex() : Fl_Mutex() {pthread_cond_init(&cond, 0);}
- void signal() {pthread_cond_broadcast(&cond);}
- void wait() {
- int save_counter = counter; counter = 0;
- pthread_cond_wait(&cond, &mutex);
- counter = save_counter;
- owner = pthread_self();
- }
-};
-
-# endif
-
# elif defined(WIN32) // Use Windows threading...
# include <windows.h>
@@ -129,36 +64,9 @@ static int fl_create_thread(Fl_Thread& t, void *(*f) (void *), void* p) {
return t = (Fl_Thread)_beginthread((void( __cdecl * )( void * ))f, 0, p);
}
-class Fl_Mutex {
- friend class Fl_SignalMutex;
- CRITICAL_SECTION cs;
- Fl_Mutex(const Fl_Mutex&);
- Fl_Mutex& operator=(const Fl_Mutex&);
-public:
- Fl_Mutex() {InitializeCriticalSection(&cs);}
- void lock() {EnterCriticalSection(&cs);}
- void unlock() {LeaveCriticalSection(&cs);}
- ~Fl_Mutex() {DeleteCriticalSection(&cs);}
-};
-
-class Fl_SignalMutex : public Fl_Mutex {
- HANDLE event;
-public:
- Fl_SignalMutex() : Fl_Mutex() {event = CreateEvent(0, FALSE, FALSE, 0);}
- void signal() {SetEvent(event);}
- void wait() {
- // int save_counter = cs.count; cs.count = 1;
- // the following three calls should be atomic, sigh...
- LeaveCriticalSection(&cs);
- WaitForSingleObject(event, INFINITE);
- EnterCriticalSection(&cs);
- // cs.count = save_counter;
- }
-};
-
# endif // !HAVE_PTHREAD_H
#endif // !Threads_h
//
-// End of "$Id: threads.h,v 1.1.2.3 2001/12/14 21:02:24 easysw Exp $".
+// End of "$Id: threads.h,v 1.1.2.4 2001/12/17 14:52:27 easysw Exp $".
//