diff --git a/common/JackPthreadCond.cpp b/common/JackPthreadCond.cpp deleted file mode 100644 index a5e90837..00000000 --- a/common/JackPthreadCond.cpp +++ /dev/null @@ -1,208 +0,0 @@ -/* -Copyright (C) 2004-2005 Grame - -This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#include "JackPthreadCond.h" -#include "JackConstants.h" -#include "JackError.h" - -namespace Jack -{ - -JackPthreadCondArray* JackPthreadCondServer::fTable = NULL; -long JackPthreadCondServer::fCount = 0; - -JackShmReadWritePtr1 JackPthreadCondClient::fTable; -long JackPthreadCondClient::fCount = 0; - -JackPthreadCondArray::JackPthreadCondArray() -{ - for (int i = 0; i < MAX_ITEM; i++) { - strcpy(fTable[i].fName, ""); - } -} - -void JackPthreadCond::BuildName(const char* name, char* res) -{ - sprintf(res, "%s/jack_sem.%s", jack_client_dir, name); -} - -bool JackPthreadCond::Signal() -{ - //pthread_mutex_lock(&fSynchro->fLock); - //JackLog("JackPthreadCond::Signal...\n"); - pthread_cond_signal(&fSynchro->fCond); - //pthread_mutex_unlock(&fSynchro->fLock); - return true; -} - -bool JackPthreadCond::SignalAll() -{ - pthread_cond_broadcast(&fSynchro->fCond); - return true; -} - -bool JackPthreadCond::Wait() -{ - pthread_mutex_lock(&fSynchro->fLock); - //JackLog("JackPthreadCond::Wait...\n"); - pthread_cond_wait(&fSynchro->fCond, &fSynchro->fLock); - pthread_mutex_unlock(&fSynchro->fLock); - //JackLog("JackProcessSync::Wait finished\n"); - return true; -} - -bool JackPthreadCond::TimedWait(long usec) -{ - timespec time; - struct timeval now; - gettimeofday(&now, 0); - time.tv_sec = now.tv_sec + usec / 1000000; - time.tv_nsec = (now.tv_usec + (usec % 1000000)) * 1000; - pthread_mutex_lock(&fSynchro->fLock); - JackLog("JackProcessSync::Wait...\n"); - pthread_cond_timedwait(&fSynchro->fCond, &fSynchro->fLock, &time); - pthread_mutex_unlock(&fSynchro->fLock); - JackLog("JackProcessSync::Wait finished\n"); - return true; -} - -// Client side : get the published semaphore from server -bool JackPthreadCond::ConnectInput(const char* name) -{ - BuildName(name, fName); - JackLog("JackPthreadCond::Connect %s\n", fName); - - // Temporary... - if (fSynchro) { - JackLog("Already connected name = %s\n", name); - return true; - } - - for (int i = 0; i < MAX_ITEM; i++) { - JackPthreadCondItem* synchro = &(GetTable()->fTable[i]); - if (strcmp(fName, synchro->fName) == 0) { - fSynchro = synchro; - return true; - } - } - - return false; -} - -bool JackPthreadCond::Connect(const char* name) -{ - return ConnectInput(name); -} - -bool JackPthreadCond::ConnectOutput(const char* name) -{ - return ConnectInput(name); -} - -bool JackPthreadCond::Disconnect() -{ - JackLog("JackPthreadCond::Disconnect %s\n", fName); - - if (fSynchro) { - strcpy(fSynchro->fName, ""); - fSynchro = NULL; - return true; - } else { - return false; - } -} - -JackPthreadCondServer::JackPthreadCondServer(): JackPthreadCond() -{ - if (fCount++ == 0 && !fTable) { - fTable = new JackPthreadCondArray(); - } - if (fCount == MAX_ITEM) - throw new std::bad_alloc; -} - -JackPthreadCondServer::~JackPthreadCondServer() -{ - if (--fCount == 0 && fTable) { - delete fTable; - fTable = NULL; - } -} - -bool JackPthreadCondServer::Allocate(const char* name, int value) -{ - BuildName(name, fName); - JackLog("JackPthreadCond::Allocate name = %s val = %ld\n", fName, value); - - pthread_mutexattr_t mutex_attr; - pthread_mutexattr_setpshared(&mutex_attr, PTHREAD_PROCESS_SHARED); - pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_NORMAL); - - pthread_condattr_t cond_attr; - pthread_condattr_init(&cond_attr); - pthread_condattr_setpshared(&cond_attr, PTHREAD_PROCESS_SHARED); - - for (int i = 0; i < MAX_ITEM; i++) { - if (strcmp(fTable->fTable[i].fName, "") == 0) { // first empty place - fSynchro = &fTable->fTable[i]; - if (pthread_mutex_init(&fSynchro->fLock, &mutex_attr) != 0) { - jack_error("Allocate: can't check in named semaphore name = %s err = %s", fName, strerror(errno)); - return false; - } - if (pthread_cond_init(&fSynchro->fCond, &cond_attr) != 0) { - jack_error("Allocate: can't check in named semaphore name = %s err = %s", fName, strerror(errno)); - return false; - } - strcpy(fSynchro->fName, fName); - return true; - } - } - - return false; -} - -void JackPthreadCondServer::Destroy() -{ - if (fSynchro != NULL) { - pthread_mutex_destroy(&fSynchro->fLock); - pthread_cond_destroy(&fSynchro->fCond); - strcpy(fSynchro->fName, ""); - fSynchro = NULL; - } else { - jack_error("JackPthreadCond::Destroy semaphore == NULL"); - } -} - -JackPthreadCondClient::JackPthreadCondClient(int shared_index): JackPthreadCond() -{ - if (fCount++ == 0 && !fTable) { - fTable = shared_index; - } - if (fCount == MAX_ITEM) - throw new std::bad_alloc; -} - -JackPthreadCondClient::~JackPthreadCondClient() -{ - if (--fCount == 0 && fTable) - delete fTable; -} - -} // end of namespace - diff --git a/common/JackPthreadCond.h b/common/JackPthreadCond.h deleted file mode 100644 index a11f6d68..00000000 --- a/common/JackPthreadCond.h +++ /dev/null @@ -1,131 +0,0 @@ -/* -Copyright (C) 2004-2005 Grame - -This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -*/ - -#ifndef __JackPthreadCond__ -#define __JackPthreadCond__ - -#include "JackSynchro.h" -#include "JackShmMem.h" -#include -#include -#include -#include -#include - -#define MAX_ITEM 8 - -namespace Jack -{ - -struct JackPthreadCondItem -{ - char fName[SYNC_MAX_NAME_SIZE]; - pthread_mutex_t fLock; - pthread_cond_t fCond; -}; - -struct JackPthreadCondArray : public JackShmMem -{ - JackPthreadCondItem fTable[MAX_ITEM]; - - JackPthreadCondArray(); - virtual ~JackPthreadCondArray() - {} -}; - -/*! -\brief Inter process synchronization using pthread condition variables. -*/ - -class JackPthreadCond : public JackSynchro -{ - - protected: - - JackPthreadCondItem* fSynchro; - void BuildName(const char* name, char* res); - virtual JackPthreadCondArray* GetTable() = 0; - - public: - - JackPthreadCond(): fSynchro(NULL) - {} - virtual ~JackPthreadCond() - {} - - bool Signal(); - bool SignalAll(); - bool Wait(); - bool TimedWait(long usec); - - bool Connect(const char* name); - bool ConnectInput(const char* name); - bool ConnectOutput(const char* name); - bool Disconnect(); -}; - -class JackPthreadCondServer : public JackPthreadCond -{ - - private: - - static JackPthreadCondArray* fTable; - static long fCount; - - protected: - - JackPthreadCondArray* GetTable() - { - return fTable; - } - - public: - - JackPthreadCondServer(); - virtual ~JackPthreadCondServer(); - - bool Allocate(const char* name, int value); - void Destroy(); -}; - -class JackPthreadCondClient : public JackPthreadCond -{ - - private: - - static JackShmReadWritePtr1 fTable; - static long fCount; - - protected: - - JackPthreadCondArray* GetTable() - { - return fTable; - } - - public: - - JackPthreadCondClient(int shared_index); - virtual ~JackPthreadCondClient(); -}; - -} // end of namespace - -#endif - diff --git a/common/Jackdmp.cpp b/common/Jackdmp.cpp index 9383197c..70c9f873 100644 --- a/common/Jackdmp.cpp +++ b/common/Jackdmp.cpp @@ -370,20 +370,6 @@ int main(int argc, char* argv[]) CFRelease(ref); #endif - /* - For testing purpose... - InternalMetro* client1 = new InternalMetro(1200, 0.4, 20, 80, "metro1"); - InternalMetro* client2 = new InternalMetro(600, 0.4, 20, 150, "metro2"); - InternalMetro* client3 = new InternalMetro(1000, 0.4, 20, 110, "metro3"); - InternalMetro* client4 = new InternalMetro(1200, 0.4, 20, 80, "metro4"); - InternalMetro* client5 = new InternalMetro(1500, 0.4, 20, 60, "metro5"); - InternalMetro* client6 = new InternalMetro(1200, 0.4, 20, 84, "metro6"); - InternalMetro* client7 = new InternalMetro(600, 0.4, 20, 160, "metro7"); - InternalMetro* client8 = new InternalMetro(1000, 0.4, 20, 113, "metro8"); - InternalMetro* client9 = new InternalMetro(1200, 0.4, 20, 84, "metro9"); - InternalMetro* client10 = new InternalMetro(1500, 0.4, 20, 70, "metro10"); - */ - // install a do-nothing handler because otherwise pthreads // behaviour is undefined when we enter sigwait. diff --git a/common/SConscript b/common/SConscript index d96bb21b..c47cb145 100644 --- a/common/SConscript +++ b/common/SConscript @@ -44,9 +44,6 @@ srcfiles_common_serverlib = env.Split( '\ JackTransportEngine.cpp JackServerGlobals.cpp JackServerLaunch.cpp timestamps.c JackTools.cpp \ ') -# FIXME: this is not pretty -srcfiles_common_serverlib.append('#/example-clients/internal_metro.cpp') - srcfiles_common_clientlib = env.Split( '\ JackActivationCount.cpp JackAPI.cpp JackClient.cpp JackConnectionManager.cpp ringbuffer.c JackServerLaunch.cpp\ JackError.c JackFrameTimer.cpp JackGlobalsClient.cpp JackGraphManager.cpp JackLibClient.cpp JackLibAPI.cpp JackPort.cpp JackPosixSemaphore.cpp \