diff --git a/dtool/src/dtoolbase/deletedBufferChain.cxx b/dtool/src/dtoolbase/deletedBufferChain.cxx index 62ce77cbeb..c03ce287e2 100644 --- a/dtool/src/dtoolbase/deletedBufferChain.cxx +++ b/dtool/src/dtoolbase/deletedBufferChain.cxx @@ -51,7 +51,7 @@ allocate(size_t size, TypeHandle type_handle) { ObjectNode *obj; - _lock.lock(); + _lock.acquire(); if (_deleted_chain != (ObjectNode *)NULL) { obj = _deleted_chain; _deleted_chain = _deleted_chain->_next; @@ -121,7 +121,7 @@ deallocate(void *ptr, TypeHandle type_handle) { assert(orig_flag == (AtomicAdjust::Integer)DCF_alive); #endif // NDEBUG - _lock.lock(); + _lock.acquire(); obj->_next = _deleted_chain; _deleted_chain = obj; diff --git a/dtool/src/dtoolbase/memoryHook.cxx b/dtool/src/dtoolbase/memoryHook.cxx index 6e6cf797a9..d46d5d2d18 100644 --- a/dtool/src/dtoolbase/memoryHook.cxx +++ b/dtool/src/dtoolbase/memoryHook.cxx @@ -152,7 +152,7 @@ MemoryHook(const MemoryHook ©) : _max_heap_size = copy._max_heap_size; #endif - ((MutexImpl &)copy._lock).lock(); + ((MutexImpl &)copy._lock).acquire(); _deleted_chains = copy._deleted_chains; ((MutexImpl &)copy._lock).release(); } @@ -182,7 +182,7 @@ MemoryHook:: void *MemoryHook:: heap_alloc_single(size_t size) { #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.lock(); + _lock.acquire(); void *alloc = call_malloc(inflate_size(size)); _lock.release(); #else @@ -225,7 +225,7 @@ heap_free_single(void *ptr) { #endif // DO_MEMORY_USAGE #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.lock(); + _lock.acquire(); call_free(alloc); _lock.release(); #else @@ -248,7 +248,7 @@ heap_free_single(void *ptr) { void *MemoryHook:: heap_alloc_array(size_t size) { #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.lock(); + _lock.acquire(); void *alloc = call_malloc(inflate_size(size)); _lock.release(); #else @@ -291,7 +291,7 @@ heap_realloc_array(void *ptr, size_t size) { #endif // DO_MEMORY_USAGE #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.lock(); + _lock.acquire(); alloc = call_realloc(alloc, inflate_size(size)); _lock.release(); #else @@ -323,7 +323,7 @@ heap_free_array(void *ptr) { #endif // DO_MEMORY_USAGE #ifdef MEMORY_HOOK_MALLOC_LOCK - _lock.lock(); + _lock.acquire(); call_free(alloc); _lock.release(); #else @@ -353,7 +353,7 @@ heap_trim(size_t pad) { // Since malloc_trim() isn't standard C, we can't be sure it exists // on a given platform. But if we're using dlmalloc, we know we // have dlmalloc_trim. - _lock.lock(); + _lock.acquire(); if (dlmalloc_trim(pad)) { trimmed = true; } @@ -485,7 +485,7 @@ DeletedBufferChain *MemoryHook:: get_deleted_chain(size_t buffer_size) { DeletedBufferChain *chain; - _lock.lock(); + _lock.acquire(); DeletedChains::iterator dci = _deleted_chains.find(buffer_size); if (dci != _deleted_chains.end()) { chain = (*dci).second; diff --git a/dtool/src/dtoolbase/mutexDummyImpl.I b/dtool/src/dtoolbase/mutexDummyImpl.I index 6aa4b60952..d7e55fd35c 100644 --- a/dtool/src/dtoolbase/mutexDummyImpl.I +++ b/dtool/src/dtoolbase/mutexDummyImpl.I @@ -32,12 +32,22 @@ INLINE MutexDummyImpl:: } //////////////////////////////////////////////////////////////////// -// Function: MutexDummyImpl::lock +// Function: MutexDummyImpl::acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE void MutexDummyImpl:: -lock() { +acquire() { +} + +//////////////////////////////////////////////////////////////////// +// Function: MutexDummyImpl::try_acquire +// Access: Public +// Description: +//////////////////////////////////////////////////////////////////// +INLINE bool MutexDummyImpl:: +try_acquire() { + return true; } //////////////////////////////////////////////////////////////////// diff --git a/dtool/src/dtoolbase/mutexDummyImpl.h b/dtool/src/dtoolbase/mutexDummyImpl.h index 9a11bb9117..b2e4b5c7b4 100644 --- a/dtool/src/dtoolbase/mutexDummyImpl.h +++ b/dtool/src/dtoolbase/mutexDummyImpl.h @@ -29,7 +29,8 @@ public: INLINE MutexDummyImpl(); INLINE ~MutexDummyImpl(); - INLINE void lock(); + INLINE void acquire(); + INLINE bool try_acquire(); INLINE void release(); }; diff --git a/dtool/src/dtoolbase/mutexPosixImpl.I b/dtool/src/dtoolbase/mutexPosixImpl.I index 98c11a3f6c..b114581b03 100644 --- a/dtool/src/dtoolbase/mutexPosixImpl.I +++ b/dtool/src/dtoolbase/mutexPosixImpl.I @@ -42,25 +42,25 @@ INLINE MutexPosixImpl:: } //////////////////////////////////////////////////////////////////// -// Function: MutexPosixImpl::lock +// Function: MutexPosixImpl::acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE void MutexPosixImpl:: -lock() { - TAU_PROFILE("void MutexPosixImpl::lock", " ", TAU_USER); +acquire() { + TAU_PROFILE("void MutexPosixImpl::acquire", " ", TAU_USER); int result = pthread_mutex_lock(&_lock); assert(result == 0); } //////////////////////////////////////////////////////////////////// -// Function: MutexPosixImpl::try_lock +// Function: MutexPosixImpl::try_acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE bool MutexPosixImpl:: -try_lock() { - TAU_PROFILE("bool MutexPosixImpl::try_lock", " ", TAU_USER); +try_acquire() { + TAU_PROFILE("bool MutexPosixImpl::try_acquire", " ", TAU_USER); int result = pthread_mutex_trylock(&_lock); assert(result == 0 || result == EBUSY); return (result == 0); @@ -107,25 +107,25 @@ INLINE ReMutexPosixImpl:: } //////////////////////////////////////////////////////////////////// -// Function: ReMutexPosixImpl::lock +// Function: ReMutexPosixImpl::acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE void ReMutexPosixImpl:: -lock() { - TAU_PROFILE("void ReMutexPosixImpl::lock", " ", TAU_USER); +acquire() { + TAU_PROFILE("void ReMutexPosixImpl::acquire", " ", TAU_USER); int result = pthread_mutex_lock(&_lock); assert(result == 0); } //////////////////////////////////////////////////////////////////// -// Function: ReMutexPosixImpl::try_lock +// Function: ReMutexPosixImpl::try_acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE bool ReMutexPosixImpl:: -try_lock() { - TAU_PROFILE("bool ReMutexPosixImpl::try_lock", " ", TAU_USER); +try_acquire() { + TAU_PROFILE("bool ReMutexPosixImpl::try_acquire", " ", TAU_USER); int result = pthread_mutex_trylock(&_lock); assert(result == 0 || result == EBUSY); return (result == 0); diff --git a/dtool/src/dtoolbase/mutexPosixImpl.h b/dtool/src/dtoolbase/mutexPosixImpl.h index 62faa2c353..4702b2dbea 100644 --- a/dtool/src/dtoolbase/mutexPosixImpl.h +++ b/dtool/src/dtoolbase/mutexPosixImpl.h @@ -33,8 +33,8 @@ public: INLINE MutexPosixImpl(); INLINE ~MutexPosixImpl(); - INLINE void lock(); - INLINE bool try_lock(); + INLINE void acquire(); + INLINE bool try_acquire(); INLINE void release(); private: @@ -51,8 +51,8 @@ public: INLINE ReMutexPosixImpl(); INLINE ~ReMutexPosixImpl(); - INLINE void lock(); - INLINE bool try_lock(); + INLINE void acquire(); + INLINE bool try_acquire(); INLINE void release(); private: diff --git a/dtool/src/dtoolbase/mutexSpinlockImpl.I b/dtool/src/dtoolbase/mutexSpinlockImpl.I index 74bbd4e033..daa76bd7d0 100644 --- a/dtool/src/dtoolbase/mutexSpinlockImpl.I +++ b/dtool/src/dtoolbase/mutexSpinlockImpl.I @@ -33,24 +33,24 @@ INLINE MutexSpinlockImpl:: } //////////////////////////////////////////////////////////////////// -// Function: MutexSpinlockImpl::lock +// Function: MutexSpinlockImpl::acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE void MutexSpinlockImpl:: -lock() { - if (!try_lock()) { +acquire() { + if (!try_acquire()) { do_lock(); } } //////////////////////////////////////////////////////////////////// -// Function: MutexSpinlockImpl::try_lock +// Function: MutexSpinlockImpl::try_acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE bool MutexSpinlockImpl:: -try_lock() { +try_acquire() { return (AtomicAdjust::compare_and_exchange(_lock, 0, 1) == 0); } diff --git a/dtool/src/dtoolbase/mutexSpinlockImpl.h b/dtool/src/dtoolbase/mutexSpinlockImpl.h index e7f550ef94..9956522e2b 100644 --- a/dtool/src/dtoolbase/mutexSpinlockImpl.h +++ b/dtool/src/dtoolbase/mutexSpinlockImpl.h @@ -36,8 +36,8 @@ public: INLINE MutexSpinlockImpl(); INLINE ~MutexSpinlockImpl(); - INLINE void lock(); - INLINE bool try_lock(); + INLINE void acquire(); + INLINE bool try_acquire(); INLINE void release(); private: diff --git a/dtool/src/dtoolbase/mutexWin32Impl.I b/dtool/src/dtoolbase/mutexWin32Impl.I index e6b8257178..0cc9202b36 100644 --- a/dtool/src/dtoolbase/mutexWin32Impl.I +++ b/dtool/src/dtoolbase/mutexWin32Impl.I @@ -24,22 +24,22 @@ INLINE MutexWin32Impl:: } //////////////////////////////////////////////////////////////////// -// Function: MutexWin32Impl::lock +// Function: MutexWin32Impl::acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE void MutexWin32Impl:: -lock() { +acquire() { EnterCriticalSection(&_lock); } //////////////////////////////////////////////////////////////////// -// Function: MutexWin32Impl::try_lock +// Function: MutexWin32Impl::try_acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE bool MutexWin32Impl:: -try_lock() { +try_acquire() { return (TryEnterCriticalSection(&_lock) != 0); } diff --git a/dtool/src/dtoolbase/mutexWin32Impl.h b/dtool/src/dtoolbase/mutexWin32Impl.h index ff2b045175..5513d120a8 100644 --- a/dtool/src/dtoolbase/mutexWin32Impl.h +++ b/dtool/src/dtoolbase/mutexWin32Impl.h @@ -31,8 +31,8 @@ public: MutexWin32Impl(); INLINE ~MutexWin32Impl(); - INLINE void lock(); - INLINE bool try_lock(); + INLINE void acquire(); + INLINE bool try_acquire(); INLINE void release(); private: diff --git a/dtool/src/dtoolbase/neverFreeMemory.I b/dtool/src/dtoolbase/neverFreeMemory.I index f36fc655da..5371fe16d3 100644 --- a/dtool/src/dtoolbase/neverFreeMemory.I +++ b/dtool/src/dtoolbase/neverFreeMemory.I @@ -57,7 +57,7 @@ get_total_used() { INLINE size_t NeverFreeMemory:: get_total_unused() { NeverFreeMemory *global_ptr = get_global_ptr(); - global_ptr->_lock.lock(); + global_ptr->_lock.acquire(); size_t total_unused = global_ptr->_total_alloc - global_ptr->_total_used; global_ptr->_lock.release(); return total_unused; diff --git a/dtool/src/dtoolbase/neverFreeMemory.cxx b/dtool/src/dtoolbase/neverFreeMemory.cxx index 8b522055d0..9c2e95ea12 100644 --- a/dtool/src/dtoolbase/neverFreeMemory.cxx +++ b/dtool/src/dtoolbase/neverFreeMemory.cxx @@ -43,7 +43,7 @@ NeverFreeMemory() { //////////////////////////////////////////////////////////////////// void *NeverFreeMemory:: ns_alloc(size_t size) { - _lock.lock(); + _lock.acquire(); _total_used += size; diff --git a/dtool/src/dtoolbase/typeRegistry.cxx b/dtool/src/dtoolbase/typeRegistry.cxx index d7e768d5de..e6fff486ef 100644 --- a/dtool/src/dtoolbase/typeRegistry.cxx +++ b/dtool/src/dtoolbase/typeRegistry.cxx @@ -37,7 +37,7 @@ TypeRegistry *TypeRegistry::_global_pointer = NULL; //////////////////////////////////////////////////////////////////// bool TypeRegistry:: register_type(TypeHandle &type_handle, const string &name) { - _lock->lock(); + _lock->acquire(); if (type_handle != TypeHandle::none()) { // Here's a type that was already registered. Just make sure @@ -124,7 +124,7 @@ register_type(TypeHandle &type_handle, const string &name) { //////////////////////////////////////////////////////////////////// TypeHandle TypeRegistry:: register_dynamic_type(const string &name) { - _lock->lock(); + _lock->acquire(); NameRegistry::iterator ri; ri = _name_registry.find(name); @@ -165,7 +165,7 @@ register_dynamic_type(const string &name) { //////////////////////////////////////////////////////////////////// void TypeRegistry:: record_derivation(TypeHandle child, TypeHandle parent) { - _lock->lock(); + _lock->acquire(); TypeRegistryNode *cnode = look_up(child, NULL); assert(cnode != (TypeRegistryNode *)NULL); @@ -198,7 +198,7 @@ record_derivation(TypeHandle child, TypeHandle parent) { //////////////////////////////////////////////////////////////////// void TypeRegistry:: record_alternate_name(TypeHandle type, const string &name) { - _lock->lock(); + _lock->acquire(); TypeRegistryNode *rnode = look_up(type, (TypedObject *)NULL); if (rnode != (TypeRegistryNode *)NULL) { @@ -223,7 +223,7 @@ record_alternate_name(TypeHandle type, const string &name) { //////////////////////////////////////////////////////////////////// TypeHandle TypeRegistry:: find_type(const string &name) const { - _lock->lock(); + _lock->acquire(); TypeHandle handle = TypeHandle::none(); NameRegistry::const_iterator ri; @@ -249,7 +249,7 @@ find_type(const string &name) const { //////////////////////////////////////////////////////////////////// string TypeRegistry:: get_name(TypeHandle type, TypedObject *object) const { - _lock->lock(); + _lock->acquire(); TypeRegistryNode *rnode = look_up(type, object); assert(rnode != (TypeRegistryNode *)NULL); string name = rnode->_name; @@ -279,7 +279,7 @@ get_name(TypeHandle type, TypedObject *object) const { bool TypeRegistry:: is_derived_from(TypeHandle child, TypeHandle base, TypedObject *child_object) { - _lock->lock(); + _lock->acquire(); const TypeRegistryNode *child_node = look_up(child, child_object); const TypeRegistryNode *base_node = look_up(base, (TypedObject *)NULL); @@ -300,7 +300,7 @@ is_derived_from(TypeHandle child, TypeHandle base, //////////////////////////////////////////////////////////////////// int TypeRegistry:: get_num_typehandles() { - _lock->lock(); + _lock->acquire(); int num_types = (int)_handle_registry.size(); _lock->release(); return num_types; @@ -314,7 +314,7 @@ get_num_typehandles() { //////////////////////////////////////////////////////////////////// TypeHandle TypeRegistry:: get_typehandle(int n) { - _lock->lock(); + _lock->acquire(); TypeRegistryNode *rnode = NULL; if (n >= 0 && n < (int)_handle_registry.size()) { rnode = _handle_registry[n]; @@ -337,7 +337,7 @@ get_typehandle(int n) { //////////////////////////////////////////////////////////////////// int TypeRegistry:: get_num_root_classes() { - _lock->lock(); + _lock->acquire(); freshen_derivations(); int num_roots = _root_classes.size(); _lock->release(); @@ -352,7 +352,7 @@ get_num_root_classes() { //////////////////////////////////////////////////////////////////// TypeHandle TypeRegistry:: get_root_class(int n) { - _lock->lock(); + _lock->acquire(); freshen_derivations(); TypeHandle handle; if (n >= 0 && n < (int)_root_classes.size()) { @@ -381,7 +381,7 @@ get_root_class(int n) { //////////////////////////////////////////////////////////////////// int TypeRegistry:: get_num_parent_classes(TypeHandle child, TypedObject *child_object) const { - _lock->lock(); + _lock->acquire(); TypeRegistryNode *rnode = look_up(child, child_object); assert(rnode != (TypeRegistryNode *)NULL); int num_parents = rnode->_parent_classes.size(); @@ -398,7 +398,7 @@ get_num_parent_classes(TypeHandle child, TypedObject *child_object) const { //////////////////////////////////////////////////////////////////// TypeHandle TypeRegistry:: get_parent_class(TypeHandle child, int index) const { - _lock->lock(); + _lock->acquire(); TypeHandle handle; TypeRegistryNode *rnode = look_up(child, (TypedObject *)NULL); assert(rnode != (TypeRegistryNode *)NULL); @@ -423,7 +423,7 @@ get_parent_class(TypeHandle child, int index) const { //////////////////////////////////////////////////////////////////// int TypeRegistry:: get_num_child_classes(TypeHandle child, TypedObject *child_object) const { - _lock->lock(); + _lock->acquire(); TypeRegistryNode *rnode = look_up(child, child_object); assert(rnode != (TypeRegistryNode *)NULL); int num_children = rnode->_child_classes.size(); @@ -440,7 +440,7 @@ get_num_child_classes(TypeHandle child, TypedObject *child_object) const { //////////////////////////////////////////////////////////////////// TypeHandle TypeRegistry:: get_child_class(TypeHandle child, int index) const { - _lock->lock(); + _lock->acquire(); TypeHandle handle; TypeRegistryNode *rnode = look_up(child, (TypedObject *)NULL); assert(rnode != (TypeRegistryNode *)NULL); @@ -468,7 +468,7 @@ get_child_class(TypeHandle child, int index) const { TypeHandle TypeRegistry:: get_parent_towards(TypeHandle child, TypeHandle base, TypedObject *child_object) { - _lock->lock(); + _lock->acquire(); TypeHandle handle; const TypeRegistryNode *child_node = look_up(child, child_object); const TypeRegistryNode *base_node = look_up(base, NULL); @@ -495,7 +495,7 @@ get_parent_towards(TypeHandle child, TypeHandle base, void TypeRegistry:: reregister_types() { init_lock(); - _lock->lock(); + _lock->acquire(); HandleRegistry::iterator ri; TypeRegistry *reg = ptr(); for (ri = reg->_handle_registry.begin(); @@ -519,7 +519,7 @@ reregister_types() { //////////////////////////////////////////////////////////////////// void TypeRegistry:: write(ostream &out) const { - _lock->lock(); + _lock->acquire(); do_write(out); _lock->release(); } @@ -533,7 +533,7 @@ write(ostream &out) const { TypeRegistry *TypeRegistry:: ptr() { init_lock(); - _lock->lock(); + _lock->acquire(); if (_global_pointer == NULL) { init_global_pointer(); } @@ -688,7 +688,7 @@ look_up(TypeHandle handle, TypedObject *object) const { // the lock while we do this, so we don't get a recursive lock. _lock->release(); handle = object->force_init_type(); - _lock->lock(); + _lock->acquire(); if (handle._index == 0) { // Strange. cerr diff --git a/panda/src/audiotraits/milesAudioManager.cxx b/panda/src/audiotraits/milesAudioManager.cxx index 875b7c7544..aa158fdc3a 100644 --- a/panda/src/audiotraits/milesAudioManager.cxx +++ b/panda/src/audiotraits/milesAudioManager.cxx @@ -523,7 +523,7 @@ cleanup() { MutexHolder holder(_streams_lock); nassertv(!_stream_thread.is_null()); _stream_thread->_keep_running = false; - _streams_cvar.signal(); + _streams_cvar.notify(); old_thread = _stream_thread; _stream_thread.clear(); } @@ -658,7 +658,7 @@ start_service_stream(HSTREAM stream) { MutexHolder holder(_streams_lock); nassertv(find(_streams.begin(), _streams.end(), stream) == _streams.end()); _streams.push_back(stream); - _streams_cvar.signal(); + _streams_cvar.notify(); if (_stream_thread.is_null() && Thread::is_threading_supported()) { milesAudio_cat.info() @@ -901,7 +901,7 @@ thread_main(volatile bool &keep_running) { // Now yield to be polite to the main application. _streams_lock.release(); Thread::force_yield(); - _streams_lock.lock(); + _streams_lock.acquire(); } } @@ -921,7 +921,7 @@ do_service_streams() { _streams_lock.release(); AIL_service_stream(stream, 0); Thread::consider_yield(); - _streams_lock.lock(); + _streams_lock.acquire(); ++i; } diff --git a/panda/src/chan/animControl.cxx b/panda/src/chan/animControl.cxx index b460ce5d9e..110a52a434 100644 --- a/panda/src/chan/animControl.cxx +++ b/panda/src/chan/animControl.cxx @@ -75,7 +75,7 @@ setup_anim(PartBundle *part, AnimBundle *anim, int channel_index, // Now the AnimControl is fully set up. _marked_frame = -1; _pending = false; - _pending_cvar.signal_all(); + _pending_cvar.notify_all(); if (!_pending_done_event.empty()) { throw_event(_pending_done_event); } @@ -105,7 +105,7 @@ fail_anim(PartBundle *part) { MutexHolder holder(_pending_lock); nassertv(_pending && part == _part); _pending = false; - _pending_cvar.signal_all(); + _pending_cvar.notify_all(); if (!_pending_done_event.empty()) { throw_event(_pending_done_event); } diff --git a/panda/src/device/analogNode.I b/panda/src/device/analogNode.I index 699e72f049..9747587b73 100644 --- a/panda/src/device/analogNode.I +++ b/panda/src/device/analogNode.I @@ -44,7 +44,7 @@ is_valid() const { //////////////////////////////////////////////////////////////////// INLINE int AnalogNode:: get_num_controls() const { - _analog->lock(); + _analog->acquire(); int result = _analog->get_num_controls(); _analog->unlock(); return result; @@ -60,7 +60,7 @@ get_num_controls() const { //////////////////////////////////////////////////////////////////// INLINE double AnalogNode:: get_control_state(int index) const { - _analog->lock(); + _analog->acquire(); double result = _analog->get_control_state(index); _analog->unlock(); return result; @@ -75,7 +75,7 @@ get_control_state(int index) const { //////////////////////////////////////////////////////////////////// INLINE bool AnalogNode:: is_control_known(int index) const { - _analog->lock(); + _analog->acquire(); bool result = _analog->is_control_known(index); _analog->unlock(); return result; diff --git a/panda/src/device/analogNode.cxx b/panda/src/device/analogNode.cxx index 7dfee3704b..5531c26578 100644 --- a/panda/src/device/analogNode.cxx +++ b/panda/src/device/analogNode.cxx @@ -74,7 +74,7 @@ write(ostream &out, int indent_level) const { DataNode::write(out, indent_level); if (_analog != (ClientAnalogDevice *)NULL) { - _analog->lock(); + _analog->acquire(); _analog->write_controls(out, indent_level + 2); _analog->unlock(); } @@ -101,7 +101,7 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &, LPoint2f out(0.0f, 0.0f); - _analog->lock(); + _analog->acquire(); for (int i = 0; i < max_outputs; i++) { if (_outputs[i]._index >= 0 && _analog->is_control_known(_outputs[i]._index)) { diff --git a/panda/src/device/buttonNode.I b/panda/src/device/buttonNode.I index afe2545af7..27faac8325 100644 --- a/panda/src/device/buttonNode.I +++ b/panda/src/device/buttonNode.I @@ -36,7 +36,7 @@ is_valid() const { //////////////////////////////////////////////////////////////////// INLINE int ButtonNode:: get_num_buttons() const { - _button->lock(); + _button->acquire(); int result = _button->get_num_buttons(); _button->unlock(); return result; @@ -58,7 +58,7 @@ get_num_buttons() const { //////////////////////////////////////////////////////////////////// INLINE void ButtonNode:: set_button_map(int index, ButtonHandle button) { - _button->lock(); + _button->acquire(); _button->set_button_map(index, button); _button->unlock(); } @@ -73,7 +73,7 @@ set_button_map(int index, ButtonHandle button) { //////////////////////////////////////////////////////////////////// INLINE ButtonHandle ButtonNode:: get_button_map(int index) const { - _button->lock(); + _button->acquire(); ButtonHandle result = _button->get_button_map(index); _button->unlock(); return result; @@ -88,7 +88,7 @@ get_button_map(int index) const { //////////////////////////////////////////////////////////////////// INLINE bool ButtonNode:: get_button_state(int index) const { - _button->lock(); + _button->acquire(); bool result = _button->get_button_state(index); _button->unlock(); return result; @@ -103,7 +103,7 @@ get_button_state(int index) const { //////////////////////////////////////////////////////////////////// INLINE bool ButtonNode:: is_button_known(int index) const { - _button->lock(); + _button->acquire(); bool result = _button->is_button_known(index); _button->unlock(); return result; diff --git a/panda/src/device/buttonNode.cxx b/panda/src/device/buttonNode.cxx index d94c9a4d05..ebae5309a3 100644 --- a/panda/src/device/buttonNode.cxx +++ b/panda/src/device/buttonNode.cxx @@ -75,7 +75,7 @@ output(ostream &out) const { if (_button != (ClientButtonDevice *)NULL) { out << " ("; - _button->lock(); + _button->acquire(); _button->output_buttons(out); _button->unlock(); out << ")"; @@ -92,7 +92,7 @@ write(ostream &out, int indent_level) const { DataNode::write(out, indent_level); if (_button != (ClientButtonDevice *)NULL) { - _button->lock(); + _button->acquire(); _button->write_buttons(out, indent_level + 2); _button->unlock(); } @@ -116,7 +116,7 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &, DataNodeTransmit &output) { if (is_valid()) { _button->poll(); - _button->lock(); + _button->acquire(); (*_button_events) = (*_button->get_button_events()); diff --git a/panda/src/device/clientAnalogDevice.I b/panda/src/device/clientAnalogDevice.I index 1f3c6b2665..c36619d4f1 100644 --- a/panda/src/device/clientAnalogDevice.I +++ b/panda/src/device/clientAnalogDevice.I @@ -52,7 +52,7 @@ get_num_controls() const { // Function: ClientAnalogDevice::set_control_state // Access: Public // Description: Sets the state of the indicated analog index. The -// caller should ensure that lock() is in effect while +// caller should ensure that acquire() is in effect while // this call is made. This should be a number in the // range -1.0 to 1.0, representing the current position // of the control within its total range of movement. diff --git a/panda/src/device/clientButtonDevice.cxx b/panda/src/device/clientButtonDevice.cxx index 1c89b9eafe..e45561ac5a 100644 --- a/panda/src/device/clientButtonDevice.cxx +++ b/panda/src/device/clientButtonDevice.cxx @@ -39,7 +39,7 @@ ClientButtonDevice(ClientBase *client, const string &device_name): // true indicates down, and false indicates up. This // may generate a ButtonEvent if the button has an // associated ButtonHandle. The caller should ensure -// that lock() is in effect while this call is made. +// that acquire() is in effect while this call is made. //////////////////////////////////////////////////////////////////// void ClientButtonDevice:: set_button_state(int index, bool down) { diff --git a/panda/src/device/clientDevice.I b/panda/src/device/clientDevice.I index 2c2b2d3b4b..efcb92e050 100644 --- a/panda/src/device/clientDevice.I +++ b/panda/src/device/clientDevice.I @@ -64,7 +64,7 @@ get_device_name() const { } //////////////////////////////////////////////////////////////////// -// Function: ClientDevice::lock +// Function: ClientDevice::acquire // Access: Public // Description: Grabs the mutex associated with this particular // device. The device will not update asynchronously @@ -73,9 +73,9 @@ get_device_name() const { // during the copy. //////////////////////////////////////////////////////////////////// INLINE void ClientDevice:: -lock() { +acquire() { #ifdef OLD_HAVE_IPC - _lock.lock(); + _lock.acquire(); #endif } @@ -84,7 +84,7 @@ lock() { // Access: Public // Description: Releases the mutex associated with this particular // device. This should be called after all the data has -// been successfully copied out. See lock(). +// been successfully copied out. See acquire(). //////////////////////////////////////////////////////////////////// INLINE void ClientDevice:: unlock() { diff --git a/panda/src/device/clientDevice.cxx b/panda/src/device/clientDevice.cxx index ddd19b6cc6..d7f7aa90f4 100644 --- a/panda/src/device/clientDevice.cxx +++ b/panda/src/device/clientDevice.cxx @@ -73,7 +73,7 @@ ClientDevice:: void ClientDevice:: disconnect() { if (_is_connected) { - lock(); + acquire(); bool disconnected = _client->disconnect_device(_device_type, _device_name, this); _is_connected = false; diff --git a/panda/src/device/clientDevice.h b/panda/src/device/clientDevice.h index c5a68d52ff..b0dbb116e3 100644 --- a/panda/src/device/clientDevice.h +++ b/panda/src/device/clientDevice.h @@ -48,7 +48,7 @@ public: void disconnect(); void poll(); - INLINE void lock(); + INLINE void acquire(); INLINE void unlock(); virtual void output(ostream &out) const; diff --git a/panda/src/device/clientDialDevice.I b/panda/src/device/clientDialDevice.I index b59550eb37..f14e8a6e87 100644 --- a/panda/src/device/clientDialDevice.I +++ b/panda/src/device/clientDialDevice.I @@ -52,7 +52,7 @@ get_num_dials() const { // Access: Public // Description: Marks that the dial has been offset by the indicated // amount. It is the user's responsibility to ensure -// that this call is protected within lock(). +// that this call is protected within acquire(). //////////////////////////////////////////////////////////////////// INLINE void ClientDialDevice:: push_dial(int index, double offset) { @@ -71,7 +71,7 @@ push_dial(int index, double offset) { // to read the dial without resetting the counter. // // It is the user's responsibility to ensure that this -// call is protected within lock(). +// call is protected within acquire(). //////////////////////////////////////////////////////////////////// INLINE double ClientDialDevice:: read_dial(int index) { diff --git a/panda/src/device/dialNode.I b/panda/src/device/dialNode.I index 043773a9a3..bd04635e46 100644 --- a/panda/src/device/dialNode.I +++ b/panda/src/device/dialNode.I @@ -33,7 +33,7 @@ is_valid() const { //////////////////////////////////////////////////////////////////// INLINE int DialNode:: get_num_dials() const { - _dial->lock(); + _dial->acquire(); int result = _dial->get_num_dials(); _dial->unlock(); return result; @@ -49,7 +49,7 @@ get_num_dials() const { //////////////////////////////////////////////////////////////////// INLINE double DialNode:: read_dial(int index) { - _dial->lock(); + _dial->acquire(); double result = _dial->read_dial(index); _dial->unlock(); return result; @@ -64,7 +64,7 @@ read_dial(int index) { //////////////////////////////////////////////////////////////////// INLINE bool DialNode:: is_dial_known(int index) const { - _dial->lock(); + _dial->acquire(); bool result = _dial->is_dial_known(index); _dial->unlock(); return result; diff --git a/panda/src/device/trackerNode.cxx b/panda/src/device/trackerNode.cxx index 5c1eef0112..750ed1f880 100644 --- a/panda/src/device/trackerNode.cxx +++ b/panda/src/device/trackerNode.cxx @@ -84,7 +84,7 @@ do_transmit_data(DataGraphTraverser *, const DataNodeTransmit &, DataNodeTransmit &output) { if (is_valid()) { _tracker->poll(); - _tracker->lock(); + _tracker->acquire(); _data = _tracker->get_data(); _tracker->unlock(); diff --git a/panda/src/display/graphicsEngine.cxx b/panda/src/display/graphicsEngine.cxx index aa404ccfb5..cd22b64aa2 100644 --- a/panda/src/display/graphicsEngine.cxx +++ b/panda/src/display/graphicsEngine.cxx @@ -673,7 +673,7 @@ render_frame() { Threads::const_iterator ti; for (ti = _threads.begin(); ti != _threads.end(); ++ti) { RenderThread *thread = (*ti).second; - thread->_cv_mutex.lock(); + thread->_cv_mutex.acquire(); while (thread->_thread_state != TS_wait) { thread->_cv_done.wait(); @@ -789,7 +789,7 @@ render_frame() { RenderThread *thread = (*ti).second; if (thread->_thread_state == TS_wait) { thread->_thread_state = TS_do_frame; - thread->_cv_start.signal(); + thread->_cv_start.notify(); } thread->_cv_mutex.release(); } @@ -849,14 +849,14 @@ open_windows() { Threads::const_iterator ti; for (ti = _threads.begin(); ti != _threads.end(); ++ti) { RenderThread *thread = (*ti).second; - thread->_cv_mutex.lock(); + thread->_cv_mutex.acquire(); while (thread->_thread_state != TS_wait) { thread->_cv_done.wait(); } thread->_thread_state = TS_do_windows; - thread->_cv_start.signal(); + thread->_cv_start.notify(); thread->_cv_mutex.release(); } } @@ -1476,7 +1476,7 @@ do_sync_frame(Thread *current_thread) { Threads::const_iterator ti; for (ti = _threads.begin(); ti != _threads.end(); ++ti) { RenderThread *thread = (*ti).second; - thread->_cv_mutex.lock(); + thread->_cv_mutex.acquire(); thread->_cv_mutex.release(); } @@ -1506,7 +1506,7 @@ do_flip_frame(Thread *current_thread) { Threads::const_iterator ti; for (ti = _threads.begin(); ti != _threads.end(); ++ti) { RenderThread *thread = (*ti).second; - thread->_cv_mutex.lock(); + thread->_cv_mutex.acquire(); while (thread->_thread_state != TS_wait) { thread->_cv_done.wait(); @@ -1523,7 +1523,7 @@ do_flip_frame(Thread *current_thread) { RenderThread *thread = (*ti).second; nassertv(thread->_thread_state == TS_wait); thread->_thread_state = TS_do_flip; - thread->_cv_start.signal(); + thread->_cv_start.notify(); thread->_cv_mutex.release(); } } @@ -2083,14 +2083,14 @@ terminate_threads(Thread *current_thread) { Threads::const_iterator ti; for (ti = _threads.begin(); ti != _threads.end(); ++ti) { RenderThread *thread = (*ti).second; - thread->_cv_mutex.lock(); + thread->_cv_mutex.acquire(); } // Now tell them to close their windows and terminate. for (ti = _threads.begin(); ti != _threads.end(); ++ti) { RenderThread *thread = (*ti).second; thread->_thread_state = TS_terminate; - thread->_cv_start.signal(); + thread->_cv_start.notify(); thread->_cv_mutex.release(); } @@ -2578,7 +2578,7 @@ thread_main() { do_pending(_engine, current_thread); do_close(_engine, current_thread); _thread_state = TS_done; - _cv_done.signal(); + _cv_done.notify(); return; case TS_done: @@ -2588,7 +2588,7 @@ thread_main() { } _thread_state = TS_wait; - _cv_done.signal(); + _cv_done.notify(); { PStatTimer timer(_wait_pcollector, current_thread); diff --git a/panda/src/event/asyncTask.cxx b/panda/src/event/asyncTask.cxx index 058bc4f553..bc2c730fab 100644 --- a/panda/src/event/asyncTask.cxx +++ b/panda/src/event/asyncTask.cxx @@ -393,7 +393,7 @@ unlock_and_do_task() { double end = clock->get_real_time(); // Now reacquire the lock (so we can return with the lock held). - _manager->_lock.lock(); + _manager->_lock.acquire(); _dt = end - start; _max_dt = max(_dt, _max_dt); diff --git a/panda/src/event/asyncTaskChain.cxx b/panda/src/event/asyncTaskChain.cxx index 9e44a5f4e6..34f0a7b5db 100644 --- a/panda/src/event/asyncTaskChain.cxx +++ b/panda/src/event/asyncTaskChain.cxx @@ -492,7 +492,7 @@ do_add(AsyncTask *task) { ++(_manager->_num_tasks); _needs_cleanup = true; - _cvar.signal_all(); + _cvar.notify_all(); } //////////////////////////////////////////////////////////////////// @@ -647,7 +647,7 @@ do_cleanup() { for (ti = dead.begin(); ti != dead.end(); ++ti) { (*ti)->upon_death(_manager, false); } - _manager->_lock.lock(); + _manager->_lock.acquire(); if (task_cat.is_spam()) { do_output(task_cat.spam()); @@ -750,7 +750,7 @@ service_one_task(AsyncTaskChain::AsyncTaskChainThread *thread) { // queue. task->_state = AsyncTask::S_active; _next_active.push_back(task); - _cvar.signal_all(); + _cvar.notify_all(); break; case AsyncTask::DS_again: @@ -767,7 +767,7 @@ service_one_task(AsyncTaskChain::AsyncTaskChainThread *thread) { << "Sleeping " << *task << ", wake time at " << task->get_wake_time() - now << "\n"; } - _cvar.signal_all(); + _cvar.notify_all(); } break; @@ -775,7 +775,7 @@ service_one_task(AsyncTaskChain::AsyncTaskChainThread *thread) { // The task wants to run again this frame if possible. task->_state = AsyncTask::S_active; _this_active.push_back(task); - _cvar.signal_all(); + _cvar.notify_all(); break; case AsyncTask::DS_interrupt: @@ -784,7 +784,7 @@ service_one_task(AsyncTaskChain::AsyncTaskChainThread *thread) { _next_active.push_back(task); if (_state == S_started) { _state = S_interrupted; - _cvar.signal_all(); + _cvar.notify_all(); } break; @@ -844,7 +844,7 @@ cleanup_task(AsyncTask *task, bool upon_death, bool clean_exit) { if (upon_death) { _manager->_lock.release(); task->upon_death(_manager, clean_exit); - _manager->_lock.lock(); + _manager->_lock.acquire(); } } @@ -872,7 +872,7 @@ finish_sort_group() { // There are more tasks; just set the next sort value. nassertr(_current_sort < _active.front()->get_sort(), true); _current_sort = _active.front()->get_sort(); - _cvar.signal_all(); + _cvar.notify_all(); return true; } @@ -922,7 +922,7 @@ finish_sort_group() { << ": tick clock\n"; } _manager->_clock->tick(); - _manager->_frame_cvar.signal_all(); + _manager->_frame_cvar.notify_all(); } // Check for any sleeping tasks that need to be woken. @@ -972,7 +972,7 @@ finish_sort_group() { if (!_active.empty()) { // Signal the threads to start executing the first task again. - _cvar.signal_all(); + _cvar.notify_all(); return true; } @@ -1079,8 +1079,8 @@ do_stop_threads() { } _state = S_shutdown; - _cvar.signal_all(); - _manager->_frame_cvar.signal_all(); + _cvar.notify_all(); + _manager->_frame_cvar.notify_all(); Threads wait_threads; wait_threads.swap(_threads); @@ -1102,7 +1102,7 @@ do_stop_threads() { << *Thread::get_current_thread() << "\n"; } } - _manager->_lock.lock(); + _manager->_lock.acquire(); _state = S_initial; @@ -1246,7 +1246,7 @@ do_poll() { _num_busy_threads++; service_one_task(NULL); _num_busy_threads--; - _cvar.signal_all(); + _cvar.notify_all(); if (!_threads.empty()) { return; @@ -1505,7 +1505,7 @@ thread_main() { _chain->_num_busy_threads++; _chain->service_one_task(this); _chain->_num_busy_threads--; - _chain->_cvar.signal_all(); + _chain->_cvar.notify_all(); } else { // We've finished all the available tasks of the current sort diff --git a/panda/src/event/asyncTaskManager.cxx b/panda/src/event/asyncTaskManager.cxx index cdb3de2840..6210a87542 100644 --- a/panda/src/event/asyncTaskManager.cxx +++ b/panda/src/event/asyncTaskManager.cxx @@ -226,7 +226,7 @@ add(AsyncTask *task) { _lock.release(); task->upon_birth(this); - _lock.lock(); + _lock.acquire(); nassertv(task->_manager == NULL && task->_state == AsyncTask::S_inactive); nassertv(!do_has_task(task)); @@ -379,7 +379,7 @@ remove(const AsyncTaskCollection &tasks) { if (task->_chain->do_remove(task)) { _lock.release(); task->upon_death(this, false); - _lock.lock(); + _lock.acquire(); ++num_removed; } else { if (task_cat.is_debug()) { @@ -548,7 +548,7 @@ poll() { // Just in case the clock was ticked explicitly by one of our // polling chains. - _frame_cvar.signal_all(); + _frame_cvar.notify_all(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/express/subStreamBuf.cxx b/panda/src/express/subStreamBuf.cxx index f82ca8f57b..fb1a5c44bc 100644 --- a/panda/src/express/subStreamBuf.cxx +++ b/panda/src/express/subStreamBuf.cxx @@ -138,7 +138,7 @@ seekoff(streamoff off, ios_seekdir dir, ios_openmode mode) { if (_end == (streampos)0) { // If the end of the file is unspecified, we have to seek to // find it. - _lock.lock(); + _lock.acquire(); _source->seekg(off, ios::end); new_pos = _source->tellg(); _lock.release(); @@ -239,7 +239,7 @@ underflow() { gbump(-(int)num_bytes); nassertr(gptr() + num_bytes <= egptr(), EOF); - _lock.lock(); + _lock.acquire(); _source->seekg(_cur); _source->read(gptr(), num_bytes); size_t read_count = _source->gcount(); diff --git a/panda/src/express/trueClock.I b/panda/src/express/trueClock.I index 73d2f0b39a..3787481318 100644 --- a/panda/src/express/trueClock.I +++ b/panda/src/express/trueClock.I @@ -25,7 +25,7 @@ get_short_time() { bool is_paranoid_clock = get_paranoid_clock(); if (is_paranoid_clock) { - _lock.lock(); + _lock.acquire(); } double time = get_short_raw_time(); diff --git a/panda/src/express/weakReferenceList.cxx b/panda/src/express/weakReferenceList.cxx index 952d7c40b9..045bf2d343 100644 --- a/panda/src/express/weakReferenceList.cxx +++ b/panda/src/express/weakReferenceList.cxx @@ -33,7 +33,7 @@ WeakReferenceList() { //////////////////////////////////////////////////////////////////// WeakReferenceList:: ~WeakReferenceList() { - _lock.lock(); + _lock.acquire(); Pointers::iterator pi; for (pi = _pointers.begin(); pi != _pointers.end(); ++pi) { (*pi)->mark_deleted(); @@ -56,7 +56,7 @@ WeakReferenceList:: //////////////////////////////////////////////////////////////////// void WeakReferenceList:: add_reference(WeakPointerToVoid *ptv) { - _lock.lock(); + _lock.acquire(); bool inserted = _pointers.insert(ptv).second; _lock.release(); nassertv(inserted); @@ -73,7 +73,7 @@ add_reference(WeakPointerToVoid *ptv) { //////////////////////////////////////////////////////////////////// void WeakReferenceList:: clear_reference(WeakPointerToVoid *ptv) { - _lock.lock(); + _lock.acquire(); Pointers::iterator pi = _pointers.find(ptv); bool valid = (pi != _pointers.end()); if (valid) { diff --git a/panda/src/gobj/adaptiveLru.cxx b/panda/src/gobj/adaptiveLru.cxx index 36ef45e175..57a942162e 100644 --- a/panda/src/gobj/adaptiveLru.cxx +++ b/panda/src/gobj/adaptiveLru.cxx @@ -391,7 +391,7 @@ do_evict_to(size_t target_size, bool hard_evict) { // We must release the lock while we call evict_lru(). _lock.release(); page->evict_lru(); - _lock.lock(); + _lock.acquire(); if (_total_size <= target_size) { // We've evicted enough to satisfy our target. diff --git a/panda/src/gobj/geomMunger.cxx b/panda/src/gobj/geomMunger.cxx index 1300617883..4848f48c72 100644 --- a/panda/src/gobj/geomMunger.cxx +++ b/panda/src/gobj/geomMunger.cxx @@ -118,7 +118,7 @@ munge_geom(CPT(Geom) &geom, CPT(GeomVertexData) &data, Geom::CacheKey key(source_data, this); - geom->_cache_lock.lock(); + geom->_cache_lock.acquire(); Geom::Cache::const_iterator ci = geom->_cache.find(&key); if (ci == geom->_cache.end()) { geom->_cache_lock.release(); diff --git a/panda/src/gobj/geomVertexArrayData.I b/panda/src/gobj/geomVertexArrayData.I index e683eb105c..ed717fa383 100644 --- a/panda/src/gobj/geomVertexArrayData.I +++ b/panda/src/gobj/geomVertexArrayData.I @@ -300,7 +300,7 @@ GeomVertexArrayDataHandle(const GeomVertexArrayData *object, #endif // DO_PIPELINING // We must grab the lock *after* we have incremented the reference // count, above. - _cdata->_rw_lock.lock(); + _cdata->_rw_lock.acquire(); #ifdef DO_MEMORY_USAGE MemoryUsage::update_type(this, get_class_type()); #endif diff --git a/panda/src/gobj/geomVertexData.cxx b/panda/src/gobj/geomVertexData.cxx index 07c734a1b6..1a6e99ebc8 100644 --- a/panda/src/gobj/geomVertexData.cxx +++ b/panda/src/gobj/geomVertexData.cxx @@ -754,7 +754,7 @@ convert_to(const GeomVertexFormat *new_format) const { CacheKey key(new_format); - _cache_lock.lock(); + _cache_lock.acquire(); Cache::const_iterator ci = _cache.find(&key); if (ci == _cache.end()) { _cache_lock.release(); diff --git a/panda/src/gobj/simpleLru.cxx b/panda/src/gobj/simpleLru.cxx index fcd94d0647..a1d7b01ae7 100644 --- a/panda/src/gobj/simpleLru.cxx +++ b/panda/src/gobj/simpleLru.cxx @@ -190,7 +190,7 @@ do_evict_to(size_t target_size, bool hard_evict) { // We must release the lock while we call evict_lru(). _global_lock.release(); node->evict_lru(); - _global_lock.lock(); + _global_lock.acquire(); if (node == end || node == _prev) { // If we reach the original tail of the list, stop. diff --git a/panda/src/gobj/texture.cxx b/panda/src/gobj/texture.cxx index 76f128ddb6..ed89c5d70c 100644 --- a/panda/src/gobj/texture.cxx +++ b/panda/src/gobj/texture.cxx @@ -2869,10 +2869,10 @@ do_write_txo(ostream &out, const string &filename) const { // will need to grab the lock). _lock.release(); if (!writer.write_object(this)) { - _lock.lock(); + _lock.acquire(); return false; } - _lock.lock(); + _lock.acquire(); if (!do_has_ram_image()) { gobj_cat.error() @@ -2918,7 +2918,7 @@ do_unlock_and_reload_ram_image(bool allow_compression) { // own mutex is left unlocked. tex->do_reload_ram_image(allow_compression); - _lock.lock(); + _lock.acquire(); do_assign(*tex); nassertv(_reloading); @@ -2931,7 +2931,7 @@ do_unlock_and_reload_ram_image(bool allow_compression) { ++_image_modified; ++_properties_modified; - _cvar.signal_all(); + _cvar.notify_all(); } } diff --git a/panda/src/gobj/vertexDataPage.cxx b/panda/src/gobj/vertexDataPage.cxx index 47d19f11ce..fce892a36d 100644 --- a/panda/src/gobj/vertexDataPage.cxx +++ b/panda/src/gobj/vertexDataPage.cxx @@ -864,7 +864,7 @@ add_page(VertexDataPage *page, RamClass ram_class) { } else { _pending_writes.push_back(page); } - _pending_cvar.signal(); + _pending_cvar.notify(); } } @@ -891,7 +891,7 @@ remove_page(VertexDataPage *page) { while (page == thread->_working_page) { thread->_working_cvar.wait(); } - page->_lock.lock(); + page->_lock.acquire(); return; } } @@ -980,7 +980,7 @@ stop_threads() { { MutexHolder holder(_tlock); _shutdown = true; - _pending_cvar.signal_all(); + _pending_cvar.notify_all(); threads.swap(_threads); } @@ -1013,7 +1013,7 @@ PageThread(PageThreadManager *manager, const string &name) : //////////////////////////////////////////////////////////////////// void VertexDataPage::PageThread:: thread_main() { - _tlock.lock(); + _tlock.acquire(); while (true) { PStatClient::thread_tick(get_sync_name()); @@ -1060,10 +1060,10 @@ thread_main() { } } - _tlock.lock(); + _tlock.acquire(); _working_page = NULL; - _working_cvar.signal(); + _working_cvar.notify(); Thread::consider_yield(); } diff --git a/panda/src/net/datagramQueue.cxx b/panda/src/net/datagramQueue.cxx index 45fb1b80a8..39fa7e4b32 100644 --- a/panda/src/net/datagramQueue.cxx +++ b/panda/src/net/datagramQueue.cxx @@ -56,7 +56,7 @@ shutdown() { MutexHolder holder(_cvlock); _shutdown = true; - _cv.signal_all(); + _cv.notify_all(); } @@ -88,7 +88,7 @@ insert(const NetDatagram &data, bool block) { if (enqueue_ok) { _queue.push_back(data); } - _cv.signal(); // Only need to wake up one thread. + _cv.notify(); // Only need to wake up one thread. return enqueue_ok; } @@ -133,7 +133,7 @@ extract(NetDatagram &result) { _queue.pop_front(); // Wake up any threads waiting to stuff things into the queue. - _cv.signal_all(); + _cv.notify_all(); return true; } diff --git a/panda/src/pipeline/Sources.pp b/panda/src/pipeline/Sources.pp index 8d218a19bb..6f2b1e2d47 100644 --- a/panda/src/pipeline/Sources.pp +++ b/panda/src/pipeline/Sources.pp @@ -60,6 +60,7 @@ reMutex.I reMutex.h \ reMutexDirect.h reMutexDirect.I \ reMutexHolder.I reMutexHolder.h \ + semaphore.h semaphore.I \ thread.h thread.I threadImpl.h \ threadDummyImpl.h threadDummyImpl.I \ threadPosixImpl.h threadPosixImpl.I \ @@ -112,6 +113,7 @@ reMutex.cxx \ reMutexDirect.cxx \ reMutexHolder.cxx \ + semaphore.cxx \ thread.cxx \ threadDummyImpl.cxx \ threadPosixImpl.cxx \ @@ -170,6 +172,7 @@ reMutex.I reMutex.h \ reMutexDirect.h reMutexDirect.I \ reMutexHolder.I reMutexHolder.h \ + semaphore.h semaphore.I \ thread.h thread.I threadImpl.h \ threadDummyImpl.h threadDummyImpl.I \ threadPosixImpl.h threadPosixImpl.I \ diff --git a/panda/src/pipeline/conditionVar.I b/panda/src/pipeline/conditionVar.I index ace77816b8..3ba6c0ff06 100644 --- a/panda/src/pipeline/conditionVar.I +++ b/panda/src/pipeline/conditionVar.I @@ -71,12 +71,12 @@ operator = (const ConditionVar ©) { //////////////////////////////////////////////////////////////////// // Function: ConditionVar::signal_all // Access: Private -// Description: The signal_all() method is specifically *not* +// Description: The notify_all() method is specifically *not* // provided by ConditionVar. Use ConditionVarFull if // you need to call this method. //////////////////////////////////////////////////////////////////// INLINE void ConditionVar:: -signal_all() { +notify_all() { nassertv(false); } diff --git a/panda/src/pipeline/conditionVar.h b/panda/src/pipeline/conditionVar.h index 0912345b43..a45acdd840 100644 --- a/panda/src/pipeline/conditionVar.h +++ b/panda/src/pipeline/conditionVar.h @@ -56,13 +56,13 @@ private: // These methods are inherited from the base class. // INLINE void wait(); - // INLINE void signal(); + // INLINE void notify(); private: - // The signal_all() method is specifically *not* provided by + // The notify_all() method is specifically *not* provided by // ConditionVar. Use ConditionVarFull if you need to call this // method. - INLINE void signal_all(); + INLINE void notify_all(); PUBLISHED: INLINE Mutex &get_mutex() const; diff --git a/panda/src/pipeline/conditionVarDebug.cxx b/panda/src/pipeline/conditionVarDebug.cxx index eaa95d9714..a83e2dd828 100755 --- a/panda/src/pipeline/conditionVarDebug.cxx +++ b/panda/src/pipeline/conditionVarDebug.cxx @@ -53,13 +53,13 @@ ConditionVarDebug:: // variable before calling this function. // // wait() will release the lock, then go to sleep until -// some other thread calls signal() on this condition +// some other thread calls notify() on this condition // variable. At that time at least one thread waiting // on the same ConditionVarDebug will grab the lock again, // and then return from wait(). // // It is possible that wait() will return even if no one -// has called signal(). It is the responsibility of the +// has called notify(). It is the responsibility of the // calling process to verify the condition on return // from wait, and possibly loop back to wait again if // necessary. @@ -72,7 +72,7 @@ ConditionVarDebug:: //////////////////////////////////////////////////////////////////// void ConditionVarDebug:: wait() { - _mutex._global_lock->lock(); + _mutex._global_lock->acquire(); Thread *this_thread = Thread::get_current_thread(); @@ -124,7 +124,7 @@ wait() { //////////////////////////////////////////////////////////////////// void ConditionVarDebug:: wait(double timeout) { - _mutex._global_lock->lock(); + _mutex._global_lock->acquire(); Thread *this_thread = Thread::get_current_thread(); @@ -182,8 +182,8 @@ wait(double timeout) { // signal is lost. //////////////////////////////////////////////////////////////////// void ConditionVarDebug:: -signal() { - _mutex._global_lock->lock(); +notify() { + _mutex._global_lock->acquire(); Thread *this_thread = Thread::get_current_thread(); @@ -201,7 +201,7 @@ signal() { << *this_thread << " signalling " << *this << "\n"; } - _impl.signal(); + _impl.notify(); _mutex._global_lock->release(); } diff --git a/panda/src/pipeline/conditionVarDebug.h b/panda/src/pipeline/conditionVarDebug.h index ce994e9acd..f84034e1b8 100644 --- a/panda/src/pipeline/conditionVarDebug.h +++ b/panda/src/pipeline/conditionVarDebug.h @@ -46,7 +46,7 @@ PUBLISHED: void wait(); void wait(double timeout); - void signal(); + void notify(); virtual void output(ostream &out) const; private: diff --git a/panda/src/pipeline/conditionVarDirect.I b/panda/src/pipeline/conditionVarDirect.I index 2edab10cd0..cc2d14de27 100755 --- a/panda/src/pipeline/conditionVarDirect.I +++ b/panda/src/pipeline/conditionVarDirect.I @@ -81,13 +81,13 @@ get_mutex() const { // variable before calling this function. // // wait() will release the lock, then go to sleep until -// some other thread calls signal() on this condition +// some other thread calls notify() on this condition // variable. At that time at least one thread waiting // on the same ConditionVarDirect will grab the lock again, // and then return from wait(). // // It is possible that wait() will return even if no one -// has called signal(). It is the responsibility of the +// has called notify(). It is the responsibility of the // calling process to verify the condition on return // from wait, and possibly loop back to wait again if // necessary. @@ -139,7 +139,7 @@ wait(double timeout) { // signal is lost. //////////////////////////////////////////////////////////////////// INLINE void ConditionVarDirect:: -signal() { - TAU_PROFILE("ConditionVarDirect::signal()", " ", TAU_USER); - _impl.signal(); +notify() { + TAU_PROFILE("ConditionVarDirect::notify()", " ", TAU_USER); + _impl.notify(); } diff --git a/panda/src/pipeline/conditionVarDirect.h b/panda/src/pipeline/conditionVarDirect.h index e89ef7a64b..1487ec0aef 100644 --- a/panda/src/pipeline/conditionVarDirect.h +++ b/panda/src/pipeline/conditionVarDirect.h @@ -46,7 +46,7 @@ PUBLISHED: BLOCKING INLINE void wait(); BLOCKING INLINE void wait(double timeout); - INLINE void signal(); + INLINE void notify(); void output(ostream &out) const; private: diff --git a/panda/src/pipeline/conditionVarDummyImpl.I b/panda/src/pipeline/conditionVarDummyImpl.I index 6d36399647..431193925b 100644 --- a/panda/src/pipeline/conditionVarDummyImpl.I +++ b/panda/src/pipeline/conditionVarDummyImpl.I @@ -57,7 +57,7 @@ wait(double) { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarDummyImpl:: -signal() { +notify() { } //////////////////////////////////////////////////////////////////// @@ -66,5 +66,5 @@ signal() { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarDummyImpl:: -signal_all() { +notify_all() { } diff --git a/panda/src/pipeline/conditionVarDummyImpl.h b/panda/src/pipeline/conditionVarDummyImpl.h index 3ed611b90c..d5d8b06556 100644 --- a/panda/src/pipeline/conditionVarDummyImpl.h +++ b/panda/src/pipeline/conditionVarDummyImpl.h @@ -36,8 +36,8 @@ public: INLINE void wait(); INLINE void wait(double timeout); - INLINE void signal(); - INLINE void signal_all(); + INLINE void notify(); + INLINE void notify_all(); }; #include "conditionVarDummyImpl.I" diff --git a/panda/src/pipeline/conditionVarFull.h b/panda/src/pipeline/conditionVarFull.h index db962296a1..3c207cbd06 100644 --- a/panda/src/pipeline/conditionVarFull.h +++ b/panda/src/pipeline/conditionVarFull.h @@ -25,21 +25,21 @@ // ConditionVar for a brief introduction to this class. // The ConditionVarFull class provides a more complete // implementation than ConditionVar; in particular, it -// provides the signal_all() method, which is guaranteed +// provides the notify_all() method, which is guaranteed // to wake up all threads currently waiting on the -// condition (whereas signal() is guaranteed to wake up +// condition (whereas notify() is guaranteed to wake up // at least one thread, but may or may not wake up all // of them). // // This class exists because on certain platforms -// (e.g. Win32), implementing signal_all() requires more +// (e.g. Win32), implementing notify_all() requires more // overhead, so you should use ConditionVar for cases -// when you do not require the signal_all() semantics. +// when you do not require the notify_all() semantics. // // There are still some minor semantics that POSIX // condition variables provide which this implementation // does not. For instance, it is required (not -// optional) that the caller of signal() or signal_all() +// optional) that the caller of notify() or notify_all() // is holding the condition variable's mutex before the // call. // diff --git a/panda/src/pipeline/conditionVarFullDebug.cxx b/panda/src/pipeline/conditionVarFullDebug.cxx index 23c6581dab..32fa5e661c 100644 --- a/panda/src/pipeline/conditionVarFullDebug.cxx +++ b/panda/src/pipeline/conditionVarFullDebug.cxx @@ -53,13 +53,13 @@ ConditionVarFullDebug:: // variable before calling this function. // // wait() will release the lock, then go to sleep until -// some other thread calls signal() on this condition +// some other thread calls notify() on this condition // variable. At that time at least one thread waiting // on the same ConditionVarFullDebug will grab the lock again, // and then return from wait(). // // It is possible that wait() will return even if no one -// has called signal(). It is the responsibility of the +// has called notify(). It is the responsibility of the // calling process to verify the condition on return // from wait, and possibly loop back to wait again if // necessary. @@ -72,7 +72,7 @@ ConditionVarFullDebug:: //////////////////////////////////////////////////////////////////// void ConditionVarFullDebug:: wait() { - _mutex._global_lock->lock(); + _mutex._global_lock->acquire(); Thread *this_thread = Thread::get_current_thread(); @@ -124,7 +124,7 @@ wait() { //////////////////////////////////////////////////////////////////// void ConditionVarFullDebug:: wait(double timeout) { - _mutex._global_lock->lock(); + _mutex._global_lock->acquire(); Thread *this_thread = Thread::get_current_thread(); @@ -182,8 +182,8 @@ wait(double timeout) { // signal is lost. //////////////////////////////////////////////////////////////////// void ConditionVarFullDebug:: -signal() { - _mutex._global_lock->lock(); +notify() { + _mutex._global_lock->acquire(); Thread *this_thread = Thread::get_current_thread(); @@ -201,7 +201,7 @@ signal() { << *this_thread << " signalling " << *this << "\n"; } - _impl.signal(); + _impl.notify(); _mutex._global_lock->release(); } @@ -220,8 +220,8 @@ signal() { // signal is lost. //////////////////////////////////////////////////////////////////// void ConditionVarFullDebug:: -signal_all() { - _mutex._global_lock->lock(); +notify_all() { + _mutex._global_lock->acquire(); Thread *this_thread = Thread::get_current_thread(); @@ -239,7 +239,7 @@ signal_all() { << *this_thread << " signalling all " << *this << "\n"; } - _impl.signal_all(); + _impl.notify_all(); _mutex._global_lock->release(); } diff --git a/panda/src/pipeline/conditionVarFullDebug.h b/panda/src/pipeline/conditionVarFullDebug.h index e3907324e8..dc9f5bed97 100644 --- a/panda/src/pipeline/conditionVarFullDebug.h +++ b/panda/src/pipeline/conditionVarFullDebug.h @@ -46,8 +46,8 @@ PUBLISHED: void wait(); void wait(double timeout); - void signal(); - void signal_all(); + void notify(); + void notify_all(); virtual void output(ostream &out) const; private: diff --git a/panda/src/pipeline/conditionVarFullDirect.I b/panda/src/pipeline/conditionVarFullDirect.I index b61ebc1d0e..908e6e8f54 100644 --- a/panda/src/pipeline/conditionVarFullDirect.I +++ b/panda/src/pipeline/conditionVarFullDirect.I @@ -81,13 +81,13 @@ get_mutex() const { // variable before calling this function. // // wait() will release the lock, then go to sleep until -// some other thread calls signal() on this condition +// some other thread calls notify() on this condition // variable. At that time at least one thread waiting // on the same ConditionVarFullDirect will grab the lock again, // and then return from wait(). // // It is possible that wait() will return even if no one -// has called signal(). It is the responsibility of the +// has called notify(). It is the responsibility of the // calling process to verify the condition on return // from wait, and possibly loop back to wait again if // necessary. @@ -139,9 +139,9 @@ wait(double timeout) { // signal is lost. //////////////////////////////////////////////////////////////////// INLINE void ConditionVarFullDirect:: -signal() { - TAU_PROFILE("ConditionVarFullDirect::signal()", " ", TAU_USER); - _impl.signal(); +notify() { + TAU_PROFILE("ConditionVarFullDirect::notify()", " ", TAU_USER); + _impl.notify(); } //////////////////////////////////////////////////////////////////// @@ -159,7 +159,7 @@ signal() { // signal is lost. //////////////////////////////////////////////////////////////////// INLINE void ConditionVarFullDirect:: -signal_all() { - TAU_PROFILE("ConditionVarFullDirect::signal()", " ", TAU_USER); - _impl.signal_all(); +notify_all() { + TAU_PROFILE("ConditionVarFullDirect::notify()", " ", TAU_USER); + _impl.notify_all(); } diff --git a/panda/src/pipeline/conditionVarFullDirect.h b/panda/src/pipeline/conditionVarFullDirect.h index 6eebadf11b..cc421e2413 100644 --- a/panda/src/pipeline/conditionVarFullDirect.h +++ b/panda/src/pipeline/conditionVarFullDirect.h @@ -46,8 +46,8 @@ PUBLISHED: INLINE void wait(); INLINE void wait(double timeout); - INLINE void signal(); - INLINE void signal_all(); + INLINE void notify(); + INLINE void notify_all(); void output(ostream &out) const; private: diff --git a/panda/src/pipeline/conditionVarFullWin32Impl.I b/panda/src/pipeline/conditionVarFullWin32Impl.I index 07b9d72a68..0a6b748421 100644 --- a/panda/src/pipeline/conditionVarFullWin32Impl.I +++ b/panda/src/pipeline/conditionVarFullWin32Impl.I @@ -54,14 +54,14 @@ wait() { // This avoids the "lost wakeup" bug... LeaveCriticalSection(_external_mutex); - // Wait for either event to become signaled due to signal() being - // called or signal_all() being called. + // Wait for either event to become signaled due to notify() being + // called or notify_all() being called. int result = WaitForMultipleObjects(2, &_event_signal, FALSE, INFINITE); bool nonzero = AtomicAdjust::dec(_waiters_count); bool last_waiter = (result == WAIT_OBJECT_0 + 1 && !nonzero); - // Some thread called signal_all(). + // Some thread called notify_all(). if (last_waiter) { // We're the last waiter to be notified or to stop waiting, so // reset the manual event. @@ -86,14 +86,14 @@ wait(double timeout) { // This avoids the "lost wakeup" bug... LeaveCriticalSection(_external_mutex); - // Wait for either event to become signaled due to signal() being - // called or signal_all() being called. + // Wait for either event to become signaled due to notify() being + // called or notify_all() being called. int result = WaitForMultipleObjects(2, &_event_signal, FALSE, (DWORD)(timeout * 1000.0)); bool nonzero = AtomicAdjust::dec(_waiters_count); bool last_waiter = (result == WAIT_OBJECT_0 + 1 && !nonzero); - // Some thread called signal_all(). + // Some thread called notify_all(). if (last_waiter) { // We're the last waiter to be notified or to stop waiting, so // reset the manual event. @@ -110,7 +110,7 @@ wait(double timeout) { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarFullWin32Impl:: -signal() { +notify() { bool have_waiters = AtomicAdjust::get(_waiters_count) > 0; if (have_waiters) { @@ -124,7 +124,7 @@ signal() { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarFullWin32Impl:: -signal_all() { +notify_all() { bool have_waiters = AtomicAdjust::get(_waiters_count) > 0; if (have_waiters) { diff --git a/panda/src/pipeline/conditionVarFullWin32Impl.h b/panda/src/pipeline/conditionVarFullWin32Impl.h index dc5dcf3dd1..da78cf393f 100644 --- a/panda/src/pipeline/conditionVarFullWin32Impl.h +++ b/panda/src/pipeline/conditionVarFullWin32Impl.h @@ -33,15 +33,15 @@ class MutexWin32Impl; // // We follow the "SetEvent" implementation suggested by // http://www.cs.wustl.edu/~schmidt/win32-cv-1.html . -// This allows us to implement both signal() and -// signal_all(), but it has more overhead than the +// This allows us to implement both notify() and +// notify_all(), but it has more overhead than the // simpler implementation of ConditionVarWin32Impl. // // As described by the above reference, this // implementation suffers from a few weaknesses; in // particular, it does not necessarily wake up all // threads fairly; and it may sometimes incorrectly wake -// up a thread that was not waiting at the time signal() +// up a thread that was not waiting at the time notify() // was called. But we figure it's good enough for our // purposes. //////////////////////////////////////////////////////////////////// @@ -52,8 +52,8 @@ public: INLINE void wait(); INLINE void wait(double timeout); - INLINE void signal(); - INLINE void signal_all(); + INLINE void notify(); + INLINE void notify_all(); private: CRITICAL_SECTION *_external_mutex; diff --git a/panda/src/pipeline/conditionVarPosixImpl.I b/panda/src/pipeline/conditionVarPosixImpl.I index 524d22fc9e..123e71bc34 100644 --- a/panda/src/pipeline/conditionVarPosixImpl.I +++ b/panda/src/pipeline/conditionVarPosixImpl.I @@ -62,8 +62,8 @@ wait() { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarPosixImpl:: -signal() { - TAU_PROFILE("ConditionVarPosixImpl::signal()", " ", TAU_USER); +notify() { + TAU_PROFILE("ConditionVarPosixImpl::notify()", " ", TAU_USER); int result = pthread_cond_signal(&_cvar); nassertv(result == 0); } @@ -74,8 +74,8 @@ signal() { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarPosixImpl:: -signal_all() { - TAU_PROFILE("ConditionVarPosixImpl::signal()", " ", TAU_USER); +notify_all() { + TAU_PROFILE("ConditionVarPosixImpl::notify()", " ", TAU_USER); int result = pthread_cond_broadcast(&_cvar); nassertv(result == 0); } diff --git a/panda/src/pipeline/conditionVarPosixImpl.h b/panda/src/pipeline/conditionVarPosixImpl.h index f4ad5690f8..c3367aa0c0 100644 --- a/panda/src/pipeline/conditionVarPosixImpl.h +++ b/panda/src/pipeline/conditionVarPosixImpl.h @@ -39,8 +39,8 @@ public: INLINE void wait(); void wait(double timeout); - INLINE void signal(); - INLINE void signal_all(); + INLINE void notify(); + INLINE void notify_all(); private: MutexPosixImpl &_mutex; diff --git a/panda/src/pipeline/conditionVarSimpleImpl.I b/panda/src/pipeline/conditionVarSimpleImpl.I index cbdfe0e51b..15e76e4848 100644 --- a/panda/src/pipeline/conditionVarSimpleImpl.I +++ b/panda/src/pipeline/conditionVarSimpleImpl.I @@ -37,7 +37,7 @@ INLINE ConditionVarSimpleImpl:: // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarSimpleImpl:: -signal() { +notify() { if (_flags & F_has_waiters) { do_signal(); } @@ -49,7 +49,7 @@ signal() { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarSimpleImpl:: -signal_all() { +notify_all() { if (_flags & F_has_waiters) { do_signal_all(); } diff --git a/panda/src/pipeline/conditionVarSimpleImpl.cxx b/panda/src/pipeline/conditionVarSimpleImpl.cxx index 5658508dfe..06da3aacd2 100644 --- a/panda/src/pipeline/conditionVarSimpleImpl.cxx +++ b/panda/src/pipeline/conditionVarSimpleImpl.cxx @@ -33,7 +33,7 @@ wait() { manager->enqueue_block(thread, this); manager->next_context(); - _mutex.lock(); + _mutex.acquire(); } //////////////////////////////////////////////////////////////////// @@ -54,7 +54,7 @@ wait(double timeout) { manager->enqueue_ready(thread); manager->next_context(); - _mutex.lock(); + _mutex.acquire(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pipeline/conditionVarSimpleImpl.h b/panda/src/pipeline/conditionVarSimpleImpl.h index d9c0fd4aa6..5ea303708b 100644 --- a/panda/src/pipeline/conditionVarSimpleImpl.h +++ b/panda/src/pipeline/conditionVarSimpleImpl.h @@ -35,8 +35,8 @@ public: void wait(); void wait(double timeout); - INLINE void signal(); - INLINE void signal_all(); + INLINE void notify(); + INLINE void notify_all(); private: void do_signal(); diff --git a/panda/src/pipeline/conditionVarSpinlockImpl.I b/panda/src/pipeline/conditionVarSpinlockImpl.I index 850f9c9bf0..b299be2499 100644 --- a/panda/src/pipeline/conditionVarSpinlockImpl.I +++ b/panda/src/pipeline/conditionVarSpinlockImpl.I @@ -38,7 +38,7 @@ INLINE ConditionVarSpinlockImpl:: // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarSpinlockImpl:: -signal() { +notify() { // This will wake up all waiters on the lock. But that's allowed. AtomicAdjust::inc(_event); } @@ -49,6 +49,6 @@ signal() { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarSpinlockImpl:: -signal_all() { +notify_all() { AtomicAdjust::inc(_event); } diff --git a/panda/src/pipeline/conditionVarSpinlockImpl.cxx b/panda/src/pipeline/conditionVarSpinlockImpl.cxx index e6c7a09422..ddfbb78b0a 100644 --- a/panda/src/pipeline/conditionVarSpinlockImpl.cxx +++ b/panda/src/pipeline/conditionVarSpinlockImpl.cxx @@ -31,7 +31,7 @@ wait() { while (AtomicAdjust::get(_event) == current) { } - _mutex.lock(); + _mutex.acquire(); } #endif // MUTEX_SPINLOCK diff --git a/panda/src/pipeline/conditionVarSpinlockImpl.h b/panda/src/pipeline/conditionVarSpinlockImpl.h index f1817d4014..1c71d9fa94 100644 --- a/panda/src/pipeline/conditionVarSpinlockImpl.h +++ b/panda/src/pipeline/conditionVarSpinlockImpl.h @@ -41,8 +41,8 @@ public: INLINE ~ConditionVarSpinlockImpl(); void wait(); - INLINE void signal(); - INLINE void signal_all(); + INLINE void notify(); + INLINE void notify_all(); private: MutexSpinlockImpl &_mutex; diff --git a/panda/src/pipeline/conditionVarWin32Impl.I b/panda/src/pipeline/conditionVarWin32Impl.I index 16e9a88736..824d607230 100644 --- a/panda/src/pipeline/conditionVarWin32Impl.I +++ b/panda/src/pipeline/conditionVarWin32Impl.I @@ -72,6 +72,6 @@ wait(double timeout) { // Description: //////////////////////////////////////////////////////////////////// INLINE void ConditionVarWin32Impl:: -signal() { +notify() { SetEvent(_event_signal); } diff --git a/panda/src/pipeline/conditionVarWin32Impl.h b/panda/src/pipeline/conditionVarWin32Impl.h index 5e1110231f..71d150ab90 100644 --- a/panda/src/pipeline/conditionVarWin32Impl.h +++ b/panda/src/pipeline/conditionVarWin32Impl.h @@ -33,9 +33,9 @@ class MutexWin32Impl; // The Windows native synchronization primitives don't // actually implement a full POSIX-style condition // variable, but the Event primitive does a fair job if -// we disallow signal_all() (POSIX broadcast). See +// we disallow notify_all() (POSIX broadcast). See // ConditionVarFullWin32Impl for a full implementation -// that includes signal_all(). This class is much +// that includes notify_all(). This class is much // simpler than that full implementation, so we can // avoid the overhead required to support broadcast. //////////////////////////////////////////////////////////////////// @@ -46,7 +46,7 @@ public: INLINE void wait(); INLINE void wait(double timeout); - INLINE void signal(); + INLINE void notify(); private: CRITICAL_SECTION *_external_mutex; diff --git a/panda/src/pipeline/cyclerHolder.I b/panda/src/pipeline/cyclerHolder.I index 2f084a6d0f..78191952ac 100644 --- a/panda/src/pipeline/cyclerHolder.I +++ b/panda/src/pipeline/cyclerHolder.I @@ -22,7 +22,7 @@ INLINE CyclerHolder:: CyclerHolder(PipelineCyclerBase &cycler) { #ifdef DO_PIPELINING _cycler = &cycler; - _cycler->lock(); + _cycler->acquire(); #endif } diff --git a/panda/src/pipeline/cyclerHolder.h b/panda/src/pipeline/cyclerHolder.h index c53e6b7b28..1d25354cab 100644 --- a/panda/src/pipeline/cyclerHolder.h +++ b/panda/src/pipeline/cyclerHolder.h @@ -21,7 +21,7 @@ //////////////////////////////////////////////////////////////////// // Class : CyclerHolder // Description : A lightweight C++ object whose constructor calls -// lock() and whose destructor calls release() on a +// acquire() and whose destructor calls release() on a // PipelineCyclerBase object. This is similar to a // MutexHolder. //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pipeline/lightMutexDirect.I b/panda/src/pipeline/lightMutexDirect.I index a4d7fdfb8e..3222c03ef5 100644 --- a/panda/src/pipeline/lightMutexDirect.I +++ b/panda/src/pipeline/lightMutexDirect.I @@ -52,7 +52,7 @@ operator = (const LightMutexDirect ©) { } //////////////////////////////////////////////////////////////////// -// Function: LightMutexDirect::lock +// Function: LightMutexDirect::acquire // Access: Published // Description: Grabs the lightMutex if it is available. If it is not // available, blocks until it becomes available, then @@ -67,9 +67,9 @@ operator = (const LightMutexDirect ©) { // Also see LightMutexHolder. //////////////////////////////////////////////////////////////////// INLINE void LightMutexDirect:: -lock() const { - TAU_PROFILE("void LightMutexDirect::lock()", " ", TAU_USER); - ((LightMutexDirect *)this)->_impl.lock(); +acquire() const { + TAU_PROFILE("void LightMutexDirect::acquire()", " ", TAU_USER); + ((LightMutexDirect *)this)->_impl.acquire(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pipeline/lightMutexDirect.h b/panda/src/pipeline/lightMutexDirect.h index 00f5d7e201..8938f44b64 100644 --- a/panda/src/pipeline/lightMutexDirect.h +++ b/panda/src/pipeline/lightMutexDirect.h @@ -37,7 +37,7 @@ private: INLINE void operator = (const LightMutexDirect ©); PUBLISHED: - BLOCKING INLINE void lock() const; + BLOCKING INLINE void acquire() const; INLINE void release() const; INLINE bool debug_is_locked() const; diff --git a/panda/src/pipeline/lightMutexHolder.I b/panda/src/pipeline/lightMutexHolder.I index 885b61e74b..096f917760 100644 --- a/panda/src/pipeline/lightMutexHolder.I +++ b/panda/src/pipeline/lightMutexHolder.I @@ -22,7 +22,7 @@ INLINE LightMutexHolder:: LightMutexHolder(const LightMutex &mutex) { #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) _mutex = &mutex; - _mutex->lock(); + _mutex->acquire(); #endif } @@ -44,7 +44,7 @@ LightMutexHolder(LightMutex *&mutex) { mutex = new LightMutex; } _mutex = mutex; - _mutex->lock(); + _mutex->acquire(); #endif } diff --git a/panda/src/pipeline/lightReMutexDirect.I b/panda/src/pipeline/lightReMutexDirect.I index 0d3d9c504e..b601e7dfcd 100644 --- a/panda/src/pipeline/lightReMutexDirect.I +++ b/panda/src/pipeline/lightReMutexDirect.I @@ -64,7 +64,7 @@ operator = (const LightReMutexDirect ©) { } //////////////////////////////////////////////////////////////////// -// Function: LightReMutexDirect::lock +// Function: LightReMutexDirect::acquire // Access: Published // Description: Grabs the lightReMutex if it is available. If it is not // available, blocks until it becomes available, then @@ -79,23 +79,23 @@ operator = (const LightReMutexDirect ©) { // Also see LightReMutexHolder. //////////////////////////////////////////////////////////////////// INLINE void LightReMutexDirect:: -lock() const { - TAU_PROFILE("void LightReMutexDirect::lock()", " ", TAU_USER); - ((LightReMutexDirect *)this)->_impl.lock(); +acquire() const { + TAU_PROFILE("void LightReMutexDirect::acquire()", " ", TAU_USER); + ((LightReMutexDirect *)this)->_impl.acquire(); } //////////////////////////////////////////////////////////////////// -// Function: LightReMutexDirect::lock +// Function: LightReMutexDirect::acquire // Access: Published -// Description: This variant on lock() accepts the current thread as +// Description: This variant on acquire() accepts the current thread as // a parameter, if it is already known, as an // optimization. //////////////////////////////////////////////////////////////////// INLINE void LightReMutexDirect:: -lock(Thread *current_thread) const { - TAU_PROFILE("void LightReMutexDirect::lock(Thread *)", " ", TAU_USER); +acquire(Thread *current_thread) const { + TAU_PROFILE("void LightReMutexDirect::acquire(Thread *)", " ", TAU_USER); #ifdef HAVE_REMUTEXIMPL - ((LightReMutexDirect *)this)->_impl.lock(); + ((LightReMutexDirect *)this)->_impl.acquire(); #else ((LightReMutexDirect *)this)->_impl.do_lock(current_thread); #endif // HAVE_REMUTEXIMPL @@ -110,7 +110,7 @@ lock(Thread *current_thread) const { // time to release the lock. // // This method really performs the same function as -// lock(), but it offers a potential (slight) +// acquire(), but it offers a potential (slight) // performance benefit when the calling thread knows // that it already holds the lock. It is an error to // call this when the calling thread does not hold the @@ -120,7 +120,7 @@ INLINE void LightReMutexDirect:: elevate_lock() const { TAU_PROFILE("void LightReMutexDirect::elevate_lock()", " ", TAU_USER); #ifdef HAVE_REMUTEXIMPL - ((LightReMutexDirect *)this)->_impl.lock(); + ((LightReMutexDirect *)this)->_impl.acquire(); #else ((LightReMutexDirect *)this)->_impl.do_elevate_lock(); #endif // HAVE_REMUTEXIMPL diff --git a/panda/src/pipeline/lightReMutexDirect.h b/panda/src/pipeline/lightReMutexDirect.h index d022e8ebe4..00dafe19bf 100644 --- a/panda/src/pipeline/lightReMutexDirect.h +++ b/panda/src/pipeline/lightReMutexDirect.h @@ -36,8 +36,8 @@ private: INLINE void operator = (const LightReMutexDirect ©); PUBLISHED: - BLOCKING INLINE void lock() const; - BLOCKING INLINE void lock(Thread *current_thread) const; + BLOCKING INLINE void acquire() const; + BLOCKING INLINE void acquire(Thread *current_thread) const; INLINE void elevate_lock() const; INLINE void release() const; diff --git a/panda/src/pipeline/lightReMutexHolder.I b/panda/src/pipeline/lightReMutexHolder.I index 3cf1419fc2..d1106c4628 100644 --- a/panda/src/pipeline/lightReMutexHolder.I +++ b/panda/src/pipeline/lightReMutexHolder.I @@ -22,7 +22,7 @@ INLINE LightReMutexHolder:: LightReMutexHolder(const LightReMutex &mutex) { #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) _mutex = &mutex; - _mutex->lock(); + _mutex->acquire(); #endif } @@ -37,7 +37,7 @@ INLINE LightReMutexHolder:: LightReMutexHolder(const LightReMutex &mutex, Thread *current_thread) { #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) _mutex = &mutex; - _mutex->lock(current_thread); + _mutex->acquire(current_thread); #endif } @@ -59,7 +59,7 @@ LightReMutexHolder(LightReMutex *&mutex) { mutex = new LightReMutex; } _mutex = mutex; - _mutex->lock(); + _mutex->acquire(); #endif } diff --git a/panda/src/pipeline/mutexDebug.I b/panda/src/pipeline/mutexDebug.I index 0b1826a472..69c8c2b4d8 100755 --- a/panda/src/pipeline/mutexDebug.I +++ b/panda/src/pipeline/mutexDebug.I @@ -34,7 +34,7 @@ operator = (const MutexDebug ©) { } //////////////////////////////////////////////////////////////////// -// Function: MutexDebug::lock +// Function: MutexDebug::acquire // Access: Published // Description: Grabs the mutex if it is available. If it is not // available, blocks until it becomes available, then @@ -48,29 +48,31 @@ operator = (const MutexDebug ©) { // // Also see MutexHolder. //////////////////////////////////////////////////////////////////// -INLINE void MutexDebug:: -lock() const { - TAU_PROFILE("void MutexDebug::lock()", " ", TAU_USER); - _global_lock->lock(); - ((MutexDebug *)this)->do_lock(); - _global_lock->release(); +INLINE bool MutexDebug:: +acquire(Thread *current_thread) const { + TAU_PROFILE("void MutexDebug::acquire(Thread *)", " ", TAU_USER); + nassertv(current_thread == Thread::get_current_thread()); + _global_lock->acquire(); + ((MutexDebug *)this)->do_acquire(); + _global_lock->release(current_thread); + return true; } //////////////////////////////////////////////////////////////////// -// Function: MutexDebug::lock +// Function: MutexDebug::try_acquire // Access: Published -// Description: This variant on lock() accepts the current thread as -// a parameter, if it is already known, as an -// optimization. +// Description: Returns immediately, with a true value indicating the +// mutex has been acquired, and false indicating it has +// not. //////////////////////////////////////////////////////////////////// -INLINE void MutexDebug:: -lock(Thread *current_thread) const { - TAU_PROFILE("void MutexDebug::lock(Thread *)", " ", TAU_USER); +INLINE bool MutexDebug:: +try_acquire(Thread *current_thread) const { + TAU_PROFILE("void MutexDebug::acquire(Thread *)", " ", TAU_USER); nassertv(current_thread == Thread::get_current_thread()); - // You may only pass a Thread parameter to a ReMutex--that is, to a - // mutex whose _allow_recursion flag is true. - nassertv(_allow_recursion); - lock(); + _global_lock->acquire(); + bool acquired = ((MutexDebug *)this)->do_try_acquire(current_thread); + _global_lock->release(); + return acquired; } //////////////////////////////////////////////////////////////////// @@ -82,7 +84,7 @@ lock(Thread *current_thread) const { // time to release the lock. // // This method really performs the same function as -// lock(), but it offers a potential (slight) +// acquire(), but it offers a potential (slight) // performance benefit when the calling thread knows // that it already holds the lock. It is an error to // call this when the calling thread does not hold the @@ -98,7 +100,7 @@ elevate_lock() const { // Also, it's an error to call this if the lock is not already held. nassertv(debug_is_locked()); - lock(); + acquire(); } //////////////////////////////////////////////////////////////////// @@ -114,7 +116,7 @@ elevate_lock() const { INLINE void MutexDebug:: release() const { TAU_PROFILE("void MutexDebug::release()", " ", TAU_USER); - _global_lock->lock(); + _global_lock->acquire(); ((MutexDebug *)this)->do_release(); _global_lock->release(); } @@ -132,7 +134,7 @@ release() const { INLINE bool MutexDebug:: debug_is_locked() const { TAU_PROFILE("bool MutexDebug::debug_is_locked()", " ", TAU_USER); - _global_lock->lock(); + _global_lock->acquire(); bool is_locked = do_debug_is_locked(); _global_lock->release(); return is_locked; diff --git a/panda/src/pipeline/mutexDebug.cxx b/panda/src/pipeline/mutexDebug.cxx index f9d0509ac2..6e29e8cc5e 100755 --- a/panda/src/pipeline/mutexDebug.cxx +++ b/panda/src/pipeline/mutexDebug.cxx @@ -85,13 +85,13 @@ output(ostream &out) const { } //////////////////////////////////////////////////////////////////// -// Function: MutexDebug::do_lock +// Function: MutexDebug::do_acquire // Access: Private -// Description: The private implementation of lock() assumes that +// Description: The private implementation of acquire() assumes that // _lock_impl is held. //////////////////////////////////////////////////////////////////// void MutexDebug:: -do_lock() { +do_acquire(Thread *current_thread) { // If this assertion is triggered, you tried to lock a // recently-destructed mutex. nassertd(_lock_count != -100) { @@ -107,21 +107,19 @@ do_lock() { return; } - Thread *this_thread = Thread::get_current_thread(); - if (_locking_thread == (Thread *)NULL) { // The mutex is not already locked by anyone. Lock it. - _locking_thread = this_thread; + _locking_thread = current_thread; ++_lock_count; nassertv(_lock_count == 1); - } else if (_locking_thread == this_thread) { + } else if (_locking_thread == current_thread) { // The mutex is already locked by this thread. Increment the lock // count. nassertv(_lock_count > 0); if (!_allow_recursion) { ostringstream ostr; - ostr << *this_thread << " attempted to double-lock non-reentrant " + ostr << *current_thread << " attempted to double-lock non-reentrant " << *this; nassert_raise(ostr.str()); } @@ -132,15 +130,15 @@ do_lock() { if (_lightweight) { // In this case, it's not a real mutex. Just watch it go by. - MissedThreads::iterator mi = _missed_threads.insert(MissedThreads::value_type(this_thread, 0)).first; + MissedThreads::iterator mi = _missed_threads.insert(MissedThreads::value_type(current_thread, 0)).first; if ((*mi).second == 0) { thread_cat.info() - << *this_thread << " not stopped by " << *this << " (held by " + << *current_thread << " not stopped by " << *this << " (held by " << *_locking_thread << ")\n"; } else { if (!_allow_recursion) { ostringstream ostr; - ostr << *this_thread << " attempted to double-lock non-reentrant " + ostr << *current_thread << " attempted to double-lock non-reentrant " << *this; nassert_raise(ostr.str()); } @@ -153,9 +151,9 @@ do_lock() { // Check for deadlock. MutexDebug *next_mutex = this; while (next_mutex != NULL) { - if (next_mutex->_locking_thread == this_thread) { + if (next_mutex->_locking_thread == current_thread) { // Whoops, the thread is blocked on me! Deadlock! - report_deadlock(this_thread); + report_deadlock(current_thread); nassert_raise("Deadlock"); return; } @@ -173,13 +171,13 @@ do_lock() { } // OK, no deadlock detected. Carry on. - this_thread->_blocked_on_mutex = this; + current_thread->_blocked_on_mutex = this; // Go to sleep on the condition variable until it's unlocked. if (thread_cat->is_debug()) { thread_cat.debug() - << *this_thread << " blocking on " << *this << " (held by " + << *current_thread << " blocking on " << *this << " (held by " << *_locking_thread << ")\n"; } @@ -189,22 +187,93 @@ do_lock() { if (thread_cat.is_debug()) { thread_cat.debug() - << *this_thread << " awake on " << *this << "\n"; + << *current_thread << " awake on " << *this << "\n"; } - this_thread->_blocked_on_mutex = NULL; + current_thread->_blocked_on_mutex = NULL; - _locking_thread = this_thread; + _locking_thread = current_thread; ++_lock_count; nassertv(_lock_count == 1); } } } +//////////////////////////////////////////////////////////////////// +// Function: MutexDebug::do_try_acquire +// Access: Private +// Description: The private implementation of acquire(false) assumes +// that _lock_impl is held. +//////////////////////////////////////////////////////////////////// +bool MutexDebug:: +do_try_acquire(Thread *current_thread) { + // If this assertion is triggered, you tried to lock a + // recently-destructed mutex. + nassertd(_lock_count != -100) { + pipeline_cat.error() + << "Destructed mutex: " << (void *)this << "\n"; + if (name_deleted_mutexes && _deleted_name != NULL) { + pipeline_cat.error() + << _deleted_name << "\n"; + } else { + pipeline_cat.error() + << "Configure name-deleted-mutexes 1 to see the mutex name.\n"; + } + return; + } + + bool acquired = true; + if (_locking_thread == (Thread *)NULL) { + // The mutex is not already locked by anyone. Lock it. + _locking_thread = current_thread; + ++_lock_count; + nassertv(_lock_count == 1); + + } else if (_locking_thread == current_thread) { + // The mutex is already locked by this thread. Increment the lock + // count. + nassertv(_lock_count > 0); + if (!_allow_recursion) { + ostringstream ostr; + ostr << *current_thread << " attempted to double-lock non-reentrant " + << *this; + nassert_raise(ostr.str()); + } + ++_lock_count; + + } else { + // The mutex is locked by some other thread. Return false. + + if (_lightweight) { + // In this case, it's not a real mutex. Just watch it go by. + MissedThreads::iterator mi = _missed_threads.insert(MissedThreads::value_type(current_thread, 0)).first; + if ((*mi).second == 0) { + thread_cat.info() + << *current_thread << " not stopped by " << *this << " (held by " + << *_locking_thread << ")\n"; + } else { + if (!_allow_recursion) { + ostringstream ostr; + ostr << *current_thread << " attempted to double-lock non-reentrant " + << *this; + nassert_raise(ostr.str()); + } + } + ++((*mi).second); + + } else { + // This is the real case. + acquired = false; + } + } + + return acquired; +} + //////////////////////////////////////////////////////////////////// // Function: MutexDebug::do_release // Access: Private -// Description: The private implementation of lock() assumes that +// Description: The private implementation of acquire() assumes that // _lock_impl is held. //////////////////////////////////////////////////////////////////// void MutexDebug:: @@ -224,16 +293,16 @@ do_release() { return; } - Thread *this_thread = Thread::get_current_thread(); + Thread *current_thread = Thread::get_current_thread(); - if (_locking_thread != this_thread) { + if (_locking_thread != current_thread) { // We're not holding this mutex. if (_lightweight) { // Not a real mutex. This just means we blew past a mutex // without locking it, above. - MissedThreads::iterator mi = _missed_threads.find(this_thread); + MissedThreads::iterator mi = _missed_threads.find(current_thread); nassertv(mi != _missed_threads.end()); nassertv((*mi).second > 0); --((*mi).second); @@ -245,7 +314,7 @@ do_release() { } else { // In the real-mutex case, this is an error condition. ostringstream ostr; - ostr << *this_thread << " attempted to release " + ostr << *current_thread << " attempted to release " << *this << " which it does not own"; nassert_raise(ostr.str()); } @@ -269,7 +338,7 @@ do_release() { nassertv(_lock_count > 0); } } else { - _cvar_impl.signal(); + _cvar_impl.notify(); } } } @@ -282,13 +351,13 @@ do_release() { //////////////////////////////////////////////////////////////////// bool MutexDebug:: do_debug_is_locked() const { - Thread *this_thread = Thread::get_current_thread(); - if (_locking_thread == this_thread) { + Thread *current_thread = Thread::get_current_thread(); + if (_locking_thread == current_thread) { return true; } if (_lightweight) { - MissedThreads::const_iterator mi = _missed_threads.find(this_thread); + MissedThreads::const_iterator mi = _missed_threads.find(current_thread); if (mi != _missed_threads.end()) { nassertr((*mi).second > 0, false); return true; @@ -305,7 +374,7 @@ do_debug_is_locked() const { // should be already held. //////////////////////////////////////////////////////////////////// void MutexDebug:: -report_deadlock(Thread *this_thread) { +report_deadlock(Thread *current_thread) { thread_cat->error() << "\n\n" << "****************************************************************\n" @@ -314,7 +383,7 @@ report_deadlock(Thread *this_thread) { << "\n"; thread_cat.error() - << *this_thread << " attempted to lock " << *this + << *current_thread << " attempted to lock " << *this << " which is held by " << *_locking_thread << "\n"; MutexDebug *next_mutex = this; diff --git a/panda/src/pipeline/mutexDebug.h b/panda/src/pipeline/mutexDebug.h index d97af57237..47cb039878 100644 --- a/panda/src/pipeline/mutexDebug.h +++ b/panda/src/pipeline/mutexDebug.h @@ -38,8 +38,8 @@ private: INLINE void operator = (const MutexDebug ©); PUBLISHED: - BLOCKING INLINE void lock() const; - BLOCKING INLINE void lock(Thread *current_thread) const; + BLOCKING INLINE void acquire(Thread *current_thread = Thread::get_current_thread()) const; + BLOCKING INLINE bool try_acquire(Thread *current_thread = Thread::get_current_thread()) const; INLINE void elevate_lock() const; INLINE void release() const; INLINE bool debug_is_locked() const; @@ -49,11 +49,12 @@ PUBLISHED: typedef void VoidFunc(); private: - void do_lock(); + void do_acquire(Thread *current_thread); + bool do_try_acquire(Thread *current_thread); void do_release(); bool do_debug_is_locked() const; - void report_deadlock(Thread *this_thread); + void report_deadlock(Thread *current_thread); private: INLINE static MutexTrueImpl *get_global_lock(); diff --git a/panda/src/pipeline/mutexDirect.I b/panda/src/pipeline/mutexDirect.I index 90767f906e..16c93aa394 100755 --- a/panda/src/pipeline/mutexDirect.I +++ b/panda/src/pipeline/mutexDirect.I @@ -52,7 +52,7 @@ operator = (const MutexDirect ©) { } //////////////////////////////////////////////////////////////////// -// Function: MutexDirect::lock +// Function: MutexDirect::acquire // Access: Published // Description: Grabs the mutex if it is available. If it is not // available, blocks until it becomes available, then @@ -67,9 +67,22 @@ operator = (const MutexDirect ©) { // Also see MutexHolder. //////////////////////////////////////////////////////////////////// INLINE void MutexDirect:: -lock() const { - TAU_PROFILE("void MutexDirect::lock()", " ", TAU_USER); - ((MutexDirect *)this)->_impl.lock(); +acquire() const { + TAU_PROFILE("void MutexDirect::acquire()", " ", TAU_USER); + ((MutexDirect *)this)->_impl.acquire(); +} + +//////////////////////////////////////////////////////////////////// +// Function: MutexDirect::try_acquire +// Access: Published +// Description: Returns immediately, with a true value indicating the +// mutex has been acquired, and false indicating it has +// not. +//////////////////////////////////////////////////////////////////// +INLINE bool MutexDirect:: +try_acquire() const { + TAU_PROFILE("void MutexDirect::acquire(bool)", " ", TAU_USER); + return ((MutexDirect *)this)->_impl.try_acquire(); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/pipeline/mutexDirect.h b/panda/src/pipeline/mutexDirect.h index 203081680f..4954cb3588 100644 --- a/panda/src/pipeline/mutexDirect.h +++ b/panda/src/pipeline/mutexDirect.h @@ -38,7 +38,8 @@ private: INLINE void operator = (const MutexDirect ©); PUBLISHED: - BLOCKING INLINE void lock() const; + BLOCKING INLINE void acquire() const; + BLOCKING INLINE bool try_acquire() const; INLINE void release() const; INLINE bool debug_is_locked() const; diff --git a/panda/src/pipeline/mutexHolder.I b/panda/src/pipeline/mutexHolder.I index f61298e65c..e8ecf59e26 100644 --- a/panda/src/pipeline/mutexHolder.I +++ b/panda/src/pipeline/mutexHolder.I @@ -22,7 +22,7 @@ INLINE MutexHolder:: MutexHolder(const Mutex &mutex) { #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) _mutex = &mutex; - _mutex->lock(); + _mutex->acquire(); #endif } @@ -44,7 +44,7 @@ MutexHolder(Mutex *&mutex) { mutex = new Mutex; } _mutex = mutex; - _mutex->lock(); + _mutex->acquire(); #endif } diff --git a/panda/src/pipeline/mutexHolder.h b/panda/src/pipeline/mutexHolder.h index 90131399ba..5df4b4c38a 100644 --- a/panda/src/pipeline/mutexHolder.h +++ b/panda/src/pipeline/mutexHolder.h @@ -21,7 +21,7 @@ //////////////////////////////////////////////////////////////////// // Class : MutexHolder // Description : A lightweight C++ object whose constructor calls -// lock() and whose destructor calls release() on a +// acquire() and whose destructor calls release() on a // mutex. It is a C++ convenience wrapper to call // release() automatically when a block exits (for // instance, on return). diff --git a/panda/src/pipeline/mutexSimpleImpl.I b/panda/src/pipeline/mutexSimpleImpl.I index 8ec83f7a0d..30a517876b 100644 --- a/panda/src/pipeline/mutexSimpleImpl.I +++ b/panda/src/pipeline/mutexSimpleImpl.I @@ -32,24 +32,24 @@ INLINE MutexSimpleImpl:: } //////////////////////////////////////////////////////////////////// -// Function: MutexSimpleImpl::lock +// Function: MutexSimpleImpl::acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE void MutexSimpleImpl:: -lock() { - if (!try_lock()) { +acquire() { + if (!try_acquire()) { do_lock(); } } //////////////////////////////////////////////////////////////////// -// Function: MutexSimpleImpl::try_lock +// Function: MutexSimpleImpl::try_acquire // Access: Public // Description: //////////////////////////////////////////////////////////////////// INLINE bool MutexSimpleImpl:: -try_lock() { +try_acquire() { if ((_flags & F_lock_count) != 0) { return false; } diff --git a/panda/src/pipeline/mutexSimpleImpl.h b/panda/src/pipeline/mutexSimpleImpl.h index 8646446e40..7d3ec059b3 100644 --- a/panda/src/pipeline/mutexSimpleImpl.h +++ b/panda/src/pipeline/mutexSimpleImpl.h @@ -46,8 +46,8 @@ public: INLINE MutexSimpleImpl(); INLINE ~MutexSimpleImpl(); - INLINE void lock(); - INLINE bool try_lock(); + INLINE void acquire(); + INLINE bool try_acquire(); INLINE void release(); private: diff --git a/panda/src/pipeline/pipeline.cxx b/panda/src/pipeline/pipeline.cxx index 921c7257a2..ebe81e78b3 100644 --- a/panda/src/pipeline/pipeline.cxx +++ b/panda/src/pipeline/pipeline.cxx @@ -176,7 +176,7 @@ set_num_stages(int num_stages) { PipelineCyclerLinks *links; for (links = this->_next; links != this; links = links->_next) { PipelineCyclerTrueImpl *cycler = (PipelineCyclerTrueImpl *)links; - cycler->_lock.lock(); + cycler->_lock.acquire(); } _num_stages = num_stages; diff --git a/panda/src/pipeline/pipelineCyclerDummyImpl.I b/panda/src/pipeline/pipelineCyclerDummyImpl.I index 145ac4527f..fc18b73271 100644 --- a/panda/src/pipeline/pipelineCyclerDummyImpl.I +++ b/panda/src/pipeline/pipelineCyclerDummyImpl.I @@ -69,15 +69,15 @@ INLINE PipelineCyclerDummyImpl:: } //////////////////////////////////////////////////////////////////// -// Function: PipelineCyclerDummyImpl::lock +// Function: PipelineCyclerDummyImpl::acquire // Access: Public // Description: Grabs an overall lock on the cycler. Release it with // a call to release(). This lock should be held while // walking the list of stages. //////////////////////////////////////////////////////////////////// INLINE void PipelineCyclerDummyImpl:: -lock(Thread *) { - TAU_PROFILE("void PipelineCyclerDummyImpl::lock(Thread *)", " ", TAU_USER); +acquire(Thread *) { + TAU_PROFILE("void PipelineCyclerDummyImpl::acquire(Thread *)", " ", TAU_USER); nassertv(!_locked); _locked = true; } @@ -86,7 +86,7 @@ lock(Thread *) { // Function: PipelineCyclerDummyImpl::release // Access: Public // Description: Release the overall lock on the cycler that was -// grabbed via lock(). +// grabbed via acquire(). //////////////////////////////////////////////////////////////////// INLINE void PipelineCyclerDummyImpl:: release() { diff --git a/panda/src/pipeline/pipelineCyclerDummyImpl.h b/panda/src/pipeline/pipelineCyclerDummyImpl.h index 5be8709c61..78a56c514e 100644 --- a/panda/src/pipeline/pipelineCyclerDummyImpl.h +++ b/panda/src/pipeline/pipelineCyclerDummyImpl.h @@ -48,7 +48,7 @@ public: INLINE void operator = (const PipelineCyclerDummyImpl ©); INLINE ~PipelineCyclerDummyImpl(); - INLINE void lock(Thread *current_thread = NULL); + INLINE void acquire(Thread *current_thread = NULL); INLINE void release(); INLINE const CycleData *read_unlocked(Thread *current_thread) const; diff --git a/panda/src/pipeline/pipelineCyclerTrivialImpl.I b/panda/src/pipeline/pipelineCyclerTrivialImpl.I index 2268662953..e069755aa7 100644 --- a/panda/src/pipeline/pipelineCyclerTrivialImpl.I +++ b/panda/src/pipeline/pipelineCyclerTrivialImpl.I @@ -74,21 +74,21 @@ INLINE PipelineCyclerTrivialImpl:: } //////////////////////////////////////////////////////////////////// -// Function: PipelineCyclerTrivialImpl::lock +// Function: PipelineCyclerTrivialImpl::acquire // Access: Public // Description: Grabs an overall lock on the cycler. Release it with // a call to release(). This lock should be held while // walking the list of stages. //////////////////////////////////////////////////////////////////// INLINE void PipelineCyclerTrivialImpl:: -lock(Thread *) { +acquire(Thread *) { } //////////////////////////////////////////////////////////////////// // Function: PipelineCyclerTrivialImpl::release // Access: Public // Description: Release the overall lock on the cycler that was -// grabbed via lock(). +// grabbed via acquire(). //////////////////////////////////////////////////////////////////// INLINE void PipelineCyclerTrivialImpl:: release() { diff --git a/panda/src/pipeline/pipelineCyclerTrivialImpl.h b/panda/src/pipeline/pipelineCyclerTrivialImpl.h index 199830b2fb..52efb7d7e6 100644 --- a/panda/src/pipeline/pipelineCyclerTrivialImpl.h +++ b/panda/src/pipeline/pipelineCyclerTrivialImpl.h @@ -53,7 +53,7 @@ private: public: INLINE ~PipelineCyclerTrivialImpl(); - INLINE void lock(Thread *current_thread = NULL); + INLINE void acquire(Thread *current_thread = NULL); INLINE void release(); INLINE const CycleData *read_unlocked(Thread *current_thread) const; diff --git a/panda/src/pipeline/pipelineCyclerTrueImpl.I b/panda/src/pipeline/pipelineCyclerTrueImpl.I index 7797ce02b5..5e69cfd81a 100644 --- a/panda/src/pipeline/pipelineCyclerTrueImpl.I +++ b/panda/src/pipeline/pipelineCyclerTrueImpl.I @@ -14,36 +14,36 @@ //////////////////////////////////////////////////////////////////// -// Function: PipelineCyclerTrueImpl::lock +// Function: PipelineCyclerTrueImpl::acquire // Access: Public // Description: Grabs an overall lock on the cycler. Release it with // a call to release(). This lock should be held while // walking the list of stages. //////////////////////////////////////////////////////////////////// INLINE void PipelineCyclerTrueImpl:: -lock() { - TAU_PROFILE("void PipelineCyclerTrueImpl::lock()", " ", TAU_USER); - _lock.lock(); +acquire() { + TAU_PROFILE("void PipelineCyclerTrueImpl::acquire()", " ", TAU_USER); + _lock.acquire(); } //////////////////////////////////////////////////////////////////// -// Function: PipelineCyclerTrueImpl::lock +// Function: PipelineCyclerTrueImpl::acquire // Access: Public // Description: Grabs an overall lock on the cycler. Release it with // a call to release(). This lock should be held while // walking the list of stages. //////////////////////////////////////////////////////////////////// INLINE void PipelineCyclerTrueImpl:: -lock(Thread *current_thread) { - TAU_PROFILE("void PipelineCyclerTrueImpl::lock(Thread *)", " ", TAU_USER); - _lock.lock(current_thread); +acquire(Thread *current_thread) { + TAU_PROFILE("void PipelineCyclerTrueImpl::acquire(Thread *)", " ", TAU_USER); + _lock.acquire(current_thread); } //////////////////////////////////////////////////////////////////// // Function: PipelineCyclerTrueImpl::release // Access: Public // Description: Release the overall lock on the cycler that was -// grabbed via lock(). +// grabbed via acquire(). //////////////////////////////////////////////////////////////////// INLINE void PipelineCyclerTrueImpl:: release() { @@ -93,7 +93,7 @@ read(Thread *current_thread) const { #ifdef _DEBUG nassertr(pipeline_stage >= 0 && pipeline_stage < _num_stages, NULL); #endif - _lock.lock(current_thread); + _lock.acquire(current_thread); return _data[pipeline_stage]; } @@ -312,7 +312,7 @@ read_stage(int pipeline_stage, Thread *current_thread) const { #ifdef _DEBUG nassertr(pipeline_stage >= 0 && pipeline_stage < _num_stages, NULL); #endif - _lock.lock(current_thread); + _lock.acquire(current_thread); return _data[pipeline_stage]; } diff --git a/panda/src/pipeline/pipelineCyclerTrueImpl.cxx b/panda/src/pipeline/pipelineCyclerTrueImpl.cxx index 5c73900a98..3d16ca8207 100644 --- a/panda/src/pipeline/pipelineCyclerTrueImpl.cxx +++ b/panda/src/pipeline/pipelineCyclerTrueImpl.cxx @@ -137,7 +137,7 @@ PipelineCyclerTrueImpl:: //////////////////////////////////////////////////////////////////// CycleData *PipelineCyclerTrueImpl:: write_stage(int pipeline_stage, Thread *current_thread) { - _lock.lock(current_thread); + _lock.acquire(current_thread); #ifndef NDEBUG nassertd(pipeline_stage >= 0 && pipeline_stage < _num_stages) { @@ -175,7 +175,7 @@ write_stage(int pipeline_stage, Thread *current_thread) { //////////////////////////////////////////////////////////////////// CycleData *PipelineCyclerTrueImpl:: write_stage_upstream(int pipeline_stage, bool force_to_0, Thread *current_thread) { - _lock.lock(current_thread); + _lock.acquire(current_thread); #ifndef NDEBUG nassertd(pipeline_stage >= 0 && pipeline_stage < _num_stages) { diff --git a/panda/src/pipeline/pipelineCyclerTrueImpl.h b/panda/src/pipeline/pipelineCyclerTrueImpl.h index 387311d187..9227e553bb 100644 --- a/panda/src/pipeline/pipelineCyclerTrueImpl.h +++ b/panda/src/pipeline/pipelineCyclerTrueImpl.h @@ -54,8 +54,8 @@ public: void operator = (const PipelineCyclerTrueImpl ©); ~PipelineCyclerTrueImpl(); - INLINE void lock(); - INLINE void lock(Thread *current_thread); + INLINE void acquire(); + INLINE void acquire(Thread *current_thread); INLINE void release(); INLINE const CycleData *read_unlocked(Thread *current_thread) const; diff --git a/panda/src/pipeline/pipeline_composite2.cxx b/panda/src/pipeline/pipeline_composite2.cxx index 3b2b99bd07..4197627925 100644 --- a/panda/src/pipeline/pipeline_composite2.cxx +++ b/panda/src/pipeline/pipeline_composite2.cxx @@ -13,6 +13,7 @@ #include "reMutex.cxx" #include "reMutexDirect.cxx" #include "reMutexHolder.cxx" +#include "semaphore.cxx" #include "thread.cxx" #include "threadDummyImpl.cxx" #include "threadPosixImpl.cxx" diff --git a/panda/src/pipeline/reMutexDirect.I b/panda/src/pipeline/reMutexDirect.I index 5a243bb1b2..e47e66f316 100755 --- a/panda/src/pipeline/reMutexDirect.I +++ b/panda/src/pipeline/reMutexDirect.I @@ -64,7 +64,7 @@ operator = (const ReMutexDirect ©) { } //////////////////////////////////////////////////////////////////// -// Function: ReMutexDirect::lock +// Function: ReMutexDirect::acquire // Access: Published // Description: Grabs the reMutex if it is available. If it is not // available, blocks until it becomes available, then @@ -79,29 +79,63 @@ operator = (const ReMutexDirect ©) { // Also see ReMutexHolder. //////////////////////////////////////////////////////////////////// INLINE void ReMutexDirect:: -lock() const { - TAU_PROFILE("void ReMutexDirect::lock()", " ", TAU_USER); +acquire() const { + TAU_PROFILE("void ReMutexDirect::acquire()", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - ((ReMutexDirect *)this)->_impl.lock(); + ((ReMutexDirect *)this)->_impl.acquire(); #else - ((ReMutexDirect *)this)->do_lock(); + ((ReMutexDirect *)this)->do_acquire(); #endif // HAVE_REMUTEXTRUEIMPL } //////////////////////////////////////////////////////////////////// -// Function: ReMutexDirect::lock +// Function: ReMutexDirect::acquire // Access: Published -// Description: This variant on lock() accepts the current thread as +// Description: This variant on acquire() accepts the current thread as // a parameter, if it is already known, as an // optimization. //////////////////////////////////////////////////////////////////// INLINE void ReMutexDirect:: -lock(Thread *current_thread) const { - TAU_PROFILE("void ReMutexDirect::lock(Thread *)", " ", TAU_USER); +acquire(Thread *current_thread) const { + TAU_PROFILE("void ReMutexDirect::acquire(Thread *)", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - ((ReMutexDirect *)this)->_impl.lock(); + ((ReMutexDirect *)this)->_impl.acquire(); #else - ((ReMutexDirect *)this)->do_lock(current_thread); + ((ReMutexDirect *)this)->do_acquire(current_thread); +#endif // HAVE_REMUTEXTRUEIMPL +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutexDirect::try_acquire +// Access: Published +// Description: Returns immediately, with a true value indicating the +// mutex has been acquired, and false indicating it has +// not. +//////////////////////////////////////////////////////////////////// +INLINE bool ReMutexDirect:: +try_acquire() const { + TAU_PROFILE("void ReMutexDirect::acquire(bool)", " ", TAU_USER); +#ifdef HAVE_REMUTEXTRUEIMPL + return ((ReMutexDirect *)this)->_impl.try_acquire(); +#else + return ((ReMutexDirect *)this)->do_try_acquire(); +#endif // HAVE_REMUTEXTRUEIMPL +} + +//////////////////////////////////////////////////////////////////// +// Function: ReMutexDirect::try_acquire +// Access: Published +// Description: Returns immediately, with a true value indicating the +// mutex has been acquired, and false indicating it has +// not. +//////////////////////////////////////////////////////////////////// +INLINE bool ReMutexDirect:: +try_acquire(Thread *current_thread) const { + TAU_PROFILE("void ReMutexDirect::acquire(bool)", " ", TAU_USER); +#ifdef HAVE_REMUTEXTRUEIMPL + return ((ReMutexDirect *)this)->_impl.try_acquire(); +#else + return ((ReMutexDirect *)this)->do_try_acquire(current_thread); #endif // HAVE_REMUTEXTRUEIMPL } @@ -114,7 +148,7 @@ lock(Thread *current_thread) const { // time to release the lock. // // This method really performs the same function as -// lock(), but it offers a potential (slight) +// acquire(), but it offers a potential (slight) // performance benefit when the calling thread knows // that it already holds the lock. It is an error to // call this when the calling thread does not hold the @@ -124,7 +158,7 @@ INLINE void ReMutexDirect:: elevate_lock() const { TAU_PROFILE("void ReMutexDirect::elevate_lock()", " ", TAU_USER); #ifdef HAVE_REMUTEXTRUEIMPL - ((ReMutexDirect *)this)->_impl.lock(); + ((ReMutexDirect *)this)->_impl.acquire(); #else ((ReMutexDirect *)this)->do_elevate_lock(); #endif // HAVE_REMUTEXTRUEIMPL @@ -209,17 +243,33 @@ get_name() const { #ifndef HAVE_REMUTEXTRUEIMPL //////////////////////////////////////////////////////////////////// -// Function: ReMutexDirect::do_lock +// Function: ReMutexDirect::do_acquire // Access: Private -// Description: The private implementation of lock(), for the case in +// Description: The private implementation of acquire(), for the case in // which the underlying lock system does not provide a // reentrant mutex (and therefore we have to build this // functionality on top of the existing non-reentrant // mutex). //////////////////////////////////////////////////////////////////// INLINE void ReMutexDirect:: -do_lock() { - do_lock(Thread::get_current_thread()); +do_acquire() { + do_acquire(Thread::get_current_thread()); +} +#endif + +#ifndef HAVE_REMUTEXTRUEIMPL +//////////////////////////////////////////////////////////////////// +// Function: ReMutexDirect::do_try_acquire +// Access: Private +// Description: The private implementation of acquire(false), for the +// case in which the underlying lock system does not +// provide a reentrant mutex (and therefore we have to +// build this functionality on top of the existing +// non-reentrant mutex). +//////////////////////////////////////////////////////////////////// +INLINE bool ReMutexDirect:: +do_try_acquire() { + return do_try_acquire(Thread::get_current_thread()); } #endif diff --git a/panda/src/pipeline/reMutexDirect.cxx b/panda/src/pipeline/reMutexDirect.cxx index 486296a730..364e9da1e9 100755 --- a/panda/src/pipeline/reMutexDirect.cxx +++ b/panda/src/pipeline/reMutexDirect.cxx @@ -30,17 +30,17 @@ output(ostream &out) const { #ifndef HAVE_REMUTEXTRUEIMPL //////////////////////////////////////////////////////////////////// -// Function: ReMutexDirect::do_lock +// Function: ReMutexDirect::do_acquire // Access: Private -// Description: The private implementation of lock(), for the case in +// Description: The private implementation of acquire(), for the case in // which the underlying lock system does not provide a // reentrant mutex (and therefore we have to build this // functionality on top of the existing non-reentrant // mutex). //////////////////////////////////////////////////////////////////// void ReMutexDirect:: -do_lock(Thread *current_thread) { - _lock_impl.lock(); +do_acquire(Thread *current_thread) { + _lock_impl.acquire(); if (_locking_thread == (Thread *)NULL) { // The mutex is not already locked by anyone. Lock it. @@ -72,11 +72,50 @@ do_lock(Thread *current_thread) { } #endif // !HAVE_REMUTEXTRUEIMPL +#ifndef HAVE_REMUTEXTRUEIMPL +//////////////////////////////////////////////////////////////////// +// Function: ReMutexDirect::do_try_acquire +// Access: Private +// Description: The private implementation of acquire(false), for the +// case in which the underlying lock system does not +// provide a reentrant mutex (and therefore we have to +// build this functionality on top of the existing +// non-reentrant mutex). +//////////////////////////////////////////////////////////////////// +bool ReMutexDirect:: +do_try_acquire(Thread *current_thread) { + bool acquired = true; + _lock_impl.acquire(); + + if (_locking_thread == (Thread *)NULL) { + // The mutex is not already locked by anyone. Lock it. + _locking_thread = current_thread; + ++_lock_count; + nassertd(_lock_count == 1) { + } + + } else if (_locking_thread == current_thread) { + // The mutex is already locked by this thread. Increment the lock + // count. + ++_lock_count; + nassertd(_lock_count > 0) { + } + + } else { + // The mutex is locked by some other thread. Return false. + acquired = false; + } + _lock_impl.release(); + + return acquired; +} +#endif // !HAVE_REMUTEXTRUEIMPL + #ifndef HAVE_REMUTEXTRUEIMPL //////////////////////////////////////////////////////////////////// // Function: ReMutexDirect::do_elevate_lock // Access: Private -// Description: The private implementation of lock(), for the case in +// Description: The private implementation of acquire(), for the case in // which the underlying lock system does not provide a // reentrant mutex (and therefore we have to build this // functionality on top of the existing non-reentrant @@ -84,7 +123,7 @@ do_lock(Thread *current_thread) { //////////////////////////////////////////////////////////////////// void ReMutexDirect:: do_elevate_lock() { - _lock_impl.lock(); + _lock_impl.acquire(); #ifdef _DEBUG nassertd(_locking_thread == Thread::get_current_thread()) { @@ -120,7 +159,7 @@ do_elevate_lock() { //////////////////////////////////////////////////////////////////// void ReMutexDirect:: do_release() { - _lock_impl.lock(); + _lock_impl.acquire(); #ifdef _DEBUG if (_locking_thread != Thread::get_current_thread()) { @@ -140,7 +179,7 @@ do_release() { if (_lock_count == 0) { // That was the last lock held by this thread. Release the lock. _locking_thread = (Thread *)NULL; - _cvar_impl.signal(); + _cvar_impl.notify(); } _lock_impl.release(); } diff --git a/panda/src/pipeline/reMutexDirect.h b/panda/src/pipeline/reMutexDirect.h index 03b0d984e9..3336171682 100644 --- a/panda/src/pipeline/reMutexDirect.h +++ b/panda/src/pipeline/reMutexDirect.h @@ -38,8 +38,10 @@ private: INLINE void operator = (const ReMutexDirect ©); PUBLISHED: - BLOCKING INLINE void lock() const; - BLOCKING INLINE void lock(Thread *current_thread) const; + BLOCKING INLINE void acquire() const; + BLOCKING INLINE void acquire(Thread *current_thread) const; + BLOCKING INLINE bool try_acquire() const; + BLOCKING INLINE bool try_acquire(Thread *current_thread) const; INLINE void elevate_lock() const; INLINE void release() const; @@ -58,8 +60,10 @@ private: #else // If we don't have a reentrant mutex, we have to hand-roll one. - INLINE void do_lock(); - void do_lock(Thread *current_thread); + INLINE void do_acquire(); + void do_acquire(Thread *current_thread); + INLINE bool do_try_acquire(); + bool do_try_acquire(Thread *current_thread); void do_elevate_lock(); void do_release(); diff --git a/panda/src/pipeline/reMutexHolder.I b/panda/src/pipeline/reMutexHolder.I index 8a5212eae0..899b3023ca 100644 --- a/panda/src/pipeline/reMutexHolder.I +++ b/panda/src/pipeline/reMutexHolder.I @@ -22,7 +22,7 @@ INLINE ReMutexHolder:: ReMutexHolder(const ReMutex &mutex) { #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) _mutex = &mutex; - _mutex->lock(); + _mutex->acquire(); #endif } @@ -37,7 +37,7 @@ INLINE ReMutexHolder:: ReMutexHolder(const ReMutex &mutex, Thread *current_thread) { #if defined(HAVE_THREADS) || defined(DEBUG_THREADS) _mutex = &mutex; - _mutex->lock(current_thread); + _mutex->acquire(current_thread); #endif } @@ -59,7 +59,7 @@ ReMutexHolder(ReMutex *&mutex) { mutex = new ReMutex; } _mutex = mutex; - _mutex->lock(); + _mutex->acquire(); #endif } diff --git a/panda/src/pipeline/semaphore.I b/panda/src/pipeline/semaphore.I new file mode 100644 index 0000000000..883fbb4096 --- /dev/null +++ b/panda/src/pipeline/semaphore.I @@ -0,0 +1,126 @@ +// Filename: semaphore.I +// Created by: drose (13Oct08) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::Constructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE Semaphore:: +Semaphore(int initial_count) : + _lock("Semaphore::_lock"), + _cvar(_lock), + _count(initial_count) +{ + nassertv(_count >= 0); +} + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::Destructor +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE Semaphore:: +~Semaphore() { +} + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::Copy Constructor +// Access: Private +// Description: Do not attempt to copy semaphores. +//////////////////////////////////////////////////////////////////// +INLINE Semaphore:: +Semaphore(const Semaphore ©) : + _cvar(_lock) +{ + nassertv(false); +} + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::Copy Assignment Operator +// Access: Private +// Description: Do not attempt to copy semaphores. +//////////////////////////////////////////////////////////////////// +INLINE void Semaphore:: +operator = (const Semaphore ©) { + nassertv(false); +} + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::acquire +// Access: Published +// Description: Decrements the internal count. If the count was +// already at zero, blocks until the count is nonzero, +// then decrements it. +//////////////////////////////////////////////////////////////////// +INLINE void Semaphore:: +acquire() { + TAU_PROFILE("void Semaphore::acquire()", " ", TAU_USER); + MutexHolder holder(_lock); + nassertv(_count >= 0); + while (_count <= 0) { + _cvar.wait(); + } + --_count; +} + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::try_acquire +// Access: Published +// Description: If the semaphore can be acquired without blocking, +// does so and returns true. Otherwise, returns false. +//////////////////////////////////////////////////////////////////// +INLINE bool Semaphore:: +try_acquire() { + TAU_PROFILE("void Semaphore::acquire(bool)", " ", TAU_USER); + MutexHolder holder(_lock); + nassertr(_count >= 0, false); + if (_count <= 0) { + return false; + } + --_count; + return true; +} + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::release +// Access: Published +// Description: Increments the semaphore's internal count. This may +// wake up another thread blocked on acquire(). +// +// Returns the count of the semaphore upon release. +//////////////////////////////////////////////////////////////////// +INLINE int Semaphore:: +release() { + TAU_PROFILE("void Semaphore::release()", " ", TAU_USER); + MutexHolder holder(_lock); + ++_count; + _cvar.notify(); + return _count; +} + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::get_count +// Access: Published +// Description: Returns the current semaphore count. Note that this +// call is not thread-safe (the count may change at any +// time). +//////////////////////////////////////////////////////////////////// +INLINE int Semaphore:: +get_count() const { + TAU_PROFILE("void Semaphore::get_count()", " ", TAU_USER); + MutexHolder holder(_lock); + return _count; +} diff --git a/panda/src/pipeline/semaphore.cxx b/panda/src/pipeline/semaphore.cxx new file mode 100644 index 0000000000..9646fd2b0a --- /dev/null +++ b/panda/src/pipeline/semaphore.cxx @@ -0,0 +1,26 @@ +// Filename: semaphore.cxx +// Created by: drose (13Oct08) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "semaphore.h" + +//////////////////////////////////////////////////////////////////// +// Function: Semaphore::output +// Access: Published +// Description: +//////////////////////////////////////////////////////////////////// +INLINE void Semaphore:: +output(ostream &out) const { + MutexHolder holder(_lock); + out << "Semaphore, count = " << _count; +} diff --git a/panda/src/pipeline/semaphore.h b/panda/src/pipeline/semaphore.h new file mode 100644 index 0000000000..6bb8672755 --- /dev/null +++ b/panda/src/pipeline/semaphore.h @@ -0,0 +1,63 @@ +// Filename: semaphore.h +// Created by: drose (13Oct08) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef SEMAPHORE_H +#define SEMAPHORE_H + +#include "pandabase.h" +#include "pmutex.h" +#include "conditionVar.h" + +//////////////////////////////////////////////////////////////////// +// Class : Semaphore +// Description : A classic semaphore synchronization primitive. +// +// A semaphore manages an internal counter which is +// decremented by each acquire() call and incremented by +// each release() call. The counter can never go below +// zero; when acquire() finds that it is zero, it +// blocks, waiting until some other thread calls +// release(). +//////////////////////////////////////////////////////////////////// +class EXPCL_PANDA_PIPELINE Semaphore { +PUBLISHED: + INLINE Semaphore(int initial_count = 1); + INLINE ~Semaphore(); +private: + INLINE Semaphore(const Semaphore ©); + INLINE void operator = (const Semaphore ©); + +PUBLISHED: + BLOCKING INLINE void acquire(); + BLOCKING INLINE bool try_acquire(); + INLINE int release(); + + INLINE int get_count() const; + void output(ostream &out) const; + +private: + Mutex _lock; + ConditionVar _cvar; + int _count; +}; + +INLINE ostream & +operator << (ostream &out, const Semaphore &sem) { + sem.output(out); + return out; +} + +#include "semaphore.I" + +#endif diff --git a/panda/src/pipeline/test_delete.cxx b/panda/src/pipeline/test_delete.cxx index 13d249666c..7a52ca552f 100644 --- a/panda/src/pipeline/test_delete.cxx +++ b/panda/src/pipeline/test_delete.cxx @@ -90,7 +90,7 @@ public: OUTPUT(nout << *this << " beginning.\n"); #ifdef WIN32_VC - rand_mutex.lock(); + rand_mutex.acquire(); srand(last_rand); rand_mutex.release(); random_f(1.0); diff --git a/panda/src/pipeline/test_diners.cxx b/panda/src/pipeline/test_diners.cxx index 674cc642c5..1ffe559a8d 100644 --- a/panda/src/pipeline/test_diners.cxx +++ b/panda/src/pipeline/test_diners.cxx @@ -77,7 +77,7 @@ private: int _id; void thread_main() { #ifdef WIN32_VC - rand_mutex.lock(); + rand_mutex.acquire(); srand(last_rand); rand_mutex.release(); random_f(1.0); @@ -95,9 +95,9 @@ private: << "\n"); int count = (int)random_f(10.0) + 1; while (--count) { - chopsticks[r].lock(); + chopsticks[r].acquire(); Thread::sleep(1); - chopsticks[l].lock(); + chopsticks[l].acquire(); PRINTMSG(cerr << "Philosopher #" << _id << " is eating spaghetti now.\n"); Thread::sleep(random_f(3.0)); @@ -107,11 +107,11 @@ private: << " is pondering about life.\n"); Thread::sleep(random_f(3.0)); } - room_mutex.lock(); + room_mutex.acquire(); --room_occupancy; cerr << "clearing philosopher " << _id << "\n"; phils[_id] = (philosopher*)0L; - room_condition.signal(); + room_condition.notify(); room_mutex.release(); PRINTMSG(cerr << "Philosopher #" << _id << " has left the room (" << room_occupancy << " left).\n"); @@ -141,7 +141,7 @@ main(int argc, char *argv[]) { } int i; - room_mutex.lock(); + room_mutex.acquire(); for (i=0; iget_short_time(); double end = start + thread_duration; while (clock->get_short_time() < end) { - _m1.lock(); + _m1.acquire(); Thread::sleep(_period); _m1.release(); } @@ -48,7 +48,7 @@ int main(int argc, char *argv[]) { MutexImpl _m1; - _m1.lock(); + _m1.acquire(); _m1.release(); cerr << "Making threads.\n"; diff --git a/panda/src/pipeline/threadPosixImpl.cxx b/panda/src/pipeline/threadPosixImpl.cxx index 68fe2a5bca..639ef7fb24 100644 --- a/panda/src/pipeline/threadPosixImpl.cxx +++ b/panda/src/pipeline/threadPosixImpl.cxx @@ -37,7 +37,7 @@ ThreadPosixImpl:: << "Deleting thread " << _parent_obj->get_name() << "\n"; } - _mutex.lock(); + _mutex.acquire(); if (!_detached) { pthread_detach(_thread); @@ -66,7 +66,7 @@ setup_main_thread() { //////////////////////////////////////////////////////////////////// bool ThreadPosixImpl:: start(ThreadPriority priority, bool joinable) { - _mutex.lock(); + _mutex.acquire(); if (thread_cat->is_debug()) { thread_cat.debug() << "Starting " << *_parent_obj << "\n"; } @@ -168,7 +168,7 @@ start(ThreadPriority priority, bool joinable) { //////////////////////////////////////////////////////////////////// void ThreadPosixImpl:: join() { - _mutex.lock(); + _mutex.acquire(); if (!_detached) { _mutex.release(); void *return_val; @@ -208,7 +208,7 @@ root_func(void *data) { nassertr(result == 0, NULL); { - self->_mutex.lock(); + self->_mutex.acquire(); nassertd(self->_status == S_start_called) { self->_mutex.release(); return NULL; @@ -227,7 +227,7 @@ root_func(void *data) { } { - self->_mutex.lock(); + self->_mutex.acquire(); nassertd(self->_status == S_running) { self->_mutex.release(); return NULL; diff --git a/panda/src/pipeline/threadWin32Impl.cxx b/panda/src/pipeline/threadWin32Impl.cxx index 156418ec5f..a22fa74e48 100644 --- a/panda/src/pipeline/threadWin32Impl.cxx +++ b/panda/src/pipeline/threadWin32Impl.cxx @@ -57,7 +57,7 @@ setup_main_thread() { //////////////////////////////////////////////////////////////////// bool ThreadWin32Impl:: start(ThreadPriority priority, bool joinable) { - _mutex.lock(); + _mutex.acquire(); if (thread_cat->is_debug()) { thread_cat.debug() << "Starting " << *_parent_obj << "\n"; } @@ -122,7 +122,7 @@ start(ThreadPriority priority, bool joinable) { //////////////////////////////////////////////////////////////////// void ThreadWin32Impl:: join() { - _mutex.lock(); + _mutex.acquire(); nassertd(_joinable && _status != S_new) { _mutex.release(); return; @@ -163,13 +163,13 @@ root_func(LPVOID data) { nassertr(result, 1); { - self->_mutex.lock(); + self->_mutex.acquire(); nassertd(self->_status == S_start_called) { self->_mutex.release(); return 1; } self->_status = S_running; - self->_cv.signal(); + self->_cv.notify(); self->_mutex.release(); } @@ -182,13 +182,13 @@ root_func(LPVOID data) { } { - self->_mutex.lock(); + self->_mutex.acquire(); nassertd(self->_status == S_running) { self->_mutex.release(); return 1; } self->_status = S_finished; - self->_cv.signal(); + self->_cv.notify(); self->_mutex.release(); } diff --git a/panda/src/pstatclient/test_client.cxx b/panda/src/pstatclient/test_client.cxx index eddce29d08..c8c0df0148 100644 --- a/panda/src/pstatclient/test_client.cxx +++ b/panda/src/pstatclient/test_client.cxx @@ -104,7 +104,7 @@ main(int argc, char *argv[]) { exit(1); } - signal(SIGINT, &signal_handler); + notify(SIGINT, &signal_handler); PStatClient *client = PStatClient::get_global_pstats(); client->set_client_name("Bogus Stats"); diff --git a/panda/src/putil/copyOnWriteObject.cxx b/panda/src/putil/copyOnWriteObject.cxx index 86c22333ed..369ed82692 100644 --- a/panda/src/putil/copyOnWriteObject.cxx +++ b/panda/src/putil/copyOnWriteObject.cxx @@ -36,7 +36,7 @@ unref() const { if (get_ref_count() == get_cache_ref_count()) { ((CopyOnWriteObject *)this)->_lock_status = LS_unlocked; ((CopyOnWriteObject *)this)->_locking_thread = NULL; - ((CopyOnWriteObject *)this)->_lock_cvar.signal(); + ((CopyOnWriteObject *)this)->_lock_cvar.notify(); } return is_zero; } diff --git a/panda/src/vrpn/vrpnAnalog.cxx b/panda/src/vrpn/vrpnAnalog.cxx index 287ce4c5c2..40e55796a4 100644 --- a/panda/src/vrpn/vrpnAnalog.cxx +++ b/panda/src/vrpn/vrpnAnalog.cxx @@ -115,7 +115,7 @@ vrpn_analog_callback(void *userdata, const vrpn_ANALOGCB info) { Devices::iterator di; for (di = self->_devices.begin(); di != self->_devices.end(); ++di) { VrpnAnalogDevice *device = (*di); - device->lock(); + device->acquire(); for (int i = 0; i < info.num_channel; i++) { if (vrpn_cat.is_debug()) { if (device->get_control_state(i) != info.channel[i]) { diff --git a/panda/src/vrpn/vrpnButton.cxx b/panda/src/vrpn/vrpnButton.cxx index ca5501df2b..444fea8708 100644 --- a/panda/src/vrpn/vrpnButton.cxx +++ b/panda/src/vrpn/vrpnButton.cxx @@ -119,7 +119,7 @@ vrpn_button_callback(void *userdata, const vrpn_BUTTONCB info) { Devices::iterator di; for (di = self->_devices.begin(); di != self->_devices.end(); ++di) { VrpnButtonDevice *device = (*di); - device->lock(); + device->acquire(); device->set_button_state(info.button, info.state != 0); device->unlock(); } diff --git a/panda/src/vrpn/vrpnDial.cxx b/panda/src/vrpn/vrpnDial.cxx index 80f0589dab..34d4ae549a 100644 --- a/panda/src/vrpn/vrpnDial.cxx +++ b/panda/src/vrpn/vrpnDial.cxx @@ -120,7 +120,7 @@ vrpn_dial_callback(void *userdata, const vrpn_DIALCB info) { Devices::iterator di; for (di = self->_devices.begin(); di != self->_devices.end(); ++di) { VrpnDialDevice *device = (*di); - device->lock(); + device->acquire(); device->push_dial(info.dial, info.change); device->unlock(); } diff --git a/panda/src/vrpn/vrpnTracker.cxx b/panda/src/vrpn/vrpnTracker.cxx index fc421a7df9..801d6f790d 100644 --- a/panda/src/vrpn/vrpnTracker.cxx +++ b/panda/src/vrpn/vrpnTracker.cxx @@ -123,7 +123,7 @@ vrpn_position_callback(void *userdata, const vrpn_TRACKERCB info) { VrpnTrackerDevice *device = (*di); if (device->get_sensor() == info.sensor && device->get_data_type() == VrpnTrackerDevice::DT_position) { - device->lock(); + device->acquire(); device->_data.set_time(VrpnClient::convert_to_secs(info.msg_time)); device->_data.set_pos(LPoint3f(info.pos[0], info.pos[1], info.pos[2])); device->_data.set_orient(LOrientationf(info.quat[3], info.quat[0], info.quat[1], info.quat[2])); @@ -152,7 +152,7 @@ vrpn_velocity_callback(void *userdata, const vrpn_TRACKERVELCB info) { VrpnTrackerDevice *device = (*di); if (device->get_sensor() == info.sensor && device->get_data_type() == VrpnTrackerDevice::DT_velocity) { - device->lock(); + device->acquire(); device->_data.set_time(VrpnClient::convert_to_secs(info.msg_time)); device->_data.set_pos(LPoint3f(info.vel[0], info.vel[1], info.vel[2])); device->_data.set_orient(LOrientationf(info.vel_quat[3], info.vel_quat[0], @@ -183,7 +183,7 @@ vrpn_acceleration_callback(void *userdata, const vrpn_TRACKERACCCB info) { VrpnTrackerDevice *device = (*di); if (device->get_sensor() == info.sensor && device->get_data_type() == VrpnTrackerDevice::DT_acceleration) { - device->lock(); + device->acquire(); device->_data.set_time(VrpnClient::convert_to_secs(info.msg_time)); device->_data.set_pos(LPoint3f(info.acc[0], info.acc[1], info.acc[2])); device->_data.set_orient(LOrientationf(info.acc_quat[3], info.acc_quat[0],