PageRenderTime 19ms CodeModel.GetById 12ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/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
 5#include "rust_globals.h"
 6
 7#ifndef RUST_NDEBUG
 8#define DEBUG_LOCKS
 9#endif
10
11class lock_and_signal {
12#if defined(__WIN32__)
13    HANDLE _event;
14    CRITICAL_SECTION _cs;
15#if defined(DEBUG_LOCKS)
16    DWORD _holding_thread;
17#endif
18#else
19    pthread_cond_t _cond;
20    pthread_mutex_t _mutex;
21#if defined(DEBUG_LOCKS)
22    pthread_t _holding_thread;
23#endif
24#endif
25
26#if defined(DEBUG_LOCKS)
27    bool lock_held_by_current_thread();
28#endif
29
30    void must_not_be_locked();
31
32public:
33    lock_and_signal();
34    virtual ~lock_and_signal();
35
36    void lock();
37    void unlock();
38    void wait();
39    void signal();
40
41    void must_have_lock();
42    void must_not_have_lock();
43};
44
45class scoped_lock {
46  lock_and_signal &lock;
47
48public:
49  scoped_lock(lock_and_signal &lock);
50  ~scoped_lock();
51};
52
53#endif /* LOCK_AND_SIGNAL_H */