00001 #ifndef CONDITION_H 00002 #define CONDITION_H 00003 00004 #include <pthread.h> 00005 00006 class Condition 00007 { 00008 public: 00009 Condition(int init_value = 0, char *title = 0, int is_binary = 0); 00010 ~Condition(); 00011 00012 00013 // Reset to init_value whether locked or not. 00014 void reset(); 00015 // Block if value <= 0, then decrease value 00016 void lock(char *location = 0); 00017 // Increase value 00018 void unlock(); 00019 // Block for requested duration if value <= 0. 00020 // value is decreased whether or not the condition is unlocked in time 00021 // Returns 1 if timeout or 0 if success. 00022 int timed_lock(int microseconds, char *location = 0); 00023 int get_value(); 00024 00025 pthread_cond_t cond; 00026 pthread_mutex_t mutex; 00027 int value; 00028 int init_value; 00029 int is_binary; 00030 char *title; 00031 }; 00032 00033 00034 #endif
1.5.5