Browse Source

Code moved in cpp files.

tags/1.9.9.5
Stephane Letz 13 years ago
parent
commit
ad0963cfc3
3 changed files with 37 additions and 31 deletions
  1. +31
    -0
      posix/JackPosixMutex.cpp
  2. +4
    -29
      posix/JackPosixMutex.h
  3. +2
    -2
      windows/JackWinProcessSync.h

+ 31
- 0
posix/JackPosixMutex.cpp View File

@@ -25,6 +25,18 @@
namespace Jack
{

JackBasePosixMutex::JackBasePosixMutex(const char* name)
:fOwner(0)
{
int res = pthread_mutex_init(&fMutex, NULL);
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex"));
}

JackBasePosixMutex::~JackBasePosixMutex()
{
pthread_mutex_destroy(&fMutex);
}

bool JackBasePosixMutex::Lock()
{
pthread_t current_thread = pthread_self();
@@ -79,6 +91,25 @@ namespace Jack
}
}

JackPosixMutex::JackPosixMutex(const char* name)
{
// Use recursive mutex
pthread_mutexattr_t mutex_attr;
int res;
res = pthread_mutexattr_init(&mutex_attr);
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex attribute"));
res = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not settype the mutex"));
res = pthread_mutex_init(&fMutex, &mutex_attr);
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex"));
pthread_mutexattr_destroy(&mutex_attr);
}

JackPosixMutex::~JackPosixMutex()
{
pthread_mutex_destroy(&fMutex);
}

bool JackPosixMutex::Lock()
{
int res = pthread_mutex_lock(&fMutex);


+ 4
- 29
posix/JackPosixMutex.h View File

@@ -45,16 +45,8 @@ class SERVER_EXPORT JackBasePosixMutex

public:

JackBasePosixMutex(const char* name = NULL):fOwner(0)
{
int res = pthread_mutex_init(&fMutex, NULL);
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex"));
}

virtual ~JackBasePosixMutex()
{
pthread_mutex_destroy(&fMutex);
}
JackBasePosixMutex(const char* name = NULL);
virtual ~JackBasePosixMutex();

bool Lock();
bool Trylock();
@@ -70,31 +62,14 @@ class SERVER_EXPORT JackPosixMutex

public:

JackPosixMutex(const char* name = NULL)
{
// Use recursive mutex
pthread_mutexattr_t mutex_attr;
int res;
res = pthread_mutexattr_init(&mutex_attr);
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex attribute"));
res = pthread_mutexattr_settype(&mutex_attr, PTHREAD_MUTEX_RECURSIVE);
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not settype the mutex"));
res = pthread_mutex_init(&fMutex, &mutex_attr);
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the mutex"));
pthread_mutexattr_destroy(&mutex_attr);
}

virtual ~JackPosixMutex()
{
pthread_mutex_destroy(&fMutex);
}
JackPosixMutex(const char* name = NULL);
virtual ~JackPosixMutex();

bool Lock();
bool Trylock();
bool Unlock();
};


} // namespace

#endif

+ 2
- 2
windows/JackWinProcessSync.h View File

@@ -90,12 +90,12 @@ class JackWinCondVar {
DeleteCriticalSection(&fMutex);
}
bool TimedWait(long usec);
bool TimedWait(long usec)
{
return SleepConditionVariableCS(&fCondVar, &fMutex, usec / 1000);
}
bool LockedTimedWait(long usec);
bool LockedTimedWait(long usec)
{
EnterCriticalSection(&fMutex);
return SleepConditionVariableCS(&fCondVar, &fMutex, usec / 1000);


Loading…
Cancel
Save