00001
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00032
00033 #ifndef GROOVX_RUTZ_SPIN_LOCK_PTHREADS_H_UTC20070905190848_DEFINED
00034 #define GROOVX_RUTZ_SPIN_LOCK_PTHREADS_H_UTC20070905190848_DEFINED
00035
00036 #include "rutz/error.h"
00037
00038 namespace rutz
00039 {
00040
00041 class spin_lock_pthreads
00042 {
00043 private:
00044 pthread_spinlock_t m_lock;
00045
00046 spin_lock_pthreads(const spin_lock_pthreads&);
00047 spin_lock_pthreads& operator=(const spin_lock_pthreads&);
00048
00049 public:
00051 spin_lock_pthreads();
00052
00053 ~spin_lock_pthreads();
00054
00055 void lock()
00056 {
00057 if (0 != pthread_spin_lock(&m_lock))
00058 throw rutz::error("pthread_spin_lock() failed", SRC_POS);
00059 }
00060
00061 bool try_lock()
00062 { return (0 == pthread_spin_trylock(&m_lock)); }
00063
00064 void unlock()
00065 { pthread_spin_unlock(&m_lock); }
00066 };
00067
00068 }
00069
00070 static const char vcid_groovx_rutz_spin_lock_pthreads_h_utc20070905190848[] = "$Id: spin_lock_pthreads.h 10134 2008-03-04 17:58:05Z rjpeters $ $HeadURL: file:///lab/rjpeters/svnrepo/code/trunk/groovx/src/rutz/spin_lock_pthreads.h $";
00071 #endif // !GROOVX_RUTZ_SPIN_LOCK_PTHREADS_H_UTC20070905190848DEFINED