From 5591f1602e6171492f5e4620e67d3addeacad7aa Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Tue, 20 Sep 2011 16:08:52 +0200 Subject: VSTi plugin version. --- src/mutex.cc | 48 +++++++++++++++++++++++++++++++++++++++--------- src/mutex.h | 4 ++-- src/path.cc | 14 +++++++++++++- 3 files changed, 54 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/mutex.cc b/src/mutex.cc index ec0d0e8..22d59a6 100644 --- a/src/mutex.cc +++ b/src/mutex.cc @@ -27,32 +27,62 @@ */ #include "mutex.h" +#ifdef WIN32 +#include +#else +#include +#endif + +struct mutex_private_t { +#ifdef WIN32 + HANDLE mutex; +#else + pthread_mutex_t mutex; +#endif +}; + Mutex::Mutex() { - pthread_mutex_init (&mutex, NULL); + prv = new struct mutex_private_t(); +#ifdef WIN32 + prv->mutex = CreateMutex(NULL, // default security attributes + FALSE, // initially not owned + NULL); // unnamed mutex +#else + pthread_mutex_init (&prv->mutex, NULL); +#endif } Mutex::~Mutex() { - pthread_mutex_destroy(&mutex); -} +#ifdef WIN32 + CloseHandle(prv->mutex); +#else + pthread_mutex_destroy(&prv->mutex); +#endif -bool Mutex::trylock() -{ - return pthread_mutex_trylock(&mutex) == 0; + if(prv) delete prv; } void Mutex::lock() { - pthread_mutex_lock(&mutex); +#ifdef WIN32 + WaitForSingleObject(prv->mutex, // handle to mutex + INFINITE); // no time-out interval +#else + pthread_mutex_lock(&prv->mutex); +#endif } void Mutex::unlock() { - pthread_mutex_unlock(&mutex); +#ifdef WIN32 + ReleaseMutex(prv->mutex); +#else + pthread_mutex_unlock(&prv->mutex); +#endif } - MutexAutolock::MutexAutolock(Mutex &m) : mutex(m) { diff --git a/src/mutex.h b/src/mutex.h index cf052ad..11704d4 100644 --- a/src/mutex.h +++ b/src/mutex.h @@ -28,7 +28,7 @@ #ifndef __PRACRO_MUTEX_H__ #define __PRACRO_MUTEX_H__ -#include +struct mutex_private_t; class Mutex { public: @@ -40,7 +40,7 @@ public: void unlock(); private: - pthread_mutex_t mutex; + struct mutex_private_t* prv; }; class MutexAutolock { diff --git a/src/path.cc b/src/path.cc index 3812b87..8be2f26 100644 --- a/src/path.cc +++ b/src/path.cc @@ -26,15 +26,27 @@ */ #include "path.h" +#ifndef WIN32 #include +#endif + #include #include std::string getPath(std::string file) { + std::string p; +#ifndef WIN32 char *b = strdup(file.c_str()); - std::string p = dirname(b); + p = dirname(b); free(b); +#else + char drive[_MAX_DRIVE]; + char dir[_MAX_DIR]; + _splitpath(file.c_str(), drive, dir, NULL, NULL); + p = std::string(drive) + dir; +#endif + return p; } -- cgit v1.2.3