|
a/src/utils/ptmutex.h |
|
b/src/utils/ptmutex.h |
|
... |
|
... |
25 |
/// Lock storage with auto-initialization. Must be created before any
|
25 |
/// Lock storage with auto-initialization. Must be created before any
|
26 |
/// lock-using thread of course (possibly as a static object).
|
26 |
/// lock-using thread of course (possibly as a static object).
|
27 |
class PTMutexInit {
|
27 |
class PTMutexInit {
|
28 |
public:
|
28 |
public:
|
29 |
pthread_mutex_t m_mutex;
|
29 |
pthread_mutex_t m_mutex;
|
|
|
30 |
int m_status;
|
30 |
PTMutexInit()
|
31 |
PTMutexInit()
|
31 |
{
|
32 |
{
|
32 |
pthread_mutex_init(&m_mutex, 0);
|
33 |
m_status = pthread_mutex_init(&m_mutex, 0);
|
33 |
}
|
34 |
}
|
34 |
};
|
35 |
};
|
35 |
|
36 |
|
36 |
/// Take the lock when constructed, release when deleted. Can be disabled
|
37 |
/// Take the lock when constructed, release when deleted. Can be disabled
|
37 |
/// by constructor params for conditional use.
|
38 |
/// by constructor params for conditional use.
|
|
... |
|
... |
48 |
{
|
49 |
{
|
49 |
if (m_status == 0)
|
50 |
if (m_status == 0)
|
50 |
pthread_mutex_unlock(&m_lock.m_mutex);
|
51 |
pthread_mutex_unlock(&m_lock.m_mutex);
|
51 |
}
|
52 |
}
|
52 |
int ok() {return m_status == 0;}
|
53 |
int ok() {return m_status == 0;}
|
|
|
54 |
// For pthread_cond_wait etc.
|
|
|
55 |
pthread_mutex_t *getMutex()
|
|
|
56 |
{
|
|
|
57 |
return &m_lock.m_mutex;
|
|
|
58 |
}
|
53 |
private:
|
59 |
private:
|
54 |
PTMutexInit& m_lock;
|
60 |
PTMutexInit& m_lock;
|
55 |
int m_status;
|
61 |
int m_status;
|
56 |
};
|
62 |
};
|
57 |
|
63 |
|