Panda3D

reMutexDirect.h

00001 // Filename: reMutexDirect.h
00002 // Created by:  drose (13Feb06)
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 #ifndef REMUTEXDIRECT_H
00016 #define REMUTEXDIRECT_H
00017 
00018 #include "pandabase.h"
00019 #include "mutexTrueImpl.h"
00020 #include "conditionVarImpl.h"
00021 
00022 class Thread;
00023 
00024 #ifndef DEBUG_THREADS
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : ReMutexDirect
00028 // Description : This class implements a standard reMutex by making
00029 //               direct calls to the underlying implementation layer.
00030 //               It doesn't perform any debugging operations.
00031 ////////////////////////////////////////////////////////////////////
00032 class EXPCL_PANDA_PIPELINE ReMutexDirect {
00033 protected:
00034   INLINE ReMutexDirect();
00035   INLINE ~ReMutexDirect();
00036 private:
00037   INLINE ReMutexDirect(const ReMutexDirect &copy);
00038   INLINE void operator = (const ReMutexDirect &copy);
00039 
00040 PUBLISHED:
00041   BLOCKING INLINE void acquire() const;
00042   BLOCKING INLINE void acquire(Thread *current_thread) const;
00043   BLOCKING INLINE bool try_acquire() const;
00044   BLOCKING INLINE bool try_acquire(Thread *current_thread) const;
00045   INLINE void elevate_lock() const;
00046   INLINE void release() const;
00047 
00048   INLINE bool debug_is_locked() const;
00049 
00050   INLINE void set_name(const string &name);
00051   INLINE void clear_name();
00052   INLINE bool has_name() const;
00053   INLINE string get_name() const;
00054 
00055   void output(ostream &out) const;
00056 
00057 private:
00058 #ifdef HAVE_REMUTEXTRUEIMPL
00059   ReMutexImpl _impl;
00060 
00061 #else
00062   // If we don't have a reentrant mutex, we have to hand-roll one.
00063   INLINE void do_acquire();
00064   void do_acquire(Thread *current_thread);
00065   INLINE bool do_try_acquire();
00066   bool do_try_acquire(Thread *current_thread);
00067   void do_elevate_lock();
00068   void do_release();
00069 
00070   Thread *_locking_thread;
00071   int _lock_count;
00072 
00073   MutexTrueImpl _lock_impl;
00074   ConditionVarImpl _cvar_impl;
00075 #endif  // HAVE_REMUTEXTRUEIMPL
00076 
00077   friend class LightReMutexDirect;
00078 };
00079 
00080 INLINE ostream &
00081 operator << (ostream &out, const ReMutexDirect &m) {
00082   m.output(out);
00083   return out;
00084 }
00085 
00086 #include "reMutexDirect.I"
00087 
00088 #endif  // !DEBUG_THREADS
00089 
00090 #endif
 All Classes Functions Variables Enumerations