Ignore:
Timestamp:
Mar 18, 2014, 4:51:05 PM (11 years ago)
Author:
Silvan Scherrer
Message:

Samba 3.6: remove mutex sem and do it with a filelock

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/server/lib/tdb/common/lock.c

    r846 r857  
    3232        tdb->interrupt_sig_ptr = ptr;
    3333}
    34 
    35 #ifdef __OS2__
    36 static int handle_mutex_lock(struct tdb_context *tdb, HMTX mutex, int rw, bool waitflag)
    37 {
    38         ULONG   ulTimeout;
    39         APIRET  rc;
    40 
    41         if (mutex == 0) {
    42                 printf( "fcntl_lock: sem not initialised\n");
    43                 exit(1);
    44         }
    45 
    46         if (waitflag)
    47                 ulTimeout = SEM_INDEFINITE_WAIT;
    48         else
    49                 ulTimeout = SEM_IMMEDIATE_RETURN;
    50 
    51         switch (rw) {
    52         case F_UNLCK:
    53                 rc = DosReleaseMutexSem(mutex);
    54                 break;
    55         case F_RDLCK: // we never wait for a read lock, as several want to hold one
    56                 rc = DosRequestMutexSem(mutex, SEM_IMMEDIATE_RETURN);
    57                 if (rc == ERROR_NOT_OWNER || ERROR_TIMEOUT)
    58                         rc = NO_ERROR;
    59                 break;
    60         case F_WRLCK:
    61                 rc = DosRequestMutexSem(mutex, ulTimeout);
    62                 break;
    63         }
    64 
    65         if (rc == NO_ERROR || rc == ERROR_SEM_OWNER_DIED)
    66                 return 0;
    67 
    68         TDB_LOG((tdb, TDB_DEBUG_TRACE,"handle_mutex_lock: (fd=%d) rw_type=%d waitflag=%d (rc=%d)\n",
    69                 tdb->fd, rw, waitflag, rc));
    70 
    71         errno = EINVAL;
    72         return -1;
    73 }
    74 #endif
    7534
    7635static int fcntl_lock(struct tdb_context *tdb,
     
    9150#ifdef __OS2__
    9251        int rc = 0;
    93 
    94         if (off == ACTIVE_LOCK) {
    95                 rc = handle_mutex_lock(tdb, tdb->hActiveLock, rw, waitflag);
    96         } else {
    97                 int cmd = 0;
    98                 if (waitflag)
    99                         cmd = F_SETLKW;
    100                 else
    101                         cmd = F_SETLK;
    102 
    103                 rc = fcntl(tdb->fd, cmd, &fl);
    104                 // if the first lock doesn't work and it's a complete lock,
    105                 // we split it in 2 parts. first hash size*4 and then the rest
    106                 if (rc != 0 && off == FREELIST_TOP && len == 0) {
    107                         fl.l_len = tdb->header.hash_size * 4;
    108                         rc = fcntl(tdb->fd, cmd, &fl);
    109                         if (rc == 0) {
    110                                 fl.l_start = off + tdb->header.hash_size * 4;
    111                                 fl.l_len = LONG_MAX;
    112                                 rc = fcntl(tdb->fd, cmd, &fl);
    113                         }
     52        int lockFile = 0;
     53
     54        if (off == ACTIVE_LOCK)
     55                lockFile = tdb->hActiveLock;
     56        else
     57                lockFile = tdb->fd;
     58
     59        int cmd = 0;
     60        if (waitflag)
     61                cmd = F_SETLKW;
     62        else
     63                cmd = F_SETLK;
     64
     65        rc = fcntl(lockFile, cmd, &fl);
     66        // if the first lock doesn't work and it's a complete lock,
     67        // we split it in 2 parts. first hash size*4 and then the rest
     68        if (rc != 0 && off == FREELIST_TOP && len == 0) {
     69                fl.l_len = tdb->header.hash_size * 4;
     70                rc = fcntl(lockFile, cmd, &fl);
     71                if (rc == 0) {
     72                        fl.l_start = off + tdb->header.hash_size * 4;
     73                        fl.l_len = LONG_MAX;
     74                        rc = fcntl(lockFile, cmd, &fl);
    11475                }
    11576        }
     
    200161#ifdef __OS2__
    201162        int rc = 0;
    202         if (off == ACTIVE_LOCK) {
    203                 rc = handle_mutex_lock(tdb, tdb->hActiveLock, F_UNLCK, 1);
    204         } else {
    205                 rc = fcntl(tdb->fd, F_SETLKW, &fl);
    206                 // if the first unlock doesn't work and it's a complete unlock,
    207                 // we split it in 2 parts. first hash size*4 and then the rest
    208                 // as it was locked that way as well. and it seems fcntl() doesn't care
    209                 if (rc != 0 && off == FREELIST_TOP && len == 0) {
    210                         fl.l_len = tdb->header.hash_size * 4;
    211                         rc = fcntl(tdb->fd, F_SETLKW, &fl);
    212                         if (rc == 0) {
    213                                 fl.l_start = off + tdb->header.hash_size * 4;
    214                                 fl.l_len = LONG_MAX;
    215                                 rc = fcntl(tdb->fd, F_SETLKW, &fl);
    216                         }
     163        int lockFile = 0;
     164        if (off == ACTIVE_LOCK)
     165                lockFile = tdb->hActiveLock;
     166        else
     167                lockFile = tdb->fd;
     168
     169        rc = fcntl(lockFile, F_SETLKW, &fl);
     170        // if the first unlock doesn't work and it's a complete unlock,
     171        // we split it in 2 parts. first hash size*4 and then the rest
     172        // as it was locked that way as well. and it seems fcntl() doesn't care
     173        if (rc != 0 && off == FREELIST_TOP && len == 0) {
     174                fl.l_len = tdb->header.hash_size * 4;
     175                rc = fcntl(lockFile, F_SETLKW, &fl);
     176                if (rc == 0) {
     177                        fl.l_start = off + tdb->header.hash_size * 4;
     178                        fl.l_len = LONG_MAX;
     179                        rc = fcntl(lockFile, F_SETLKW, &fl);
    217180                }
    218181        }
Note: See TracChangeset for help on using the changeset viewer.