00001 /* 00002 $Id: mutex_pthread.cpp,v 1.1.1.1 2000/04/09 12:18:02 mbn Exp $ 00003 00004 ------------------------------------------------------------------------ 00005 ClanLib, the platform independent game SDK. 00006 00007 This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE 00008 version 2. See COPYING for details. 00009 00010 For a total list of contributers see CREDITS. 00011 00012 ------------------------------------------------------------------------ 00013 */ 00014 00015 #include "Core/precomp.h" 00016 00017 #include <pthread.h> 00018 #include "mutex_pthread.h" 00019 00020 // We need to do this because the posix threads library under linux obviously 00021 // suck: 00022 extern "C" 00023 { 00024 int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind); 00025 } 00026 00027 CL_Mutex *CL_Mutex::create() 00028 { 00029 return new CL_Mutex_Posix; 00030 } 00031 00032 CL_Mutex_Posix::CL_Mutex_Posix() 00033 { 00034 pthread_mutexattr_t attr; 00035 pthread_mutexattr_init(&attr); 00036 pthread_mutexattr_setkind_np(&attr, PTHREAD_MUTEX_RECURSIVE_NP); 00037 pthread_mutex_init(&mutex, &attr); 00038 pthread_mutexattr_destroy(&attr); 00039 00040 pthread_cond_init(&cond,0); 00041 } 00042 00043 CL_Mutex_Posix::~CL_Mutex_Posix() 00044 { 00045 pthread_mutex_destroy(&mutex); 00046 pthread_cond_destroy(&cond); 00047 } 00048 00049 void CL_Mutex_Posix::enter() 00050 { 00051 pthread_mutex_lock(&mutex); 00052 } 00053 00054 void CL_Mutex_Posix::leave() 00055 { 00056 pthread_mutex_unlock(&mutex); 00057 } 00058 00059 00060 void CL_Mutex_Posix::wait() 00061 { 00062 pthread_cond_wait(&cond,&mutex); 00063 } 00064 00065 00066 void CL_Mutex_Posix::notify() 00067 { 00068 pthread_cond_signal(&cond); 00069 } 00070 00071 void CL_Mutex_Posix::notify_all() 00072 { 00073 pthread_cond_broadcast(&cond); 00074 }
1.2.6 written by Dimitri van Heesch,
© 1997-2001