open_toontown_panda3d/panda/src/pipeline/reMutexSimpleImpl.I

79 lines
2.3 KiB
Plaintext

// Filename: reMutexSimpleImpl.I
// Created by: drose (20Jun07)
//
////////////////////////////////////////////////////////////////////
//
// 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: ReMutexSimpleImpl::Constructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE ReMutexSimpleImpl::
ReMutexSimpleImpl() {
}
////////////////////////////////////////////////////////////////////
// Function: ReMutexSimpleImpl::Destructor
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE ReMutexSimpleImpl::
~ReMutexSimpleImpl() {
}
////////////////////////////////////////////////////////////////////
// Function: ReMutexSimpleImpl::lock
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void ReMutexSimpleImpl::
lock() {
if (!try_lock()) {
do_lock();
}
}
////////////////////////////////////////////////////////////////////
// Function: ReMutexSimpleImpl::try_lock
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE bool ReMutexSimpleImpl::
try_lock() {
ThreadSimpleManager *manager = ThreadSimpleManager::get_global_ptr();
ThreadSimpleImpl *thread = manager->get_current_thread();
thread->consider_yield_this();
if ((_flags & F_lock_count) != 0) {
return false;
}
++_flags;
_locking_thread = thread;
return true;
}
////////////////////////////////////////////////////////////////////
// Function: ReMutexSimpleImpl::release
// Access: Public
// Description:
////////////////////////////////////////////////////////////////////
INLINE void ReMutexSimpleImpl::
release() {
nassertv((_flags & F_lock_count) != 0);
--_flags;
if ((_flags & F_lock_count) == 0 && (_flags & F_has_waiters)) {
do_release();
}
}