root/juggler/tags/1.0.5/Sync/vjNullMutex.h
| Revision 2828, 4.6 kB (checked in by patrickh, 8 years ago) | |
|---|---|
| |
| Line | |
|---|---|
| 1 | /*************** <auto-copyright.pl BEGIN do not edit this line> ************** |
| 2 | * |
| 3 | * VR Juggler is (C) Copyright 1998, 1999, 2000 by Iowa State University |
| 4 | * |
| 5 | * Original Authors: |
| 6 | * Allen Bierbaum, Christopher Just, |
| 7 | * Patrick Hartling, Kevin Meinert, |
| 8 | * Carolina Cruz-Neira, Albert Baker |
| 9 | * |
| 10 | * This library is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU Library General Public |
| 12 | * License as published by the Free Software Foundation; either |
| 13 | * version 2 of the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This library is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 18 | * Library General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU Library General Public |
| 21 | * License along with this library; if not, write to the |
| 22 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 23 | * Boston, MA 02111-1307, USA. |
| 24 | * |
| 25 | * ----------------------------------------------------------------- |
| 26 | * File: $RCSfile$ |
| 27 | * Date modified: $Date$ |
| 28 | * Version: $Revision$ |
| 29 | * ----------------------------------------------------------------- |
| 30 | * |
| 31 | *************** <auto-copyright.pl END do not edit this line> ***************/ |
| 32 | |
| 33 | |
| 34 | #ifndef _vjNullMutex_h_ |
| 35 | #define _vjNullMutex_h_ |
| 36 | //---------------------------------------------- |
| 37 | // vjNullMutex |
| 38 | // |
| 39 | // Purpose: |
| 40 | // Null mutex wrapper. Used to pass a do nothing |
| 41 | // mutex as a template type. |
| 42 | // |
| 43 | // Author: |
| 44 | // Allen Bierbaum |
| 45 | // |
| 46 | // Date: 1-21-97 |
| 47 | //----------------------------------------------- |
| 48 | |
| 49 | #include <vjConfig.h> |
| 50 | |
| 51 | //: Null mutex wrapper. Used to pass a "do nothing" mutex as a template type. |
| 52 | //!PUBLIC_API: |
| 53 | class vjNullMutex |
| 54 | { |
| 55 | public: |
| 56 | vjNullMutex () {} |
| 57 | ~vjNullMutex() {} |
| 58 | |
| 59 | |
| 60 | //--------------------------------------------------------- |
| 61 | //: Lock the mutex. |
| 62 | // |
| 63 | //! RETURNS: 1 - Acquired |
| 64 | //! RETURNS: -1 - Error |
| 65 | //--------------------------------------------------------- |
| 66 | int acquire() const |
| 67 | { |
| 68 | return 1; |
| 69 | } |
| 70 | |
| 71 | //---------------------------------------------------------- |
| 72 | //: Acquire a read mutex. |
| 73 | //---------------------------------------------------------- |
| 74 | int acquireRead() const |
| 75 | { |
| 76 | return this->acquire(); // No special "read" semaphore -- For now |
| 77 | } |
| 78 | |
| 79 | //---------------------------------------------------------- |
| 80 | //: Acquire a write mutex. |
| 81 | //---------------------------------------------------------- |
| 82 | int acquireWrite() const |
| 83 | { |
| 84 | return this->acquire(); // No special "write" semaphore -- For now |
| 85 | } |
| 86 | |
| 87 | //--------------------------------------------------------- |
| 88 | //: Try to acquire the lock. Returns immediately even if |
| 89 | //+ we don't acquire the lock. |
| 90 | // |
| 91 | //! RETURNS: 1 - Acquired |
| 92 | //! RETURNS: 0 - Not acquired |
| 93 | //--------------------------------------------------------- |
| 94 | int tryAcquire () const |
| 95 | { |
| 96 | return 1; // Try 100 spins. |
| 97 | } |
| 98 | |
| 99 | //---------------------------------------------------------- |
| 100 | //: Try to acquire a read mutex. |
| 101 | //---------------------------------------------------------- |
| 102 | int tryacquire_read () const |
| 103 | { |
| 104 | return this->tryAcquire(); |
| 105 | } |
| 106 | |
| 107 | //---------------------------------------------------------- |
| 108 | //: Try to acquire a write mutex. |
| 109 | //---------------------------------------------------------- |
| 110 | int tryacquire_write () const |
| 111 | { |
| 112 | return this->tryAcquire(); |
| 113 | } |
| 114 | |
| 115 | //--------------------------------------------------------- |
| 116 | //: Release the mutex. |
| 117 | // |
| 118 | //! RETURNS: 0 - Success |
| 119 | //! RETURNS: -1 - Error |
| 120 | //--------------------------------------------------------- |
| 121 | int release() const |
| 122 | { |
| 123 | return 0; |
| 124 | } |
| 125 | |
| 126 | //------------------------------------------------------ |
| 127 | //: Test the current lock status. |
| 128 | // |
| 129 | //! RETURNS: 0 - Not locked |
| 130 | //! RETURNS: 1 - Locked |
| 131 | //------------------------------------------------------ |
| 132 | int test() |
| 133 | { |
| 134 | return 0; // Just return 0 since it is a null lock |
| 135 | } |
| 136 | |
| 137 | //--------------------------------------------------------- |
| 138 | //: Dump the mutex debug stuff and current state. |
| 139 | //--------------------------------------------------------- |
| 140 | #ifndef VJ_OS_Win32 |
| 141 | void dump (FILE* dest = stderr, const char* message = "\n------ Mutex Dump -----\n") const |
| 142 | { |
| 143 | std::cerr << message << "NULL Mutex\n"; |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | protected: |
| 148 | // = Prevent assignment and initialization. |
| 149 | void operator= (const vjNullMutex &) {} |
| 150 | vjNullMutex (const vjNullMutex &) {} |
| 151 | }; |
| 152 | |
| 153 | #endif |
Note: See TracBrowser for help on using the browser.
