Home C-Bits Package Documentation Project Page

Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

ResourceLock.h

Go to the documentation of this file.
00001 /* ====================================================================
00002  *              The CBITS Software License, Version 1.0
00003  *
00004  *               Copyright (c) 2002-2003 Bruce Lowery
00005  *                       All rights reserved
00006  *
00007  * Redistribution and use of this software, in source and binary forms,
00008  * with or without modification, are permitted provided that the above
00009  * copyright notice, this paragraph, and the following paragraph are
00010  * retained in each source code file.
00011  *
00012  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00013  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00014  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00015  * DISCLAIMED.  IN NO EVENT SHALL BRUCE LOWERY OR OTHER CONTRIBUTORS
00016  * TO THE CBITS LIBRARY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00017  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00018  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00019  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00020  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00021  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00022  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00023  * SUCH DAMAGE.
00024  * ====================================================================
00025  */
00026 #ifndef __RESOURCE_LOCK_H__
00027 #define __RESOURCE_LOCK_H__
00028 
00029 #include <list>
00030 #include <set>
00031 
00032 #ifdef BUILD_DLL
00033 #define EXPORT __declspec(dllexport)
00034 #else
00035 #define EXPORT
00036 #endif
00037 
00038 
00039 namespace cbits
00040 {
00041 
00061 class EXPORT ResourceLock
00062 {
00063 
00064 public:
00069     enum LockType
00070     {
00072         NONE  = -1,
00073 
00075         READ  = +1,
00076 
00078         WRITE = +2
00079     };
00080 
00081 
00088     static ResourceLock* create();
00089 
00090 
00129     const bool     lock
00130     ( 
00132         const LockType
00133     );
00134 
00135 
00146     const bool     unlock();
00147 
00148 
00156     const bool     isLocked()    const;
00157 
00158 
00166     const bool     isOwner
00167     (
00169         const bool lockit=true 
00170     ) const;
00171 
00172 
00183     const LockType getLockType() const;
00184 
00185 
00190     virtual ~ResourceLock();
00191 
00192 
00193 protected:
00194 
00199     ResourceLock();
00200 
00201 
00213     virtual const bool impl_lock_obj()     const = 0;
00214 
00215 
00224     virtual const bool impl_unlock_obj()   const = 0;
00225 
00226 
00233     virtual const long impl_get_threadid() const = 0;
00234 
00235 
00244     virtual const bool impl_wait_for_event() = 0;
00245 
00246 
00256     virtual const bool impl_send_event()     = 0;
00257 
00258 
00259     std::list<long> _queue;
00261 private:
00262 
00263 
00272     const bool get_read_lock();
00273 
00274 
00283     const bool get_write_lock();
00284 
00285 
00287     std::set<long>  _read_locks;
00288 
00290     long            _write_lock;
00291 };
00292 
00293 };
00294 
00295 #endif
00296 
00297 /*
00298  * $Id: ResourceLock.h,v 1.5 2002/10/07 21:07:41 brulow Exp $
00299  *
00300  * History: (Add nothing manually below)
00301  * -----------------------------------------------------------------------
00302  *
00303  * $Log: ResourceLock.h,v $
00304  * Revision 1.5  2002/10/07 21:07:41  brulow
00305  * Add/improve documentation
00306  *
00307  * Revision 1.4  2002/10/07 00:24:56  brulow
00308  * Fix comments
00309  *
00310  * Revision 1.3  2002/10/06 04:13:01  brulow
00311  * Add unit thread pkg unit tests and fix thread pkg bugs.
00312  *
00313  * Revision 1.2  2002/10/03 15:09:23  brulow
00314  * Add footer
00315  *
00316  *
00317  */

Generated by
doxygen
Hosted by
SourceForge