Changeset 846 for trunk/server/lib/tdb/common/lock.c
- Timestamp:
- Feb 14, 2014, 3:12:09 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/tdb/common/lock.c
r842 r846 32 32 tdb->interrupt_sig_ptr = ptr; 33 33 } 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 34 75 35 76 static int fcntl_lock(struct tdb_context *tdb, … … 49 90 50 91 #ifdef __OS2__ 51 int cmd = 0; 52 if (waitflag) 53 cmd = F_SETLKW; 54 else 55 cmd = F_SETLK; 56 57 TDB_LOG((tdb, TDB_DEBUG_TRACE,"fcntl_lock in: (fd=%d) offset=%lld rw_type=%d len=%lld waitflag=%d\n", 58 tdb->fd, off, rw, len, waitflag)); 59 60 int rc = fcntl(tdb->fd, cmd, &fl); 61 // if the first lock doesn't work and it's a complete lock, 62 // we split it in 2 parts. first hash size*4 and then the rest 63 if (rc != 0 && off == FREELIST_TOP && len == 0) { 64 fl.l_len = tdb->header.hash_size * 4; 92 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 65 103 rc = fcntl(tdb->fd, cmd, &fl); 66 if (rc == 0) { 67 fl.l_start = off + tdb->header.hash_size * 4; 68 fl.l_len = LONG_MAX; 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; 69 108 rc = fcntl(tdb->fd, cmd, &fl); 70 } 71 } 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 } 114 } 115 } 116 117 TDB_LOG((tdb, TDB_DEBUG_TRACE,"fcntl_lock: (fd=%d) offset=%lld rw_type=%d len=%lld waitflag=%d (rc=%d)\n", 118 tdb->fd, off, rw, len, waitflag, rc)); 119 72 120 return rc; 73 121 #else … … 151 199 152 200 #ifdef __OS2__ 153 TDB_LOG((tdb, TDB_DEBUG_TRACE,"fcntl_unlock in: (fd=%d) offset=%lld rw_type=%d len=%lld\n", 154 tdb->fd, off, rw, len)); 155 156 int rc = fcntl(tdb->fd, F_SETLKW, &fl); 157 // if the first unlock doesn't work and it's a complete unlock, 158 // we split it in 2 parts. first hash size*4 and then the rest 159 // as it was locked that way as well. and it seems fcntl() doesn't care 160 if (rc != 0 && off == FREELIST_TOP && len == 0) { 161 fl.l_len = tdb->header.hash_size * 4; 201 int rc = 0; 202 if (off == ACTIVE_LOCK) { 203 rc = handle_mutex_lock(tdb, tdb->hActiveLock, F_UNLCK, 1); 204 } else { 162 205 rc = fcntl(tdb->fd, F_SETLKW, &fl); 163 if (rc == 0) { 164 fl.l_start = off + tdb->header.hash_size * 4; 165 fl.l_len = LONG_MAX; 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; 166 211 rc = fcntl(tdb->fd, F_SETLKW, &fl); 167 } 168 } 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 } 217 } 218 } 219 220 TDB_LOG((tdb, TDB_DEBUG_TRACE,"fcntl_unlock: (fd=%d) offset=%lld rw_type=%d len=%lld (rc=%d)\n", 221 tdb->fd, off, rw, len, rc)); 222 169 223 return rc; 170 224 #else
Note:
See TracChangeset
for help on using the changeset viewer.