[libbluray-devel] commit: Added wrapper for pthread mutexes. (hpi1 )

git at videolan.org git at videolan.org
Mon Aug 23 21:06:39 CEST 2010


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Aug 23 21:40:33 2010 +0300| [3b666d445a7fee972a10f02dd9bffc9394188d00] | committer: hpi1 

Added wrapper for pthread mutexes.
Added support for WIN32 critical sections.
--> no need for pthread when building for Windows.

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=3b666d445a7fee972a10f02dd9bffc9394188d00
---

 src/libbluray/register.c |    2 +-
 src/util/mutex.h         |   59 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 1 deletions(-)

diff --git a/src/libbluray/register.c b/src/libbluray/register.c
index cbfb200..52d979c 100644
--- a/src/libbluray/register.c
+++ b/src/libbluray/register.c
@@ -21,10 +21,10 @@
 #include "util/attributes.h"
 #include "util/macro.h"
 #include "util/logging.h"
+#include "util/mutex.h"
 
 #include <stdlib.h>
 #include <string.h>
-#include <pthread.h>
 
 #define BD_PSR_COUNT 128
 #define BD_GPR_COUNT 4096
diff --git a/src/util/mutex.h b/src/util/mutex.h
new file mode 100644
index 0000000..0138f46
--- /dev/null
+++ b/src/util/mutex.h
@@ -0,0 +1,59 @@
+/*
+ * This file is part of libbluray
+ * Copyright (C) 2010  hpi1
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef LIBBLURAY_MUTEX_H_
+#define LIBBLURAY_MUTEX_H_
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#if defined(HAVE_PTHREAD_H)
+#   include <pthread.h>
+#elif defined(_WIN32)
+#   include <windows.h>
+#else
+#   error no mutex support found
+#endif
+
+#if defined(_WIN32) && !defined(HAVE_PTHREAD_H)
+
+#include <errno.h>
+
+typedef CRITICAL_SECTION pthread_mutex_t;
+
+#define pthread_mutex_lock(m) \
+  (EnterCriticalSection(m), 0)
+
+#define pthread_mutex_unlock(m) \
+  (LeaveCriticalSection(m), 0)
+
+#define pthread_mutex_trylock(m) \
+  (TryEnterCriticalSection(m) ? 0 : EBUSY)
+
+#define pthread_mutex_init(m, a) \
+  (InitializeCriticalSection(m), 0)
+
+#define pthread_mutex_destroy(m) \
+  (DeleteCriticalSection(m), 0)
+
+#endif
+
+
+#endif // LIBBLURAY_MUTEX_H_



More information about the libbluray-devel mailing list