Browse Source

Various cleanup

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@1737 0c269be4-1314-0410-8aa9-9f06e86f4224
tags/0.69
sletz 17 years ago
parent
commit
ab5e0faa6d
4 changed files with 0 additions and 356 deletions
  1. +0
    -208
      common/JackPthreadCond.cpp
  2. +0
    -131
      common/JackPthreadCond.h
  3. +0
    -14
      common/Jackdmp.cpp
  4. +0
    -3
      common/SConscript

+ 0
- 208
common/JackPthreadCond.cpp View File

@@ -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<JackPthreadCondArray> 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


+ 0
- 131
common/JackPthreadCond.h View File

@@ -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 <pthread.h>
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
#include <assert.h>

#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<JackPthreadCondArray> fTable;
static long fCount;

protected:

JackPthreadCondArray* GetTable()
{
return fTable;
}

public:

JackPthreadCondClient(int shared_index);
virtual ~JackPthreadCondClient();
};

} // end of namespace

#endif


+ 0
- 14
common/Jackdmp.cpp View File

@@ -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.



+ 0
- 3
common/SConscript View File

@@ -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 \


Loading…
Cancel
Save