Go to the documentation of this file.00001
00002 #ifndef vpl_mutex_h_
00003 #define vpl_mutex_h_
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <vxl_config.h>
00015
00016 #if VXL_HAS_PTHREAD_H
00017 # include <pthread.h>
00018 # include <vcl_cerrno.h>
00019 struct vpl_mutex
00020 {
00021 vpl_mutex() { pthread_mutex_init(&mutex_, 0); }
00022
00023 void lock() { pthread_mutex_lock(&mutex_); }
00024
00025
00026 bool trylock() { return pthread_mutex_trylock(&mutex_) != EBUSY; }
00027
00028 void unlock() { pthread_mutex_unlock(&mutex_); }
00029
00030 ~vpl_mutex() { pthread_mutex_destroy(&mutex_); }
00031
00032 private:
00033 pthread_mutex_t mutex_;
00034
00035
00036 vpl_mutex(vpl_mutex const &) { }
00037 vpl_mutex& operator=(vpl_mutex const &) { return *this; }
00038 };
00039
00040 #else
00041 # error "only works with pthreads for now"
00042 #endif
00043
00044 #endif // vpl_mutex_h_