Panda3D

reMutexHolder.I

00001 // Filename: reMutexHolder.I
00002 // Created by:  drose (15Jan06)
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: ReMutexHolder::Constructor
00018 //       Access: Public
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE ReMutexHolder::
00022 ReMutexHolder(const ReMutex &mutex) {
00023 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
00024   _mutex = &mutex;
00025   _mutex->acquire();
00026 #endif
00027 }
00028 
00029 ////////////////////////////////////////////////////////////////////
00030 //     Function: ReMutexHolder::Constructor
00031 //       Access: Public
00032 //  Description: This variant on the constructor accepts the current
00033 //               thread as a parameter, if it is already known, as an
00034 //               optimization.
00035 ////////////////////////////////////////////////////////////////////
00036 INLINE ReMutexHolder::
00037 ReMutexHolder(const ReMutex &mutex, Thread *current_thread) {
00038 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
00039   _mutex = &mutex;
00040   _mutex->acquire(current_thread);
00041 #endif
00042 }
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //     Function: ReMutexHolder::Constructor
00046 //       Access: Public
00047 //  Description: If the ReMutexHolder constructor is given a pointer to
00048 //               a ReMutex object (instead of an actual object), it will
00049 //               first check to see if the pointer is NULL, and
00050 //               allocate a new ReMutex if it is.  This is intended as a
00051 //               convenience for functions that may need to reference
00052 //               a ReMutex at static init time, when it is impossible to
00053 //               guarantee ordering of initializers.
00054 ////////////////////////////////////////////////////////////////////
00055 INLINE ReMutexHolder::
00056 ReMutexHolder(ReMutex *&mutex) {
00057 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
00058   if (mutex == (ReMutex *)NULL) {
00059     mutex = new ReMutex;
00060   }
00061   _mutex = mutex;
00062   _mutex->acquire();
00063 #endif
00064 }
00065 
00066 ////////////////////////////////////////////////////////////////////
00067 //     Function: ReMutexHolder::Destructor
00068 //       Access: Public
00069 //  Description:
00070 ////////////////////////////////////////////////////////////////////
00071 INLINE ReMutexHolder::
00072 ~ReMutexHolder() {
00073 #if defined(HAVE_THREADS) || defined(DEBUG_THREADS)
00074   _mutex->release();
00075 #endif
00076 }
00077 
00078 ////////////////////////////////////////////////////////////////////
00079 //     Function: ReMutexHolder::Copy Constructor
00080 //       Access: Private
00081 //  Description: Do not attempt to copy ReMutexHolders.
00082 ////////////////////////////////////////////////////////////////////
00083 INLINE ReMutexHolder::
00084 ReMutexHolder(const ReMutexHolder &copy) {
00085   nassertv(false);
00086 }
00087 
00088 ////////////////////////////////////////////////////////////////////
00089 //     Function: ReMutexHolder::Copy Assignment Operator
00090 //       Access: Private
00091 //  Description: Do not attempt to copy ReMutexHolders.
00092 ////////////////////////////////////////////////////////////////////
00093 INLINE void ReMutexHolder::
00094 operator = (const ReMutexHolder &copy) {
00095   nassertv(false);
00096 }
 All Classes Functions Variables Enumerations