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 ;
00052 
00057 class JackPthreadCond : public JackSynchro
00058 {
00059 
00060     protected:
00061 
00062         JackPthreadCondItem* fSynchro;
00063         void BuildName(const char* name, char* res);
00064         virtual JackPthreadCondArray* GetTable() = 0;
00065 
00066     public:
00067 
00068         JackPthreadCond(): fSynchro(NULL)
00069         {}
00070         virtual ~JackPthreadCond()
00071         {}
00072 
00073         bool Signal();
00074         bool SignalAll();
00075         bool Wait();
00076         bool TimedWait(long usec);
00077 
00078         bool Connect(const char* name);
00079         bool ConnectInput(const char* name);
00080         bool ConnectOutput(const char* name);
00081         bool Disconnect();
00082 
00083 };
00084 
00085 class JackPthreadCondServer : public JackPthreadCond
00086 {
00087 
00088     private:
00089 
00090         static JackPthreadCondArray* fTable;
00091         static long fCount;
00092 
00093     protected:
00094 
00095         JackPthreadCondArray* GetTable()
00096         {
00097             return fTable;
00098         }
00099 
00100     public:
00101 
00102         JackPthreadCondServer();
00103         virtual ~JackPthreadCondServer();
00104 
00105         bool Allocate(const char* name, int value);
00106         void Destroy();
00107 };
00108 
00109 class JackPthreadCondClient : public JackPthreadCond
00110 {
00111 
00112     private:
00113 
00114         static JackShmReadWritePtr1<JackPthreadCondArray> fTable;
00115         static long fCount;
00116 
00117     protected:
00118 
00119         JackPthreadCondArray* GetTable()
00120         {
00121             return fTable;
00122         }
00123 
00124     public:
00125 
00126         JackPthreadCondClient(int shared_index);
00127         virtual ~JackPthreadCondClient();
00128 };
00129 
00130 } // end of namespace
00131 
00132 #endif
00133 

Generated on Wed Jan 10 11:42:46 2007 for Jackdmp by  doxygen 1.4.5