![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * Lockable object base type (used in threading) * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************/ 00022 #ifndef FXLOCKABLE_H 00023 #define FXLOCKABLE_H 00024 00025 namespace FXEX { 00026 00027 /** 00028 * A lockable class is a base type for lockable objects. 00029 * We use lock/unlock & acquire/release, to make it easier on programmers :-) 00030 */ 00031 class FXAPI FXLockable { 00032 00033 protected: 00034 FXuint lock_; // lock count 00035 00036 protected: 00037 FXLockable(); 00038 00039 public: 00040 /// are we locked? 00041 inline FXbool locked() { return lock_?TRUE:FALSE; } 00042 00043 /// lock mutex 00044 virtual void lock()=0; 00045 00046 /// try to lock, within some period 00047 virtual FXbool trylock(FXuint ms)=0; 00048 00049 /// release mutex lock 00050 virtual void unlock()=0; 00051 00052 /// lock mutex 00053 inline void acquire() { lock(); } 00054 00055 /// try to lock 00056 inline FXbool tryacquire(FXint ms) { return trylock(ms); } 00057 00058 /// release mutex lock 00059 inline void release() { unlock(); } 00060 00061 /// dtor 00062 virtual ~FXLockable(){} 00063 }; 00064 00065 } // namespace FXEX 00066 #endif // FXLOCKABLE_H