1 // $Header$
2 //
3 // Copyright (C) 2002 - 2004, by
4 //
5 // Carlo Wood, Run on IRC <carlo@alinoe.com>
6 // RSA-1024 0x624ACAD5 1997-01-26                    Sign & Encrypt
7 // Fingerprint16 = 32 EC A7 B6 AC DB 65 A6  F6 F6 55 DD 1C DC FF 61
8 //
9 // This file may be distributed under the terms of the Q Public License
10 // version 1.0 as appearing in the file LICENSE.QPL included in the
11 // packaging of this file.
12 //
13 
14 /** \file private_lock_interface.h
15  * Do not include this header file directly, instead include \ref preparation_step2 "debug.h".
16  */
17 
18 #ifndef LIBCWD_PRIVATE_LOCK_INTERFACE_H
19 #define LIBCWD_PRIVATE_LOCK_INTERFACE_H
20 
21 #if LIBCWD_THREAD_SAFE
22 namespace libcwd {
23   namespace _private_ {
24 
25 class lock_interface_base_ct {
26 public:
27   virtual int trylock(void) = 0;
28   virtual void lock(void) = 0;
29   virtual void unlock(void) = 0;
~lock_interface_base_ct()30   virtual ~lock_interface_base_ct() { }
31 };
32 
33 template<class T>
34   class lock_interface_tct : public lock_interface_base_ct {
35     private:
36       T* ptr;
trylock(void)37       virtual int trylock(void) { return ptr->trylock(); }
lock(void)38       virtual void lock(void) { ptr->lock(); }
unlock(void)39       virtual void unlock(void) { ptr->unlock(); }
40     public:
lock_interface_tct(T * mutex)41       lock_interface_tct(T* mutex) : ptr(mutex) { }
42   };
43 
44 class pthread_lock_interface_ct : public lock_interface_base_ct {
45   private:
46     pthread_mutex_t* ptr;
47     virtual int trylock(void);
48     virtual void lock(void);
49     virtual void unlock(void);
50   public:
pthread_lock_interface_ct(pthread_mutex_t * mutex)51     pthread_lock_interface_ct(pthread_mutex_t* mutex) : ptr(mutex) { }
52 };
53 
54   } // namespace _private_
55 }  // namespace libcwd
56 
57 #endif // LIBCWD_THREAD_SAFE
58 #endif // LIBCWD_PRIVATE_LOCK_INTERFACE_H
59 
60