Skip to content

Commit f45ddca

Browse files
committed
general: switch to C++11 Lockable semantics for mutexes
This renames acquire/release to lock/unlock in order to be compatible with std::lock_guard and std::unique_lock (which will eventually replace the *MutexHolder classes). It will also allow us to typedef MutexImpl to std::mutex later on.
1 parent 3653413 commit f45ddca

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+624
-469
lines changed

dtool/src/dtoolbase/deletedBufferChain.cxx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ allocate(size_t size, TypeHandle type_handle) {
4343

4444
ObjectNode *obj;
4545

46-
_lock.acquire();
46+
_lock.lock();
4747
if (_deleted_chain != (ObjectNode *)NULL) {
4848
obj = _deleted_chain;
4949
_deleted_chain = _deleted_chain->_next;
50-
_lock.release();
50+
_lock.unlock();
5151

5252
#ifdef USE_DELETEDCHAINFLAG
5353
assert(obj->_flag == (AtomicAdjust::Integer)DCF_deleted);
@@ -64,7 +64,7 @@ allocate(size_t size, TypeHandle type_handle) {
6464

6565
return ptr;
6666
}
67-
_lock.release();
67+
_lock.unlock();
6868

6969
// If we get here, the deleted_chain is empty; we have to allocate a new
7070
// object from the system pool.
@@ -126,12 +126,12 @@ deallocate(void *ptr, TypeHandle type_handle) {
126126
assert(orig_flag == (AtomicAdjust::Integer)DCF_alive);
127127
#endif // USE_DELETEDCHAINFLAG
128128

129-
_lock.acquire();
129+
_lock.lock();
130130

131131
obj->_next = _deleted_chain;
132132
_deleted_chain = obj;
133133

134-
_lock.release();
134+
_lock.unlock();
135135

136136
#else // USE_DELETED_CHAIN
137137
PANDA_FREE_SINGLE(ptr);

dtool/src/dtoolbase/memoryHook.cxx

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ MemoryHook(const MemoryHook &copy) :
223223
_total_mmap_size(copy._total_mmap_size),
224224
_max_heap_size(copy._max_heap_size) {
225225

226-
copy._lock.acquire();
226+
copy._lock.lock();
227227
_deleted_chains = copy._deleted_chains;
228-
copy._lock.release();
228+
copy._lock.unlock();
229229
}
230230

231231
/**
@@ -249,19 +249,19 @@ heap_alloc_single(size_t size) {
249249
size_t inflated_size = inflate_size(size);
250250

251251
#ifdef MEMORY_HOOK_MALLOC_LOCK
252-
_lock.acquire();
252+
_lock.lock();
253253
void *alloc = call_malloc(inflated_size);
254-
_lock.release();
254+
_lock.unlock();
255255
#else
256256
void *alloc = call_malloc(inflated_size);
257257
#endif
258258

259259
while (alloc == (void *)NULL) {
260260
alloc_fail(inflated_size);
261261
#ifdef MEMORY_HOOK_MALLOC_LOCK
262-
_lock.acquire();
262+
_lock.lock();
263263
alloc = call_malloc(inflated_size);
264-
_lock.release();
264+
_lock.unlock();
265265
#else
266266
alloc = call_malloc(inflated_size);
267267
#endif
@@ -305,9 +305,9 @@ heap_free_single(void *ptr) {
305305
#endif // DO_MEMORY_USAGE
306306

307307
#ifdef MEMORY_HOOK_MALLOC_LOCK
308-
_lock.acquire();
308+
_lock.lock();
309309
call_free(alloc);
310-
_lock.release();
310+
_lock.unlock();
311311
#else
312312
call_free(alloc);
313313
#endif
@@ -326,19 +326,19 @@ heap_alloc_array(size_t size) {
326326
size_t inflated_size = inflate_size(size);
327327

328328
#ifdef MEMORY_HOOK_MALLOC_LOCK
329-
_lock.acquire();
329+
_lock.lock();
330330
void *alloc = call_malloc(inflated_size);
331-
_lock.release();
331+
_lock.unlock();
332332
#else
333333
void *alloc = call_malloc(inflated_size);
334334
#endif
335335

336336
while (alloc == (void *)NULL) {
337337
alloc_fail(inflated_size);
338338
#ifdef MEMORY_HOOK_MALLOC_LOCK
339-
_lock.acquire();
339+
_lock.lock();
340340
alloc = call_malloc(inflated_size);
341-
_lock.release();
341+
_lock.unlock();
342342
#else
343343
alloc = call_malloc(inflated_size);
344344
#endif
@@ -380,9 +380,9 @@ heap_realloc_array(void *ptr, size_t size) {
380380

381381
void *alloc1 = alloc;
382382
#ifdef MEMORY_HOOK_MALLOC_LOCK
383-
_lock.acquire();
383+
_lock.lock();
384384
alloc1 = call_realloc(alloc1, inflated_size);
385-
_lock.release();
385+
_lock.unlock();
386386
#else
387387
alloc1 = call_realloc(alloc1, inflated_size);
388388
#endif
@@ -394,9 +394,9 @@ heap_realloc_array(void *ptr, size_t size) {
394394
alloc1 = alloc;
395395

396396
#ifdef MEMORY_HOOK_MALLOC_LOCK
397-
_lock.acquire();
397+
_lock.lock();
398398
alloc1 = call_realloc(alloc1, inflated_size);
399-
_lock.release();
399+
_lock.unlock();
400400
#else
401401
alloc1 = call_realloc(alloc1, inflated_size);
402402
#endif
@@ -453,9 +453,9 @@ heap_free_array(void *ptr) {
453453
#endif // DO_MEMORY_USAGE
454454

455455
#ifdef MEMORY_HOOK_MALLOC_LOCK
456-
_lock.acquire();
456+
_lock.lock();
457457
call_free(alloc);
458-
_lock.release();
458+
_lock.unlock();
459459
#else
460460
call_free(alloc);
461461
#endif
@@ -478,11 +478,11 @@ heap_trim(size_t pad) {
478478
// Since malloc_trim() isn't standard C, we can't be sure it exists on a
479479
// given platform. But if we're using dlmalloc, we know we have
480480
// dlmalloc_trim.
481-
_lock.acquire();
481+
_lock.lock();
482482
if (dlmalloc_trim(pad)) {
483483
trimmed = true;
484484
}
485-
_lock.release();
485+
_lock.unlock();
486486
#endif
487487

488488
#ifdef WIN32
@@ -596,7 +596,7 @@ DeletedBufferChain *MemoryHook::
596596
get_deleted_chain(size_t buffer_size) {
597597
DeletedBufferChain *chain;
598598

599-
_lock.acquire();
599+
_lock.lock();
600600
DeletedChains::iterator dci = _deleted_chains.find(buffer_size);
601601
if (dci != _deleted_chains.end()) {
602602
chain = (*dci).second;
@@ -606,7 +606,7 @@ get_deleted_chain(size_t buffer_size) {
606606
_deleted_chains.insert(DeletedChains::value_type(buffer_size, chain));
607607
}
608608

609-
_lock.release();
609+
_lock.unlock();
610610
return chain;
611611
}
612612

dtool/src/dtoolbase/mutexDummyImpl.I

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
*
1616
*/
1717
ALWAYS_INLINE void MutexDummyImpl::
18-
acquire() {
18+
lock() {
1919
}
2020

2121
/**
2222
*
2323
*/
2424
ALWAYS_INLINE bool MutexDummyImpl::
25-
try_acquire() {
25+
try_lock() {
2626
return true;
2727
}
2828

2929
/**
3030
*
3131
*/
3232
ALWAYS_INLINE void MutexDummyImpl::
33-
release() {
33+
unlock() {
3434
}

dtool/src/dtoolbase/mutexDummyImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ class EXPCL_DTOOL_DTOOLBASE MutexDummyImpl {
3030
MutexDummyImpl &operator = (const MutexDummyImpl &copy) DELETED_ASSIGN;
3131

3232
public:
33-
ALWAYS_INLINE void acquire();
34-
ALWAYS_INLINE bool try_acquire();
35-
ALWAYS_INLINE void release();
33+
ALWAYS_INLINE void lock();
34+
ALWAYS_INLINE bool try_lock();
35+
ALWAYS_INLINE void unlock();
3636
};
3737

3838
#include "mutexDummyImpl.I"

dtool/src/dtoolbase/mutexPosixImpl.I

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ INLINE MutexPosixImpl::
3232
*
3333
*/
3434
INLINE void MutexPosixImpl::
35-
acquire() {
36-
TAU_PROFILE("void MutexPosixImpl::acquire", " ", TAU_USER);
35+
lock() {
36+
TAU_PROFILE("void MutexPosixImpl::lock", " ", TAU_USER);
3737
int result = pthread_mutex_lock(&_lock);
3838
assert(result == 0);
3939
}
@@ -42,8 +42,8 @@ acquire() {
4242
*
4343
*/
4444
INLINE bool MutexPosixImpl::
45-
try_acquire() {
46-
TAU_PROFILE("bool MutexPosixImpl::try_acquire", " ", TAU_USER);
45+
try_lock() {
46+
TAU_PROFILE("bool MutexPosixImpl::try_lock", " ", TAU_USER);
4747
int result = pthread_mutex_trylock(&_lock);
4848
assert(result == 0 || result == EBUSY);
4949
return (result == 0);
@@ -53,20 +53,12 @@ try_acquire() {
5353
*
5454
*/
5555
INLINE void MutexPosixImpl::
56-
release() {
57-
TAU_PROFILE("void MutexPosixImpl::release", " ", TAU_USER);
56+
unlock() {
57+
TAU_PROFILE("void MutexPosixImpl::unlock", " ", TAU_USER);
5858
int result = pthread_mutex_unlock(&_lock);
5959
assert(result == 0);
6060
}
6161

62-
/**
63-
* Returns the underlying Posix lock handle.
64-
*/
65-
INLINE pthread_mutex_t *MutexPosixImpl::
66-
get_posix_lock() {
67-
return &_lock;
68-
}
69-
7062
/**
7163
*
7264
*/
@@ -101,8 +93,8 @@ INLINE ReMutexPosixImpl::
10193
*
10294
*/
10395
INLINE void ReMutexPosixImpl::
104-
acquire() {
105-
TAU_PROFILE("void ReMutexPosixImpl::acquire", " ", TAU_USER);
96+
lock() {
97+
TAU_PROFILE("void ReMutexPosixImpl::lock", " ", TAU_USER);
10698
int result = pthread_mutex_lock(&_lock);
10799
assert(result == 0);
108100
}
@@ -111,8 +103,8 @@ acquire() {
111103
*
112104
*/
113105
INLINE bool ReMutexPosixImpl::
114-
try_acquire() {
115-
TAU_PROFILE("bool ReMutexPosixImpl::try_acquire", " ", TAU_USER);
106+
try_lock() {
107+
TAU_PROFILE("bool ReMutexPosixImpl::try_lock", " ", TAU_USER);
116108
int result = pthread_mutex_trylock(&_lock);
117109
assert(result == 0 || result == EBUSY);
118110
return (result == 0);
@@ -122,16 +114,8 @@ try_acquire() {
122114
*
123115
*/
124116
INLINE void ReMutexPosixImpl::
125-
release() {
126-
TAU_PROFILE("void ReMutexPosixImpl::release", " ", TAU_USER);
117+
unlock() {
118+
TAU_PROFILE("void ReMutexPosixImpl::unlock", " ", TAU_USER);
127119
int result = pthread_mutex_unlock(&_lock);
128120
assert(result == 0);
129121
}
130-
131-
/**
132-
* Returns the underlying Posix lock handle.
133-
*/
134-
INLINE pthread_mutex_t *ReMutexPosixImpl::
135-
get_posix_lock() {
136-
return &_lock;
137-
}

dtool/src/dtoolbase/mutexPosixImpl.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ class EXPCL_DTOOL_DTOOLBASE MutexPosixImpl {
3636
MutexPosixImpl &operator = (const MutexPosixImpl &copy) DELETED_ASSIGN;
3737

3838
public:
39-
INLINE void acquire();
40-
INLINE bool try_acquire();
41-
INLINE void release();
42-
43-
INLINE pthread_mutex_t *get_posix_lock();
39+
INLINE void lock();
40+
INLINE bool try_lock();
41+
INLINE void unlock();
4442

4543
private:
4644
pthread_mutex_t _lock;
@@ -64,11 +62,9 @@ class EXPCL_DTOOL_DTOOLBASE ReMutexPosixImpl {
6462
ReMutexPosixImpl &operator = (const ReMutexPosixImpl &copy) DELETED;
6563

6664
public:
67-
INLINE void acquire();
68-
INLINE bool try_acquire();
69-
INLINE void release();
70-
71-
INLINE pthread_mutex_t *get_posix_lock();
65+
INLINE void lock();
66+
INLINE bool try_lock();
67+
INLINE void unlock();
7268

7369
private:
7470
pthread_mutex_t _lock;

dtool/src/dtoolbase/mutexSpinlockImpl.I

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ MutexSpinlockImpl() : _lock(0) {
2222
*
2323
*/
2424
INLINE void MutexSpinlockImpl::
25-
acquire() {
26-
if (!try_acquire()) {
25+
lock() {
26+
if (!try_lock()) {
2727
do_lock();
2828
}
2929
}
@@ -32,14 +32,14 @@ acquire() {
3232
*
3333
*/
3434
INLINE bool MutexSpinlockImpl::
35-
try_acquire() {
35+
try_lock() {
3636
return (AtomicAdjust::compare_and_exchange(_lock, 0, 1) == 0);
3737
}
3838

3939
/**
4040
*
4141
*/
4242
INLINE void MutexSpinlockImpl::
43-
release() {
43+
unlock() {
4444
AtomicAdjust::set(_lock, 0);
4545
}

dtool/src/dtoolbase/mutexSpinlockImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class EXPCL_DTOOL_DTOOLBASE MutexSpinlockImpl {
3636
MutexSpinlockImpl &operator = (const MutexSpinlockImpl &copy) DELETED_ASSIGN;
3737

3838
public:
39-
INLINE void acquire();
40-
INLINE bool try_acquire();
41-
INLINE void release();
39+
INLINE void lock();
40+
INLINE bool try_lock();
41+
INLINE void unlock();
4242

4343
private:
4444
void do_lock();

dtool/src/dtoolbase/mutexWin32Impl.I

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@ INLINE MutexWin32Impl::
2323
*
2424
*/
2525
INLINE void MutexWin32Impl::
26-
acquire() {
26+
lock() {
2727
EnterCriticalSection(&_lock);
2828
}
2929

3030
/**
3131
*
3232
*/
3333
INLINE bool MutexWin32Impl::
34-
try_acquire() {
34+
try_lock() {
3535
return (TryEnterCriticalSection(&_lock) != 0);
3636
}
3737

3838
/**
3939
*
4040
*/
4141
INLINE void MutexWin32Impl::
42-
release() {
42+
unlock() {
4343
LeaveCriticalSection(&_lock);
4444
}

0 commit comments

Comments
 (0)