Main Page   Reference Manual   Namespace List   Compound List   Namespace Members   Compound Members   File Members  

libcwd/private_lock_interface.h

Go to the documentation of this file.
00001 // $Header: /cvsroot/libcwd/libcwd/include/libcwd/private_lock_interface.h,v 1.4 2004/06/03 12:23:07 libcw Exp $
00002 //
00003 // Copyright (C) 2002 - 2004, by
00004 // 
00005 // Carlo Wood, Run on IRC <carlo@alinoe.com>
00006 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
00007 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
00008 //
00009 // This file may be distributed under the terms of the Q Public License
00010 // version 1.0 as appearing in the file LICENSE.QPL included in the
00011 // packaging of this file.
00012 //
00013 
00018 #ifndef LIBCWD_PRIVATE_LOCK_INTERFACE_H
00019 #define LIBCWD_PRIVATE_LOCK_INTERFACE_H
00020 
00021 #if LIBCWD_THREAD_SAFE
00022 namespace libcwd {
00023   namespace _private_ {
00024 
00025 class lock_interface_base_ct {
00026 public:
00027   virtual int trylock(void) = 0;
00028   virtual void lock(void) = 0;
00029   virtual void unlock(void) = 0;
00030   virtual ~lock_interface_base_ct() { }
00031 };
00032 
00033 template<class T>
00034   class lock_interface_tct : public lock_interface_base_ct {
00035     private:
00036       T* ptr;
00037       virtual int trylock(void) { return ptr->trylock(); }
00038       virtual void lock(void) { ptr->lock(); }
00039       virtual void unlock(void) { ptr->unlock(); }
00040     public:
00041       lock_interface_tct(T* mutex) : ptr(mutex) { }
00042   };
00043 
00044 class pthread_lock_interface_ct : public lock_interface_base_ct {
00045   private:
00046     pthread_mutex_t* ptr;
00047     virtual int trylock(void);
00048     virtual void lock(void);
00049     virtual void unlock(void);
00050   public:
00051     pthread_lock_interface_ct(pthread_mutex_t* mutex) : ptr(mutex) { }
00052 };
00053 
00054   } // namespace _private_
00055 }  // namespace libcwd
00056 
00057 #endif // LIBCWD_THREAD_SAFE
00058 #endif // LIBCWD_PRIVATE_LOCK_INTERFACE_H
00059 
Copyright © 2001 - 2004 Carlo Wood.  All rights reserved.