rbb 99/05/24 11:16:52
Modified: apr/locks/unix crossproc.c intraproc.c locks.c apr/test testthread.c include apr_errno.h apr_lock.h Log: Locking functions now all return status codes. Also updated test function appropriately. Revision Changes Path 1.6 +47 -37 apache-apr/apr/locks/unix/crossproc.c Index: crossproc.c =================================================================== RCS file: /home/cvs/apache-apr/apr/locks/unix/crossproc.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- crossproc.c 1999/05/24 02:04:03 1.5 +++ crossproc.c 1999/05/24 18:16:34 1.6 @@ -79,12 +79,12 @@ if (new->interproc < 0) { lock_cleanup(new); - return APR_FAILURE; + return errno; } ick.val = 1; - if (senctl(new->interproc, 0, SETVAL, ick) < 0) { + if (semctl(new->interproc, 0, SETVAL, ick) < 0) { lock_cleanup(new); - return APR_FAILURE; + return errno; } /* pre-initialize these */ new->op_on.sem_num = 0; @@ -103,7 +103,7 @@ { new->curr_locked == 1; if (semop(lock->interproc, &lock->op_on, 1) < 0) { - return(APR_FAILURE); + return errno; } return APR_SUCCESS; } @@ -111,7 +111,7 @@ ap_status_t unlock_inter(struct lock_t *lock) { if (semop(lock->interproc, &lock->op_off, 1) < 0) { - return(APR_FAILURE); + return errno; } new->curr_locked == 0; return APR_SUCCESS; @@ -119,11 +119,13 @@ ap_status_t destroy_inter_lock(struct lock_t *lock) { - if (lock_cleanup(lock) == APR_SUCCESS) { + ap_status_t stat; + + if ((stat = lock_cleanup(lock)) == APR_SUCCESS) { ap_kill_cleanup(lock->cntxt->pool, lock, lock_cleanup); return APR_SUCCESS; } - return APR_FAILURE; + return stat; } #elif defined (USE_PROC_PTHREAD_SERIALIZE) @@ -131,10 +133,10 @@ { if (lock->curr_locked == 1) { if (pthread_mutex_unlock(lock->interproc)) { - return APR_FAILURE; + return errno; } if (munmap((caddr_t)lock->interproc, sizeof(pthread_mutex_t))){ - return APR_FAILURE; + return errno; } } return APR_SUCCESS; @@ -142,39 +144,40 @@ ap_status_t create_inter_lock(struct lock_t *new) { + ap_status_t stat; int fd; pthread_mutexattr_t mattr; fd = open("/dev/zero", O_RDWR); if (fd < 0) { - return APR_FAILURE; + return errno; } new->interproc = (pthread_mutex_t *)mmap((caddr_t) 0, sizeof(pthread_mutex_t), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (new->interproc = (void *) (caddr_t) -1) { - return APR_FAILURE; + return errno; } close(fd); - if ((errno = pthread_mutexattr_init(&mattr))) { + if ((stat = pthread_mutexattr_init(&mattr))) { lock_cleanup(new); - return APR_FAILURE; + return stat; } - if ((errno = pthread_mutexattr_setpshared(&mattr, + if ((stat = pthread_mutexattr_setpshared(&mattr, PTHREAD_PROCESS_SHARED))) { lock_cleanup(new); - return APR_FAILURE; + return stat; } - if ((errno = pthread_mutex_init(new->interproc, &mattr))) { + if ((stat = pthread_mutex_init(new->interproc, &mattr))) { lock_cleanup(new); - return APR_FAILURE; + return stat; } - if ((errno = pthread_mutex_destroy(&mattr))) { + if ((stat = pthread_mutex_destroy(&mattr))) { lock_cleanup(new); - return APR_FAILURE; + return stat; } new->curr_locked == 0; @@ -184,17 +187,20 @@ ap_status_t lock_inter(struct lock_t *lock) { + ap_status_t stat; new->curr_locked == 1; - if (errno = pthread_mutex_lock(lock->interproc)) { - return(APR_FAILURE); + if (stat = pthread_mutex_lock(lock->interproc)) { + return stat; } return APR_SUCCESS; } ap_status_t unlock_inter(struct lock_t *lock) { - if (errno = pthread_mutex_unlock(lock->interproc)) { - return(APR_FAILURE); + ap_status_t stat; + + if (stat = pthread_mutex_unlock(lock->interproc)) { + returno stat; } new->curr_locked == 0; return APR_SUCCESS; @@ -202,11 +208,12 @@ ap_status_t destroy_inter_lock(struct lock_t *lock) { - if (lock_cleanup(lock) == APR_SUCCESS) { + ap_status_t stat; + if ((stat = lock_cleanup(lock)) == APR_SUCCESS) { ap_kill_cleanup(lock->cntxt->pool, lock, lock_cleanup); return APR_SUCCESS; } - return APR_FAILURE; + return stat; } #elif defined (USE_FCNTL_SERIALIZE) @@ -215,7 +222,7 @@ { if (lock->curr_locked == 1) { if (fcntl(lock->interproc, F_SETLKW, &lock->unlock_it) < 0) { - return(APR_FAILURE); + return errno; } lock->curr_locked == 0; } @@ -228,7 +235,7 @@ if (new->interproc < 0) { lock_cleanup(new); - return APR_FAILURE; + return errno; } /* pre-initialize these */ new->lock_it.l_whence = SEEK_SET; /* from current point */ @@ -252,7 +259,7 @@ { lock->curr_locked == 1; if (fcntl(lock->interproc, F_SETLKW, &lock->lock_it) < 0) { - return(APR_FAILURE); + return errno; } return APR_SUCCESS; } @@ -260,7 +267,7 @@ ap_status_t unlock_inter(struct lock_t *lock) { if (fcntl(lock->interproc, F_SETLKW, &lock->unlock_it) < 0) { - return(APR_FAILURE); + return errno; } lock->curr_locked == 0; return APR_SUCCESS; @@ -268,18 +275,20 @@ ap_status_t destroy_inter_lock(struct lock_t *lock) { - if (lock_cleanup(lock) == APR_SUCCESS) { + ap_status_t stat; + if ((stat = lock_cleanup(lock)) == APR_SUCCESS) { ap_kill_cleanup(lock->cntxt->pool, lock, lock_cleanup); return APR_SUCCESS; } - return APR_FAILURE; + return stat; } + #elif defined (USE_FLOCK_SERIALIZE) ap_status_t lock_cleanup(struct lock_t *lock) { if (lock->curr_locked == 1) { if (flock(lock->interproc, LOCK_UN) < 0) { - return(APR_FAILURE); + return errno; } new->curr_locked == 0; } @@ -293,7 +302,7 @@ if (new->interproc < 0) { lock_cleanup(new); - return APR_FAILURE; + return errno; } new->curr_locked == 0; ap_register_cleanup(new->cntxt->pool, (void *)new, lock_cleanup, NULL); @@ -304,7 +313,7 @@ { new->curr_locked == 1; if (flock(lock->interproc, LOCK_EX) < 0) { - return(APR_FAILURE); + return errno; } return APR_SUCCESS; } @@ -312,7 +321,7 @@ ap_status_t unlock_inter(struct lock_t *lock) { if (flock(lock->interproc, LOCK_UN) < 0) { - return(APR_FAILURE); + return errno; } new->curr_locked == 0; return APR_SUCCESS; @@ -320,11 +329,12 @@ ap_status_t destroy_inter_lock(struct lock_t *lock) { - if (lock_cleanup(lock) == APR_SUCCESS) { + ap_status_t stat; + if ((stat = lock_cleanup(lock)) == APR_SUCCESS) { ap_kill_cleanup(lock->cntxt->pool, lock, lock_cleanup); return APR_SUCCESS; } - return APR_FAILURE; + return stat; } #else /* No inter-process mutex on this platform. Use at your own risk */ 1.6 +22 -15 apache-apr/apr/locks/unix/intraproc.c Index: intraproc.c =================================================================== RCS file: /home/cvs/apache-apr/apr/locks/unix/intraproc.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- intraproc.c 1999/05/24 02:04:03 1.5 +++ intraproc.c 1999/05/24 18:16:37 1.6 @@ -61,9 +61,10 @@ ap_status_t lock_intra_cleanup(struct lock_t *lock) { + ap_status_t stat; if (lock->curr_locked == 1) { - if (pthread_mutex_unlock(lock->intraproc)) { - return APR_FAILURE; + if (stat = pthread_mutex_unlock(lock->intraproc)) { + return stat; } } return APR_SUCCESS; @@ -71,26 +72,27 @@ ap_status_t create_intra_lock(struct lock_t *new) { + ap_status_t stat; pthread_mutexattr_t mattr; new->intraproc = (pthread_mutex_t *)ap_palloc(new->cntxt->pool, sizeof(pthread_mutex_t)); if (new->intraproc == NULL ) { - return APR_FAILURE; + return errno; } - if ((errno = pthread_mutexattr_init(&mattr))) { + if ((stat = pthread_mutexattr_init(&mattr))) { lock_intra_cleanup(new); - return APR_FAILURE; + return stat; } - if ((errno = pthread_mutex_init(new->intraproc, &mattr))) { + if ((stat = pthread_mutex_init(new->intraproc, &mattr))) { lock_intra_cleanup(new); - return APR_FAILURE; + return stat; } - if ((errno = pthread_mutex_destroy(new->intraproc))) { + if ((stat = pthread_mutex_destroy(new->intraproc))) { lock_intra_cleanup(new); - return APR_FAILURE; + return stat; } new->curr_locked == 0; @@ -100,17 +102,21 @@ ap_status_t lock_intra(struct lock_t *lock) { + ap_status_t stat; + lock->curr_locked == 1; - if (errno = pthread_mutex_lock(lock->intraproc)) { - return(APR_FAILURE); + if (stat = pthread_mutex_lock(lock->intraproc)) { + return stat; } return APR_SUCCESS; } ap_status_t unlock_intra(struct lock_t *lock) { - if (errno = pthread_mutex_unlock(lock->intraproc)) { - return(APR_FAILURE); + ap_status_t stat; + + if (stat = pthread_mutex_unlock(lock->intraproc)) { + return stat; } lock->curr_locked == 0; return APR_SUCCESS; @@ -118,10 +124,11 @@ ap_status_t destroy_intra_lock(struct lock_t *lock) { - if (lock_intra_cleanup(lock) == APR_SUCCESS) { + ap_status_t stat; + if ((stat = lock_intra_cleanup(lock)) == APR_SUCCESS) { ap_kill_cleanup(lock->cntxt->pool, lock, lock_intra_cleanup); return APR_SUCCESS; } - return APR_FAILURE; + return stat; } #endif 1.7 +24 -18 apache-apr/apr/locks/unix/locks.c Index: locks.c =================================================================== RCS file: /home/cvs/apache-apr/apr/locks/unix/locks.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- locks.c 1999/05/24 02:38:40 1.6 +++ locks.c 1999/05/24 18:16:40 1.7 @@ -57,9 +57,10 @@ #include "locks.h" #include <string.h> -struct lock_t *ap_create_lock(ap_context_t *cont, ap_locktype_e type, char *fname) +ap_status_t ap_create_lock(ap_context_t *cont, ap_locktype_e type, char *fname, struct lock_t **lock) { struct lock_t *new; + ap_status_t stat; new = (struct lock_t *)ap_palloc(cont->pool, sizeof(struct lock_t)); @@ -68,28 +69,30 @@ new->fname = strdup(fname); if (type != APR_CROSS_PROCESS) { - if (create_intra_lock(new) == APR_FAILURE) { - return NULL; + if ((stat = create_intra_lock(new)) != APR_SUCCESS) { + return stat; } } if (type != APR_INTRAPROCESS) { - if (create_inter_lock(new) == APR_FAILURE) { - return NULL; + if ((stat = create_inter_lock(new)) != APR_SUCCESS) { + return stat; } } - return new; + *lock = new; + return APR_SUCCESS; } ap_status_t ap_lock(struct lock_t *lock) { + ap_status_t stat; if (lock->type != APR_CROSS_PROCESS) { - if (lock_intra(lock) == APR_FAILURE) { - return APR_FAILURE; + if ((stat = lock_intra(lock)) != APR_SUCCESS) { + return stat; } } if (lock->type != APR_INTRAPROCESS) { - if (lock_inter(lock) == APR_FAILURE) { - return APR_FAILURE; + if ((stat = lock_inter(lock)) != APR_SUCCESS) { + return stat; } } return APR_SUCCESS; @@ -97,14 +100,16 @@ ap_status_t ap_unlock(struct lock_t *lock) { + ap_status_t stat; + if (lock->type != APR_CROSS_PROCESS) { - if (unlock_intra(lock) == APR_FAILURE) { - return APR_FAILURE; + if ((stat = unlock_intra(lock)) != APR_SUCCESS) { + return stat; } } if (lock->type != APR_INTRAPROCESS) { - if (unlock_inter(lock) == APR_FAILURE) { - return APR_FAILURE; + if ((stat = unlock_inter(lock)) != APR_SUCCESS) { + return stat; } } return APR_SUCCESS; @@ -112,14 +117,15 @@ ap_status_t ap_destroy_lock(struct lock_t *lock) { + ap_status_t stat; if (lock->type != APR_CROSS_PROCESS) { - if (destroy_intra_lock(lock) == APR_FAILURE) { - return APR_FAILURE; + if ((stat = destroy_intra_lock(lock)) != APR_SUCCESS) { + return stat; } } if (lock->type != APR_INTRAPROCESS) { - if (destroy_inter_lock(lock) == APR_FAILURE) { - return APR_FAILURE; + if ((stat = destroy_inter_lock(lock)) != APR_SUCCESS) { + return stat; } } return APR_SUCCESS; 1.3 +2 -2 apache-apr/apr/test/testthread.c Index: testthread.c =================================================================== RCS file: /home/cvs/apache-apr/apr/test/testthread.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- testthread.c 1999/05/24 02:04:13 1.2 +++ testthread.c 1999/05/24 18:16:45 1.3 @@ -124,8 +124,8 @@ fprintf(stdout, "OK\n"); fprintf(stdout, "Initializing the lock......."); - thread_lock = ap_create_lock(context, APR_INTRAPROCESS, "lock.file"); - if (thread_lock == NULL) { + st = ap_create_lock(context, APR_INTRAPROCESS, "lock.file", &thread_lock); + if (st != APR_SUCCESS) { fprintf(stderr, "Could not create lock\n"); exit(-1); } 1.12 +29 -29 apache-apr/include/apr_errno.h Index: apr_errno.h =================================================================== RCS file: /home/cvs/apache-apr/include/apr_errno.h,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- apr_errno.h 1999/05/24 17:28:19 1.11 +++ apr_errno.h 1999/05/24 18:16:48 1.12 @@ -206,61 +206,61 @@ #else #define APR_ESPIPE 3022 #endif -/* -#ifdef EBUSY -#define APR_EBUSY EBUSY + +#ifdef EIDRM +#define APR_EIDRM EIDRM #else -#define APR_EBUSY 3021 +#define APR_EIDRM 3023 #endif -#ifdef EBUSY -#define APR_EBUSY EBUSY +#ifdef ERANGE +#define APR_ERANGE ERANGE #else -#define APR_EBUSY 3021 +#define APR_ERANGE 3024 #endif -#ifdef EBUSY -#define APR_EBUSY EBUSY +#ifdef E2BIG +#define APR_E2BIG E2BIG #else -#define APR_EBUSY 3021 +#define APR_E2BIG 3025 #endif -#ifdef EBUSY -#define APR_EBUSY EBUSY +#ifdef EAGAIN +#define APR_EAGAIN EAGAIN #else -#define APR_EBUSY 3021 +#define APR_EAGAIN 3026 #endif -#ifdef EBUSY -#define APR_EBUSY EBUSY +#ifdef EFBIG +#define APR_EFBIG EFBIG #else -#define APR_EBUSY 3021 +#define APR_EFBIG 3027 #endif -#ifdef EBUSY -#define APR_EBUSY EBUSY +#ifdef EINTR +#define APR_EINTR EINTR #else -#define APR_EBUSY 3021 +#define APR_EINTR 3028 #endif -#ifdef EBUSY -#define APR_EBUSY EBUSY +#ifdef EDEADLK +#define APR_EDEADLK EDEADLK #else -#define APR_EBUSY 3021 +#define APR_EDEADLK 3029 #endif -#ifdef EBUSY -#define APR_EBUSY EBUSY +#ifdef ENOLCK +#define APR_ENOLCK ENOLCK #else -#define APR_EBUSY 3021 +#define APR_ENOLCK 3030 #endif -#ifdef EBUSY -#define APR_EBUSY EBUSY +#ifdef EWOULDBLOCK +#define APR_EWOULDBLOCK EWOULDBLOCK #else -#define APR_EBUSY 3021 +#define APR_EWOULDBLOCK 3031 #endif - +/* #ifdef EBUSY #define APR_EBUSY EBUSY #else 1.3 +1 -1 apache-apr/include/apr_lock.h Index: apr_lock.h =================================================================== RCS file: /home/cvs/apache-apr/include/apr_lock.h,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- apr_lock.h 1999/05/24 02:04:23 1.2 +++ apr_lock.h 1999/05/24 18:16:49 1.3 @@ -68,7 +68,7 @@ typedef struct lock_t ap_lock_t; /* Function definitions */ -ap_lock_t *ap_create_lock(ap_context_t *, ap_locktype_e, char *); +ap_status_t ap_create_lock(ap_context_t *, ap_locktype_e, char *, ap_lock_t **); ap_status_t ap_lock(ap_lock_t *); ap_status_t ap_unlock(ap_lock_t *); ap_status_t ap_destroy_lock(ap_lock_t *);