JackPthreadCond.h

00001 /*
00002 Copyright (C) 2004-2005 Grame  
00003 
00004 This program is free software; you can redistribute it and/or modify
00005   it under the terms of the GNU General Public License as published by
00006   the Free Software Foundation; either version 2 of the License, or
00007   (at your option) any later version.
00008 
00009   This program is distributed in the hope that it will be useful,
00010   but WITHOUT ANY WARRANTY; without even the implied warranty of
00011   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012   GNU General Public License for more details.
00013 
00014   You should have received a copy of the GNU General Public License
00015   along with this program; if not, write to the Free Software
00016   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017 
00018 */
00019 
00020 #ifndef __JackPthreadCond__
00021 #define __JackPthreadCond__
00022 
00023 #include "JackSynchro.h"
00024 #include "JackShmMem.h"
00025 #include <pthread.h>
00026 #include <sys/time.h>
00027 #include <time.h>
00028 #include <stdio.h>
00029 #include <assert.h>
00030 
00031 #define MAX_ITEM 8
00032 
00033 namespace Jack
00034 {
00035 
00036 struct JackPthreadCondItem
00037 {
00038     char fName[SYNC_MAX_NAME_SIZE];
00039     pthread_mutex_t fLock;
00040     pthread_cond_t fCond;
00041 };
00042 
00043 struct JackPthreadCondArray : public JackShmMem
00044 {
00045     JackPthreadCondItem fTable[MAX_ITEM];
00046 
00047     JackPthreadCondArray();
00048     virtual ~JackPthreadCondArray()
00049     {}
00050 };
00051 
00056 class JackPthreadCond : public JackSynchro
00057 {
00058 
00059     protected:
00060 
00061         JackPthreadCondItem* fSynchro;
00062         void BuildName(const char* name, char* res);
00063         virtual JackPthreadCondArray* GetTable() = 0;
00064 
00065     public:
00066 
00067         JackPthreadCond(): fSynchro(NULL)
00068         {}
00069         virtual ~JackPthreadCond()
00070         {}
00071 
00072         bool Signal();
00073         bool SignalAll();
00074         bool Wait();
00075         bool TimedWait(long usec);
00076 
00077         bool Connect(const char* name);
00078         bool ConnectInput(const char* name);
00079         bool ConnectOutput(const char* name);
00080         bool Disconnect();
00081 };
00082 
00083 class JackPthreadCondServer : public JackPthreadCond
00084 {
00085 
00086     private:
00087 
00088         static JackPthreadCondArray* fTable;
00089         static long fCount;
00090 
00091     protected:
00092 
00093         JackPthreadCondArray* GetTable()
00094         {
00095             return fTable;
00096         }
00097 
00098     public:
00099 
00100         JackPthreadCondServer();
00101         virtual ~JackPthreadCondServer();
00102 
00103         bool Allocate(const char* name, int value);
00104         void Destroy();
00105 };
00106 
00107 class JackPthreadCondClient : public JackPthreadCond
00108 {
00109 
00110     private:
00111 
00112         static JackShmReadWritePtr1<JackPthreadCondArray> fTable;
00113         static long fCount;
00114 
00115     protected:
00116 
00117         JackPthreadCondArray* GetTable()
00118         {
00119             return fTable;
00120         }
00121 
00122     public:
00123 
00124         JackPthreadCondClient(int shared_index);
00125         virtual ~JackPthreadCondClient();
00126 };
00127 
00128 } // end of namespace
00129 
00130 #endif
00131 

Generated on Mon Oct 15 17:11:14 2007 for Jackdmp by  doxygen 1.5.1