mirror of https://github.com/fltk/fltk
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
This commit is contained in:
parent
8408e863de
commit
5dd7625092
3
CHANGES
3
CHANGES
|
@ -1,5 +1,8 @@
|
|||
CHANGES IN FLTK 1.1.0b8
|
||||
|
||||
- Removed the Fl_Mutex and Fl_Signal_Mutex classes from
|
||||
the threads example, since they weren't being used
|
||||
and apparently are not very portable.
|
||||
- Fl_Help_View now ignores links when the link callback
|
||||
returns NULL, and displays a sensible error message
|
||||
when an unhandled URI scheme is used (e.g. http:,
|
||||
|
|
|
@ -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 $".
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue