Skip to content

Commit 3439b65

Browse files
committed
---
yaml --- r: 7977 b: refs/heads/snap-stage3 c: f76e6c3 h: refs/heads/master i: 7975: a113df9 v: v3
1 parent e0be741 commit 3439b65

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 6b5f7865bea09737f67fa7ff5af5ee49b52955bb
4+
refs/heads/snap-stage3: f76e6c39f6f2bfef58e77cf786be8d5e1e19592c
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/rt/sync/lock_and_signal.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <assert.h>
12
#include "../globals.h"
23

34
/*
@@ -9,8 +10,13 @@
910

1011
#include "lock_and_signal.h"
1112

13+
// FIXME: This is not a portable way of specifying an invalid pthread_t
14+
#define INVALID_THREAD 0
15+
16+
1217
#if defined(__WIN32__)
1318
lock_and_signal::lock_and_signal()
19+
: _holding_thread(INVALID_THREAD)
1420
{
1521
// FIXME: In order to match the behavior of pthread_cond_broadcast on
1622
// Windows, we create manual reset events. This however breaks the
@@ -23,7 +29,7 @@ lock_and_signal::lock_and_signal()
2329

2430
#else
2531
lock_and_signal::lock_and_signal()
26-
: _locked(false)
32+
: _holding_thread(INVALID_THREAD)
2733
{
2834
CHECKED(pthread_cond_init(&_cond, NULL));
2935
CHECKED(pthread_mutex_init(&_mutex, NULL));
@@ -47,11 +53,10 @@ void lock_and_signal::lock() {
4753
CHECKED(pthread_mutex_lock(&_mutex));
4854
_holding_thread = pthread_self();
4955
#endif
50-
_locked = true;
5156
}
5257

5358
void lock_and_signal::unlock() {
54-
_locked = false;
59+
_holding_thread = INVALID_THREAD;
5560
#if defined(__WIN32__)
5661
LeaveCriticalSection(&_cs);
5762
#else
@@ -67,7 +72,8 @@ void lock_and_signal::wait() {
6772
}
6873

6974
bool lock_and_signal::timed_wait(size_t timeout_in_ms) {
70-
_locked = false;
75+
assert(lock_held_by_current_thread());
76+
_holding_thread = INVALID_THREAD;
7177
bool rv = true;
7278
#if defined(__WIN32__)
7379
LeaveCriticalSection(&_cs);
@@ -105,7 +111,6 @@ bool lock_and_signal::timed_wait(size_t timeout_in_ms) {
105111
}
106112
_holding_thread = pthread_self();
107113
#endif
108-
_locked = true;
109114
return rv;
110115
}
111116

@@ -134,9 +139,9 @@ void lock_and_signal::signal_all() {
134139
bool lock_and_signal::lock_held_by_current_thread()
135140
{
136141
#if defined(__WIN32__)
137-
return _locked && _holding_thread == GetCurrentThreadId();
142+
return _holding_thread == GetCurrentThreadId();
138143
#else
139-
return _locked && _holding_thread == pthread_self();
144+
return pthread_equal(_holding_thread, pthread_self());
140145
#endif
141146
}
142147

branches/snap-stage3/src/rt/sync/lock_and_signal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class lock_and_signal {
1313

1414
pthread_t _holding_thread;
1515
#endif
16-
bool _locked;
1716

1817
public:
1918
lock_and_signal();

0 commit comments

Comments
 (0)