MVP/Windows convergence
authorMark Calderbank <mark@vomp.tv>
Fri, 23 Jun 2006 23:55:10 +0000 (23:55 +0000)
committerMark Calderbank <mark@vomp.tv>
Fri, 23 Jun 2006 23:55:10 +0000 (23:55 +0000)
mutex.cc [new file with mode: 0644]
mutex.h [new file with mode: 0644]

diff --git a/mutex.cc b/mutex.cc
new file mode 100644 (file)
index 0000000..1017180
--- /dev/null
+++ b/mutex.cc
@@ -0,0 +1,51 @@
+/*\r
+    Copyright 2004-2005 Chris Tallon\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+*/\r
+#include "mutex.h"\r
+\r
+Mutex::Mutex() {\r
+#ifndef WIN32\r
+       pthread_mutex_init(&my_mutex, NULL);\r
+#else\r
+        my_mutex=CreateMutex(NULL,FALSE,NULL);\r
+#endif\r
+}\r
+\r
+Mutex::~Mutex() {\r
+#ifdef WIN32\r
+  CloseHandle(my_mutex);\r
+#endif\r
+}\r
+\r
+void Mutex::Lock() {\r
+#ifndef WIN32\r
+  pthread_mutex_lock(&my_mutex);\r
+#else\r
+   WaitForSingleObject(my_mutex, INFINITE );\r
+#endif\r
+}\r
+\r
+void Mutex::Unlock() {\r
+#ifndef WIN32\r
+  pthread_mutex_unlock(&my_mutex);\r
+#else\r
+   ReleaseMutex(my_mutex);\r
+#endif\r
+}\r
+\r
diff --git a/mutex.h b/mutex.h
new file mode 100644 (file)
index 0000000..d989da8
--- /dev/null
+++ b/mutex.h
@@ -0,0 +1,47 @@
+/*\r
+    Copyright 2004-2005 Chris Tallon\r
+\r
+    This file is part of VOMP.\r
+\r
+    VOMP is free software; you can redistribute it and/or modify\r
+    it under the terms of the GNU General Public License as published by\r
+    the Free Software Foundation; either version 2 of the License, or\r
+    (at your option) any later version.\r
+\r
+    VOMP is distributed in the hope that it will be useful,\r
+    but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+    GNU General Public License for more details.\r
+\r
+    You should have received a copy of the GNU General Public License\r
+    along with VOMP; if not, write to the Free Software\r
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+*/\r
+\r
+#ifndef MUTEX_H\r
+#define MUTEX_H\r
+\r
+#ifndef WIN32\r
+#include <pthread.h>\r
+#else\r
+#include <winsock2.h>\r
+#include <windows.h>\r
+#endif\r
+\r
+\r
+\r
+class Mutex\r
+{\r
+public:\r
+       Mutex();\r
+       ~Mutex();\r
+       void Lock();\r
+       void Unlock();\r
+protected:\r
+#ifndef WIN32\r
+        pthread_mutex_t my_mutex;\r
+#else\r
+       HANDLE my_mutex;\r
+#endif\r
+};\r
+#endif\r