summaryrefslogtreecommitdiff
path: root/locks/os2
diff options
context:
space:
mode:
authorBrian Havard <bjh@apache.org>2001-09-12 14:25:05 +0000
committerBrian Havard <bjh@apache.org>2001-09-12 14:25:05 +0000
commitc9b747e5c6ae21a36ed5cca0fc66b9c1ef1a95b4 (patch)
treea81cd595e18b81ac1aec7c9f03ead0323e1fee28 /locks/os2
parent438be872f37586b74e22f670618462d9f2323759 (diff)
downloadapr-c9b747e5c6ae21a36ed5cca0fc66b9c1ef1a95b4.tar.gz
OS/2: Implement apr_thread_mutex functions.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@62315 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'locks/os2')
-rw-r--r--locks/os2/thread_mutex.c57
1 files changed, 51 insertions, 6 deletions
diff --git a/locks/os2/thread_mutex.c b/locks/os2/thread_mutex.c
index d47e3be12..4464ec1a8 100644
--- a/locks/os2/thread_mutex.c
+++ b/locks/os2/thread_mutex.c
@@ -59,30 +59,75 @@
#include "thread_mutex.h"
#include "fileio.h"
#include <string.h>
+#include <stddef.h>
+
+static apr_status_t thread_mutex_cleanup(void *themutex)
+{
+ apr_thread_mutex_t *mutex = themutex;
+ return apr_thread_mutex_destroy(mutex);
+}
+
+
APR_DECLARE(apr_status_t) apr_thread_mutex_create(apr_thread_mutex_t **mutex,
apr_pool_t *pool)
{
- return APR_ENOTIMPL;
+ apr_thread_mutex_t *new_mutex;
+ ULONG rc;
+
+ new_mutex = (apr_thread_mutex_t *)apr_palloc(pool, sizeof(apr_thread_mutex_t));
+ new_mutex->pool = pool;
+
+ rc = DosCreateMutexSem(NULL, &(new_mutex->hMutex), 0, FALSE);
+ *mutex = new_mutex;
+
+ if (!rc)
+ apr_pool_cleanup_register(pool, new_mutex, thread_mutex_cleanup, apr_pool_cleanup_null);
+
+ return APR_OS2_STATUS(rc);
}
+
+
APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
{
- return APR_ENOTIMPL;
+ ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_INDEFINITE_WAIT);
+ return APR_OS2_STATUS(rc);
}
+
+
APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
{
- return APR_ENOTIMPL;
+ ULONG rc = DosRequestMutexSem(mutex->hMutex, SEM_IMMEDIATE_RETURN);
+ return APR_OS2_STATUS(rc);
}
+
+
APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
{
- return APR_ENOTIMPL;
+ ULONG rc = DosReleaseMutexSem(mutex->hMutex);
+ return APR_OS2_STATUS(rc);
}
+
+
APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
{
- return APR_ENOTIMPL;
-}
+ ULONG rc;
+ if (mutex->hMutex == 0)
+ return APR_SUCCESS;
+
+ while (DosReleaseMutexSem(mutex->hMutex) == 0);
+
+ rc = DosCloseMutexSem(mutex->hMutex);
+
+ if (!rc) {
+ mutex->hMutex = 0;
+ return APR_SUCCESS;
+ }
+
+ return APR_FROM_OS_ERROR(rc);
+}