]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - contrib/llvm/tools/lldb/source/Host/common/ProcessRunLock.cpp
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.git] / contrib / llvm / tools / lldb / source / Host / common / ProcessRunLock.cpp
1 #ifndef _WIN32
2
3 #include "lldb/Host/ProcessRunLock.h"
4
5 namespace lldb_private {
6
7     ProcessRunLock::ProcessRunLock()
8         : m_running(false)
9     {
10         int err = ::pthread_rwlock_init(&m_rwlock, NULL); (void) err;
11         //#if LLDB_CONFIGURATION_DEBUG
12         //        assert(err == 0);
13         //#endif
14     }
15
16     ProcessRunLock::~ProcessRunLock()
17     {
18         int err = ::pthread_rwlock_destroy(&m_rwlock); (void) err;
19         //#if LLDB_CONFIGURATION_DEBUG
20         //        assert(err == 0);
21         //#endif
22     }
23
24     bool ProcessRunLock::ReadTryLock()
25     {
26         ::pthread_rwlock_rdlock(&m_rwlock);
27         if (m_running == false)
28         {
29             return true;
30         }
31         ::pthread_rwlock_unlock(&m_rwlock);
32         return false;
33     }
34
35     bool ProcessRunLock::ReadUnlock()
36     {
37         return ::pthread_rwlock_unlock(&m_rwlock) == 0;
38     }
39
40     bool ProcessRunLock::SetRunning()
41     {
42         ::pthread_rwlock_wrlock(&m_rwlock);
43         m_running = true;
44         ::pthread_rwlock_unlock(&m_rwlock);
45         return true;
46     }
47
48     bool ProcessRunLock::TrySetRunning()
49     {
50         bool r;
51
52         if (::pthread_rwlock_trywrlock(&m_rwlock) == 0)
53         {
54             r = !m_running;
55             m_running = true;
56             ::pthread_rwlock_unlock(&m_rwlock);
57             return r;
58         }
59         return false;
60     }
61
62     bool ProcessRunLock::SetStopped()
63     {
64         ::pthread_rwlock_wrlock(&m_rwlock);
65         m_running = false;
66         ::pthread_rwlock_unlock(&m_rwlock);
67         return true;
68     }
69 }
70
71 #endif