/src/rt/sync/lock_and_signal.h

http://github.com/jruderman/rust · C Header · 53 lines · 41 code · 11 blank · 1 comment · 0 complexity · 0eb80e3dd2f272787f8e5b687a299a96 MD5 · raw file

  1. // -*- c++ -*-
  2. #ifndef LOCK_AND_SIGNAL_H
  3. #define LOCK_AND_SIGNAL_H
  4. #include "rust_globals.h"
  5. #ifndef RUST_NDEBUG
  6. #define DEBUG_LOCKS
  7. #endif
  8. class lock_and_signal {
  9. #if defined(__WIN32__)
  10. HANDLE _event;
  11. CRITICAL_SECTION _cs;
  12. #if defined(DEBUG_LOCKS)
  13. DWORD _holding_thread;
  14. #endif
  15. #else
  16. pthread_cond_t _cond;
  17. pthread_mutex_t _mutex;
  18. #if defined(DEBUG_LOCKS)
  19. pthread_t _holding_thread;
  20. #endif
  21. #endif
  22. #if defined(DEBUG_LOCKS)
  23. bool lock_held_by_current_thread();
  24. #endif
  25. void must_not_be_locked();
  26. public:
  27. lock_and_signal();
  28. virtual ~lock_and_signal();
  29. void lock();
  30. void unlock();
  31. void wait();
  32. void signal();
  33. void must_have_lock();
  34. void must_not_have_lock();
  35. };
  36. class scoped_lock {
  37. lock_and_signal &lock;
  38. public:
  39. scoped_lock(lock_and_signal &lock);
  40. ~scoped_lock();
  41. };
  42. #endif /* LOCK_AND_SIGNAL_H */