Panda3D

mutexSimpleImpl.I

00001 // Filename: mutexSimpleImpl.I
00002 // Created by:  drose (19Jun07)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: MutexSimpleImpl::Constructor
00018 //       Access: Public
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE MutexSimpleImpl::
00022 MutexSimpleImpl() {
00023 }
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: MutexSimpleImpl::Destructor
00027 //       Access: Public
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 INLINE MutexSimpleImpl::
00031 ~MutexSimpleImpl() {
00032 }
00033 
00034 ////////////////////////////////////////////////////////////////////
00035 //     Function: MutexSimpleImpl::acquire
00036 //       Access: Public
00037 //  Description: 
00038 ////////////////////////////////////////////////////////////////////
00039 INLINE void MutexSimpleImpl::
00040 acquire() {
00041   if (!try_acquire()) {
00042     do_acquire();
00043   }
00044 }
00045 
00046 ////////////////////////////////////////////////////////////////////
00047 //     Function: MutexSimpleImpl::try_acquire
00048 //       Access: Public
00049 //  Description: 
00050 ////////////////////////////////////////////////////////////////////
00051 INLINE bool MutexSimpleImpl::
00052 try_acquire() {
00053   if ((_flags & F_lock_count) != 0) {
00054     return false;
00055   }
00056   _flags |= F_lock_count;
00057   return true;
00058 }
00059 
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: MutexSimpleImpl::release
00062 //       Access: Public
00063 //  Description: Releases the mutex.  An immediate context switch
00064 //               might occur if there were waiters on the mutex.
00065 ////////////////////////////////////////////////////////////////////
00066 INLINE void MutexSimpleImpl::
00067 release() {
00068   nassertv((_flags & F_lock_count) != 0);
00069   _flags &= ~F_lock_count;
00070 
00071   if (_flags & F_has_waiters) {
00072     do_release();
00073   }
00074 }
00075 
00076 ////////////////////////////////////////////////////////////////////
00077 //     Function: MutexSimpleImpl::release_quietly
00078 //       Access: Public
00079 //  Description: Releases the mutex, without allowing a context switch
00080 //               to occur.
00081 ////////////////////////////////////////////////////////////////////
00082 INLINE void MutexSimpleImpl::
00083 release_quietly() {
00084   nassertv((_flags & F_lock_count) != 0);
00085   _flags &= ~F_lock_count;
00086 
00087   if (_flags & F_has_waiters) {
00088     do_release_quietly();
00089   }
00090 }
 All Classes Functions Variables Enumerations