123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- #ifndef BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_
- #define BASE_SYNCHRONIZATION_CONDITION_VARIABLE_H_
- #if defined(OS_POSIX) || defined(OS_FUCHSIA)
- #include <pthread.h>
- #endif
- #include "base/base_export.h"
- #include "base/logging.h"
- #include "base/macros.h"
- #include "base/synchronization/lock.h"
- #include "build/build_config.h"
- #if defined(OS_WIN)
- #include "base/win/windows_types.h"
- #endif
- namespace base {
- class TimeDelta;
- class BASE_EXPORT ConditionVariable {
- public:
-
- explicit ConditionVariable(Lock* user_lock);
- ~ConditionVariable();
-
-
-
- void Wait();
- void TimedWait(const TimeDelta& max_time);
-
-
- void Broadcast();
-
- void Signal();
-
-
-
-
-
-
-
- void declare_only_used_while_idle() { waiting_is_blocking_ = false; }
- private:
- #if defined(OS_WIN)
- CHROME_CONDITION_VARIABLE cv_;
- CHROME_SRWLOCK* const srwlock_;
- #elif defined(OS_POSIX) || defined(OS_FUCHSIA)
- pthread_cond_t condition_;
- pthread_mutex_t* user_mutex_;
- #endif
- #if DCHECK_IS_ON()
- base::Lock* const user_lock_;
- #endif
-
-
-
- bool waiting_is_blocking_ = true;
- DISALLOW_COPY_AND_ASSIGN(ConditionVariable);
- };
- }
- #endif
|