Drizzled Public API Documentation

CSMutex.h
00001 /* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
00002  *
00003  * PrimeBase Media Stream for MySQL
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00018  *
00019  * Original author: Paul McCullagh (H&G2JCtL)
00020  * Continued development: Barry Leslie
00021  *
00022  * 2007-06-06
00023  *
00024  * CORE SYSTEM:
00025  * A basic mutex (mutual exclusion) object.
00026  *
00027  */
00028 
00029 #pragma once
00030 #ifndef __CSMUTEX_H__
00031 #define __CSMUTEX_H__
00032 
00033 #include <pthread.h>
00034 
00035 #include "CSDefs.h"
00036 
00037 class CSThread;
00038 
00039 class CSMutex {
00040 public:
00041   CSMutex();
00042   virtual ~CSMutex();
00043 
00044   virtual void lock();
00045   virtual void unlock();
00046 
00047   friend class CSLock;
00048   friend class CSSync;
00049 
00050 private:
00051   pthread_mutex_t iMutex;
00052 #ifdef DEBUG
00053   CSThread    *iLocker;
00054 public:
00055   bool      trace;
00056 #endif
00057 };
00058 
00059 class CSLock : public CSMutex {
00060 public:
00061   CSLock();
00062   virtual ~CSLock();
00063 
00064   virtual void lock();
00065   virtual void unlock();
00066   virtual bool haveLock();
00067 
00068   friend class CSSync;
00069 
00070 private:
00071   CSThread    *iLockingThread;
00072   int       iLockCount;
00073 };
00074 
00075 class CSSync : public CSLock {
00076 public:
00077   CSSync();
00078   virtual ~CSSync();
00079   
00080   /* Wait for resources on the object
00081    * to be freed.
00082    *
00083    * This function may only be called
00084    * if the thread has already locked the
00085    * object.
00086    */
00087   virtual void wait();
00088 
00089   /* Wait for a certain amount of time, in
00090    * milli-seconds (1/1000th of a second).
00091    */
00092   void wait(time_t mill_sec);
00093 
00094   /*
00095    * Wakeup any waiters.
00096    */
00097   virtual void wakeup();
00098 
00099 private:
00100   pthread_cond_t  iCondition;
00101 };
00102 
00103 #endif
00104