apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bnicho...@apache.org
Subject cvs commit: apr/locks/netware thread_rwlock.c thread_mutex.c thread_cond.c
Date Thu, 04 Oct 2001 21:01:05 GMT
bnicholes    01/10/04 14:01:05

  Modified:    locks/netware thread_rwlock.c thread_mutex.c thread_cond.c
  Log:
  Implementation of the new locking routines
  
  Revision  Changes    Path
  1.3       +48 -7     apr/locks/netware/thread_rwlock.c
  
  Index: thread_rwlock.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/netware/thread_rwlock.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- thread_rwlock.c	2001/09/29 05:04:44	1.2
  +++ thread_rwlock.c	2001/10/04 21:01:05	1.3
  @@ -59,40 +59,81 @@
   #include "thread_rwlock.h"
   #include "apr_portable.h"
   
  +static apr_status_t thread_rwlock_cleanup(void *data)
  +{
  +    apr_thread_rwlock_t *rwlock = (apr_thread_rwlock_t *)data;
  +
  +    NXRwLockFree (rwlock->rwlock);
  +    return APR_SUCCESS;
  +} 
  +
   APR_DECLARE(apr_status_t) apr_thread_rwlock_create(apr_thread_rwlock_t **rwlock,
                                                      apr_pool_t *pool)
   {
  -    return APR_ENOTIMPL;
  +    apr_thread_rwlock_t *new_rwlock = NULL;
  +   
  +	NXHierarchy_t hierarchy = 1;   //for libc NKS NXRwLockAlloc
  +	NXLockInfo_t *info;			   //for libc NKS NXRwLockAlloc
  +
  +    new_rwlock = (apr_thread_rwlock_t *)apr_pcalloc(pool, sizeof(apr_thread_rwlock_t));
  +	
  +	if(new_rwlock ==NULL) {
  +        return APR_ENOMEM;
  +    }     
  +    new_rwlock->pool = pool;
  +    
  +    info = (NXLockInfo_t *)apr_pcalloc(pool, sizeof(NXLockInfo_t));
  +    new_rwlock->rwlock = NXRwLockAlloc(hierarchy, info);
  +    if(new_rwlock->rwlock == NULL)
  +        return APR_ENOMEM;
  +
  +    apr_pool_cleanup_register(new_rwlock->pool, new_rwlock, thread_rwlock_cleanup,
  +                              apr_pool_cleanup_null);
  +    *rwlock = new_rwlock;
  +
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_rwlock_rdlock(apr_thread_rwlock_t *rwlock)
   {
  -    return APR_ENOTIMPL;
  +    NXRdLock(rwlock->rwlock);
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_rwlock_tryrdlock(apr_thread_rwlock_t *rwlock)
   {
  -    return APR_ENOTIMPL;
  +    if (!NXTryRdLock(rwlock->rwlock))
  +        return APR_EBUSY;
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_rwlock_wrlock(apr_thread_rwlock_t *rwlock)
   {
  -    return APR_ENOTIMPL;
  +    NXWrLock(rwlock->rwlock);
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_rwlock_trywrlock(apr_thread_rwlock_t *rwlock)
   {
  -    return APR_ENOTIMPL;
  +    if (!NXTryWrLock(rwlock->rwlock))
  +        return APR_EBUSY;
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_rwlock_unlock(apr_thread_rwlock_t *rwlock)
   {
  -    return APR_ENOTIMPL;
  +    NXRwUnlock(rwlock->rwlock);
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_rwlock_destroy(apr_thread_rwlock_t *rwlock)
   {
  -    return APR_ENOTIMPL;
  +    apr_status_t stat;
  +    if ((stat = thread_rwlock_cleanup(rwlock)) == APR_SUCCESS) {
  +        apr_pool_cleanup_kill(rwlock->pool, rwlock, thread_rwlock_cleanup);
  +        return APR_SUCCESS;
  +    }
  +    return stat;
   }
   
   APR_POOL_IMPLEMENT_ACCESSOR(thread_rwlock)
  
  
  
  1.3       +36 -6     apr/locks/netware/thread_mutex.c
  
  Index: thread_mutex.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/netware/thread_mutex.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- thread_mutex.c	2001/09/26 20:55:33	1.2
  +++ thread_mutex.c	2001/10/04 21:01:05	1.3
  @@ -61,33 +61,63 @@
   
   static apr_status_t thread_mutex_cleanup(void *data)
   {
  -    return APR_ENOTIMPL;
  +    apr_thread_mutex_t *mutex = (apr_thread_mutex_t *)data;
  +
  +    NXMutexFree(mutex->mutex);        
  +    return APR_SUCCESS;
   }
   
   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 = NULL;
  +
  +    new_mutex = (apr_thread_mutex_t *)apr_pcalloc(pool, sizeof(apr_thread_mutex_t));
  +	
  +	if(new_mutex ==NULL) {
  +        return APR_ENOMEM;
  +    }     
  +    new_mutex->pool = pool;
  +
  +    new_mutex->mutex = NXMutexAlloc(NX_MUTEX_RECURSIVE, NULL, NULL);
  +    
  +    if(new_mutex->mutex == NULL)
  +        return APR_ENOMEM;
  +
  +    apr_pool_cleanup_register(new_mutex->pool, new_mutex, 
  +                                (void*)thread_mutex_cleanup,
  +                                apr_pool_cleanup_null);
  +   *mutex = new_mutex;
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_mutex_lock(apr_thread_mutex_t *mutex)
   {
  -    return APR_ENOTIMPL;
  +    NXLock(mutex->mutex);
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_mutex_trylock(apr_thread_mutex_t *mutex)
   {
  -    return APR_ENOTIMPL;
  +    if (!NXTryLock(mutex->mutex))
  +        return APR_EBUSY;
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_mutex_unlock(apr_thread_mutex_t *mutex)
   {
  -    return APR_ENOTIMPL;
  +    NXUnlock(mutex->mutex);
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_mutex_destroy(apr_thread_mutex_t *mutex)
   {
  -    return APR_ENOTIMPL;
  +    apr_status_t stat;
  +    if ((stat = thread_mutex_cleanup(mutex)) == APR_SUCCESS) {
  +        apr_pool_cleanup_kill(mutex->pool, mutex, thread_mutex_cleanup);
  +        return APR_SUCCESS;
  +    }
  +    return stat;
   }
   
   APR_POOL_IMPLEMENT_ACCESSOR(thread_mutex)
  
  
  
  1.3       +40 -5     apr/locks/netware/thread_cond.c
  
  Index: thread_cond.c
  ===================================================================
  RCS file: /home/cvs/apr/locks/netware/thread_cond.c,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- thread_cond.c	2001/09/29 05:05:41	1.2
  +++ thread_cond.c	2001/10/04 21:01:05	1.3
  @@ -60,31 +60,66 @@
   #include "thread_cond.h"
   #include "apr_portable.h"
   
  +static apr_status_t thread_cond_cleanup(void *data)
  +{
  +    apr_thread_cond_t *cond = (apr_thread_cond_t *)data;
  +
  +    NXCondFree(cond->cond);        
  +    return APR_SUCCESS;
  +} 
  +
   APR_DECLARE(apr_status_t) apr_thread_cond_create(apr_thread_cond_t **cond,
                                                    apr_pool_t *pool)
   {
  -    return APR_ENOTIMPL;
  +    apr_thread_cond_t *new_cond = NULL;
  +
  +    new_cond = (apr_thread_cond_t *)apr_pcalloc(pool, sizeof(apr_thread_cond_t));
  +	
  +	if(new_cond ==NULL) {
  +        return APR_ENOMEM;
  +    }     
  +    new_cond->pool = pool;
  +
  +    new_cond->cond = NXCondAlloc(NULL);
  +    
  +    if(new_cond->cond == NULL)
  +        return APR_ENOMEM;
  +
  +    apr_pool_cleanup_register(new_cond->pool, new_cond, 
  +                                (void*)thread_cond_cleanup,
  +                                apr_pool_cleanup_null);
  +   *cond = new_cond;
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_cond_wait(apr_thread_cond_t *cond,
                                                  apr_thread_mutex_t *mutex)
   {
  -    return APR_ENOTIMPL;
  +    if (NXCondWait(cond->cond, mutex->mutex) != 0)
  +        return APR_EINTR;
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_cond_signal(apr_thread_cond_t *cond)
   {
  -    return APR_ENOTIMPL;
  +    NXCondSignal(cond->cond);
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_cond_broadcast(apr_thread_cond_t *cond)
   {
  -    return APR_ENOTIMPL;
  +    NXCondBroadcast(cond->cond);
  +    return APR_SUCCESS;
   }
   
   APR_DECLARE(apr_status_t) apr_thread_cond_destroy(apr_thread_cond_t *cond)
   {
  -    return APR_ENOTIMPL;
  +    apr_status_t stat;
  +    if ((stat = thread_cond_cleanup(cond)) == APR_SUCCESS) {
  +        apr_pool_cleanup_kill(cond->pool, cond, thread_cond_cleanup);
  +        return APR_SUCCESS;
  +    }
  +    return stat;
   }
   
   APR_POOL_IMPLEMENT_ACCESSOR(thread_cond)
  
  
  

Mime
View raw message