[Freeswitch-svn] [commit] r4409 - in freeswitch/trunk/libs/iax: . src
Freeswitch SVN
mikej at freeswitch.org
Tue Feb 27 19:28:24 EST 2007
Author: mikej
Date: Tue Feb 27 19:28:23 2007
New Revision: 4409
Added:
freeswitch/trunk/libs/iax/src/iax-mutex.c
freeswitch/trunk/libs/iax/src/iax-mutex.h
Modified:
freeswitch/trunk/libs/iax/libiax2.vcproj
freeswitch/trunk/libs/iax/src/Makefile.am
Log:
add cross platform mutex abstraction.
Modified: freeswitch/trunk/libs/iax/libiax2.vcproj
==============================================================================
--- freeswitch/trunk/libs/iax/libiax2.vcproj (original)
+++ freeswitch/trunk/libs/iax/libiax2.vcproj Tue Feb 27 19:28:23 2007
@@ -148,6 +148,10 @@
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File
+ RelativePath=".\src\iax-mutex.c"
+ >
+ </File>
+ <File
RelativePath=".\src\iax.c"
>
</File>
@@ -190,6 +194,10 @@
>
</File>
<File
+ RelativePath=".\src\iax-mutex.h"
+ >
+ </File>
+ <File
RelativePath=".\src\iax.h"
>
</File>
Modified: freeswitch/trunk/libs/iax/src/Makefile.am
==============================================================================
--- freeswitch/trunk/libs/iax/src/Makefile.am (original)
+++ freeswitch/trunk/libs/iax/src/Makefile.am Tue Feb 27 19:28:23 2007
@@ -8,8 +8,8 @@
pkgdir = $(libdir)
pkg_LTLIBRARIES=libiax.la
-libiax_la_SOURCES = iax2-parser.c iax.c md5.c jitterbuf.c
+libiax_la_SOURCES = iax2-parser.c iax.c md5.c jitterbuf.c iax-mutex.c
library_includedir = $(prefix)/include/iax
-library_include_HEADERS = md5.h frame.h iax-client.h iax2.h iax2-parser.h iax.h
+library_include_HEADERS = md5.h frame.h iax-client.h iax2.h iax2-parser.h iax.h iax-mutex.h
noinst_HEADERS = jitterbuf.h
Added: freeswitch/trunk/libs/iax/src/iax-mutex.c
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/iax/src/iax-mutex.c Tue Feb 27 19:28:23 2007
@@ -0,0 +1,105 @@
+/*
+ * Simple Mutex abstraction
+ * Copyright(C) 2007 Michael Jerris
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so.
+ *
+ * This work is provided under this license on an "as is" basis, without warranty of any kind,
+ * either expressed or implied, including, without limitation, warranties that the covered code
+ * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
+ * risk as to the quality and performance of the covered code is with you. Should any covered
+ * code prove defective in any respect, you (not the initial developer or any other contributor)
+ * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
+ * constitutes an essential part of this license. No use of any covered code is authorized hereunder
+ * except under this disclaimer.
+ *
+ */
+
+
+#include "iax-mutex.h"
+
+
+#ifdef WIN32
+#define _WIN32_WINNT 0x0400
+#include <windows.h>
+struct mutex {
+ CRITICAL_SECTION mutex;
+};
+
+#else
+
+#include <pthread.h>
+struct mutex {
+ pthread_mutex_t mutex;
+};
+
+#endif
+
+
+mutex_status_t mutex_create(mutex_t **mutex)
+{
+ mutex_t *check = NULL;
+
+ check = (mutex_t *)malloc(sizeof(**mutex));
+ if (!check)
+ return MUTEX_FAILURE;
+#ifdef WIN32
+ InitializeCriticalSection(&check->mutex);
+#else
+ if (pthread_mutex_init(&check->mutex, NULL))
+ return MUTEX_FAILURE;
+
+#endif
+
+ *mutex = check;
+
+ return MUTEX_SUCCESS;
+}
+
+mutex_status_t mutex_destroy(mutex_t *mutex)
+{
+#ifdef WIN32
+ DeleteCriticalSection(&mutex->mutex);
+#else
+ if (pthread_mutex_destroy(&mutex->mutex))
+ return MUTEX_FAILURE;
+#endif
+ free(mutex);
+ return MUTEX_SUCCESS;
+}
+
+mutex_status_t mutex_lock(mutex_t *mutex)
+{
+#ifdef WIN32
+ EnterCriticalSection(&mutex->mutex);
+#else
+ if (pthread_mutex_lock(&mutex->mutex))
+ return MUTEX_FAILURE;
+#endif
+ return MUTEX_SUCCESS;
+}
+
+mutex_status_t mutex_trylock(mutex_t *mutex)
+{
+#ifdef WIN32
+ if (!TryEnterCriticalSection(&mutex->mutex))
+ return MUTEX_FAILURE;
+#else
+ if (pthread_mutex_trylock(&mutex->mutex))
+ return MUTEX_FAILURE;
+#endif
+ return MUTEX_SUCCESS;
+}
+
+mutex_status_t mutex_unlock(mutex_t *mutex)
+{
+#ifdef WIN32
+ LeaveCriticalSection(&mutex->mutex);
+#else
+ if (pthread_mutex_unlock(&mutex->mutex))
+ return MUTEX_FAILURE;
+#endif
+ return MUTEX_SUCCESS;
+}
Added: freeswitch/trunk/libs/iax/src/iax-mutex.h
==============================================================================
--- (empty file)
+++ freeswitch/trunk/libs/iax/src/iax-mutex.h Tue Feb 27 19:28:23 2007
@@ -0,0 +1,37 @@
+/*
+ * Simple Mutex abstraction
+ * Copyright(C) 2007 Michael Jerris
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so.
+ *
+ * This work is provided under this license on an "as is" basis, without warranty of any kind,
+ * either expressed or implied, including, without limitation, warranties that the covered code
+ * is free of defects, merchantable, fit for a particular purpose or non-infringing. The entire
+ * risk as to the quality and performance of the covered code is with you. Should any covered
+ * code prove defective in any respect, you (not the initial developer or any other contributor)
+ * assume the cost of any necessary servicing, repair or correction. This disclaimer of warranty
+ * constitutes an essential part of this license. No use of any covered code is authorized hereunder
+ * except under this disclaimer.
+ *
+ */
+
+
+#ifndef _SIMPLE_ABSTRACT_MUTEX_H
+#define _SIMPLE_ABSTRACT_MUTEX_H
+
+typedef struct mutex mutex_t;
+
+typedef enum mutex_status {
+ MUTEX_SUCCESS,
+ MUTEX_FAILURE
+} mutex_status_t;
+
+mutex_status_t mutex_create(mutex_t **mutex);
+mutex_status_t mutex_destroy(mutex_t *mutex);
+mutex_status_t mutex_lock(mutex_t *mutex);
+mutex_status_t mutex_trylock(mutex_t *mutex);
+mutex_status_t mutex_unlock(mutex_t *mutex);
+
+#endif
More information about the Freeswitch-svn
mailing list