00001 #ifndef MUTEX_H 00002 #define MUTEX_H 00003 00004 #include <pthread.h> 00005 #include <stdio.h> 00006 00007 class Mutex 00008 { 00009 public: 00010 Mutex(char *title = 0, int recursive = 0); 00011 ~Mutex(); 00012 00013 int lock(char *location = 0); 00014 int unlock(); 00015 // Calls pthread_mutex_trylock, whose effect depends on library version. 00016 int trylock(); 00017 int reset(); 00018 // Returns 1 if count is > 0 00019 int is_locked(); 00020 00021 // Number of times the thread currently holding the mutex has locked it. 00022 // For recursive locking. 00023 int count; 00024 // ID of the thread currently holding the mutex. For recursive locking. 00025 pthread_t thread_id; 00026 int thread_id_valid; 00027 int recursive; 00028 // Lock the variables for recursive locking. 00029 pthread_mutex_t recursive_lock; 00030 pthread_mutex_t mutex; 00031 char *title; 00032 }; 00033 00034 00035 #endif
1.5.5