You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by bj...@apache.org on 2001/09/12 16:25:05 UTC

cvs commit: apr/locks/os2 thread_mutex.c

bjh         01/09/12 07:25:05

  Modified:    include/arch/os2 thread_mutex.h
               locks/os2 thread_mutex.c
  Log:
  OS/2: Implement apr_thread_mutex functions.
  
  Revision  Changes    Path
  1.2       +1 -0      apr/include/arch/os2/thread_mutex.h
  
  Index: thread_mutex.h
  ===================================================================
  RCS file: /home/cvs/apr/include/arch/os2/thread_mutex.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- thread_mutex.h	2001/09/04 23:28:50	1.1
  +++ thread_mutex.h	2001/09/12 14:25:05	1.2
  @@ -60,6 +60,7 @@
   
   struct apr_thread_mutex_t {
       apr_pool_t *pool;
  +    HMTX hMutex;
   };
   
   #endif  /* THREAD_MUTEX_H */
  
  
  
  1.2       +51 -6     apr/locks/os2/thread_mutex.c
  
  Index: thread_mutex.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/os2/thread_mutex.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- thread_mutex.c	2001/09/04 23:28:51	1.1
  +++ thread_mutex.c	2001/09/12 14:25:05	1.2
  @@ -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);
  +}