summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2011-09-20 16:08:52 +0200
committerBent Bisballe Nyeng <deva@aasimon.org>2011-09-20 16:08:52 +0200
commit5591f1602e6171492f5e4620e67d3addeacad7aa (patch)
treea51c16d5760cd7db9b1fbbf5bf3afeb9bae4ab18 /src
parent6611e83df0ed5b9bed42ff8cd549da0b5df11df2 (diff)
VSTi plugin version.
Diffstat (limited to 'src')
-rw-r--r--src/mutex.cc48
-rw-r--r--src/mutex.h4
-rw-r--r--src/path.cc14
3 files changed, 54 insertions, 12 deletions
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 <windows.h>
+#else
+#include <pthread.h>
+#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 <pthread.h>
+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 <libgen.h>
+#endif
+
#include <string.h>
#include <stdlib.h>
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;
}