httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gst...@locus.apache.org
Subject cvs commit: apache-2.0/src/lib/sdbm sdbm_lock.c sdbm_tune.h sdbm.c
Date Sat, 01 Jul 2000 13:58:56 GMT
gstein      00/07/01 06:58:53

  Modified:    src/lib/sdbm sdbm_lock.c sdbm_tune.h sdbm.c
  Log:
  switch over to use APR locks (the old scheme relied on Apache 1.3 symbols
      which no longer exist in 2.0). still not right (the lock is not
      fine-grained enough), but it works.
  
  Revision  Changes    Path
  1.2       +25 -87    apache-2.0/src/lib/sdbm/sdbm_lock.c
  
  Index: sdbm_lock.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/sdbm/sdbm_lock.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sdbm_lock.c	2000/06/28 08:56:03	1.1
  +++ sdbm_lock.c	2000/07/01 13:58:52	1.2
  @@ -4,103 +4,41 @@
   ** Snarfed from mod_rewrite.c. Munged up for our use.
   */
   
  -#include "ap_config.h"
  +#include "apr_lock.h"
   
  -    /* The locking support:
  -     * Try to determine whether we should use fcntl() or flock().
  -     * Would be better ap_config.h could provide this... :-(
  -     */
  -#if defined(USE_FCNTL_SERIALIZED_ACCEPT)
  -#define USE_FCNTL 1
  -#include <fcntl.h>
  -#endif
  -#if defined(USE_FLOCK_SERIALIZED_ACCEPT)
  -#define USE_FLOCK 1
  -#include <sys/file.h>
  -#endif
  -#if !defined(USE_FCNTL) && !defined(USE_FLOCK)
  -#define USE_FLOCK 1
  -#if !defined(MPE) && !defined(WIN32)
  -#include <sys/file.h>
  -#endif
  -#ifndef LOCK_UN
  -#undef USE_FLOCK
  -#define USE_FCNTL 1
  -#include <fcntl.h>
  -#endif
  -#endif
  -#ifdef AIX
  -#undef USE_FLOCK
  -#define USE_FCNTL 1
  -#include <fcntl.h>
  -#endif
  -#ifdef WIN32
  -#undef USE_FCNTL
  -#define USE_LOCKING
  -#include <sys/locking.h>
  -#endif
  -
  -
  -#ifdef USE_FCNTL
  -/* ugly interface requires this structure to be "live" for a while */
  -static struct flock   lock_it;
  -static struct flock unlock_it;
  -#endif
  +static ap_lock_t *sdbm_lock_object = NULL;
   
  +
  +static ap_status_t create_lock()
  +{
  +    /* ### this should be specific to the file... */
  +    return ap_create_lock(&sdbm_lock_object, APR_MUTEX, APR_LOCKALL,
  +                          NULL, NULL);
  +}
  +
   /* NOTE: this function blocks until it acquires the lock */
  -int sdbm_fd_lock(int fd, int readonly)
  +ap_status_t sdbm_fd_lock(int fd, int readonly)
   {
  -    int rc;
  +    ap_status_t status;
   
  -#ifdef USE_FCNTL
  -    lock_it.l_whence = SEEK_SET; /* from current point */
  -    lock_it.l_start  = 0;        /* -"- */
  -    lock_it.l_len    = 0;        /* until end of file */
  -    lock_it.l_type   = readonly ? F_RDLCK : F_WRLCK;  /* set lock type */
  -    lock_it.l_pid    = 0;        /* pid not actually interesting */
  -
  -    while (   ((rc = fcntl(fd, F_SETLKW, &lock_it)) < 0)
  -              && (errno == EINTR)                               ) {
  -        continue;
  -    }
  -#endif
  -#ifdef USE_FLOCK
  -    while (   ((rc = flock(fd, readonly ? LOCK_SH : LOCK_EX)) < 0)
  -              && (errno == EINTR)               ) {
  -        continue;
  +    if (sdbm_lock_object == NULL) {
  +        if ((status = create_lock()) != APR_SUCCESS) {
  +            return status;
  +        }
       }
  -#endif
  -#ifdef USE_LOCKING
  -    /* ### this doesn't allow simultaneous reads! */
  -    /* ### this doesn't block forever */
  -    /* Lock the first byte */
  -    lseek(fd, 0, SEEK_SET);
  -    rc = _locking(fd, _LK_LOCK, 1);
  -#endif
   
  -    return rc;
  +    return ap_lock(sdbm_lock_object);
   }
   
  -int sdbm_fd_unlock(int fd)
  +ap_status_t sdbm_fd_unlock(int fd)
   {
  -    int rc;
  +    ap_status_t status;
   
  -#ifdef USE_FCNTL
  -    unlock_it.l_whence = SEEK_SET; /* from current point */
  -    unlock_it.l_start  = 0;        /* -"- */
  -    unlock_it.l_len    = 0;        /* until end of file */
  -    unlock_it.l_type   = F_UNLCK;  /* unlock */
  -    unlock_it.l_pid    = 0;        /* pid not actually interesting */
  -
  -    rc = fcntl(fd, F_SETLKW, &unlock_it);
  -#endif
  -#ifdef USE_FLOCK
  -    rc = flock(fd, LOCK_UN);
  -#endif
  -#ifdef USE_LOCKING
  -    lseek(fd, 0, SEEK_SET);
  -    rc = _locking(fd, _LK_UNLCK, 1);
  -#endif
  +    if (sdbm_lock_object == NULL) {
  +        if ((status = create_lock()) != APR_SUCCESS) {
  +            return status;
  +        }
  +    }
   
  -    return rc;
  +    return ap_unlock(sdbm_lock_object);
   }
  
  
  
  1.2       +4 -2      apache-2.0/src/lib/sdbm/sdbm_tune.h
  
  Index: sdbm_tune.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/sdbm/sdbm_tune.h,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sdbm_tune.h	2000/06/28 08:56:03	1.1
  +++ sdbm_tune.h	2000/07/01 13:58:52	1.2
  @@ -4,6 +4,8 @@
    * author: oz@nexus.yorku.ca
    */
   
  +#include "apr_errno.h"
  +
   #define BYTESIZ		8
   
   /*
  @@ -22,5 +24,5 @@
   #define debug(x)
   #endif
   
  -int sdbm_fd_lock(int fd, int readonly);
  -int sdbm_fd_unlock(int fd);
  +ap_status_t sdbm_fd_lock(int fd, int readonly);
  +ap_status_t sdbm_fd_unlock(int fd);
  
  
  
  1.2       +1 -1      apache-2.0/src/lib/sdbm/sdbm.c
  
  Index: sdbm.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/sdbm/sdbm.c,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- sdbm.c	2000/06/28 08:56:03	1.1
  +++ sdbm.c	2000/07/01 13:58:52	1.2
  @@ -124,7 +124,7 @@
   	flags |= O_BINARY;
   #endif
   	if ((db->pagf = open(pagname, flags, mode)) > -1) {
  -	    if ( sdbm_fd_lock(db->pagf, sdbm_rdonly(db)) > -1 ) {
  +	    if ( sdbm_fd_lock(db->pagf, sdbm_rdonly(db)) == APR_SUCCESS ) {
   		if ((db->dirf = open(dirname, flags, mode)) > -1) {
   /*
    * need the dirfile size to establish max bit number.
  
  
  

Mime
View raw message