Changeset 840
- Timestamp:
- Feb 4, 2014, 4:58:40 PM (12 years ago)
- Location:
- trunk/server/lib/tdb/common
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/tdb/common/io.c
r835 r840 92 92 93 93 #ifdef __OS2__ 94 // YD we must upgrade read locks to write locks (exclusive), otherwise94 // YD we must upgrade read locks to write locks (exclusive), as otherwise 95 95 // the owner (us) is not allowed to write to the file (different from unix) 96 96 // if a wider previous lock is in effect, we cannot write lock our segment 97 97 // (e.g. a lock_upgrade locks all the file), so we hope the previous lock 98 98 // is a write lock: do not wait for lock. 99 int upgradeLockRC = tdb_brlock( tdb, F_WRLCK, off, len, F_SETLK); 99 // so this is what we try here: 100 // 1. add a write lock and see if it works 101 // 2. if the write lock wasn't set, we try to unlock the segment 102 // first and add the write lock afterwards 103 int upgradeLockRC = tdb_brlock(tdb, F_WRLCK, off, len, TDB_LOCK_NOWAIT); 104 if (upgradeLockRC != 0) { 105 tdb_brunlock(tdb, F_RDLCK, off, len); 106 int upgradeLockRC = tdb_brlock(tdb, F_WRLCK, off, len, TDB_LOCK_NOWAIT); 107 } 100 108 TDB_LOG((tdb, TDB_DEBUG_TRACE,"upgrading lock at %d len=%d " 101 109 "before writing %s (rc=%d).\n", off, len, -
trunk/server/lib/tdb/common/lock.c
r834 r840 34 34 35 35 static int fcntl_lock(struct tdb_context *tdb, 36 int rw, off_t off, off_t len, bool waitflag)36 int rw, tdb_off_t off, size_t len, bool waitflag) 37 37 { 38 38 struct flock fl; … … 48 48 fl.l_pid = 0; 49 49 50 #ifdef __OS2__ 51 int cmd = 0; 52 if (waitflag) 53 cmd = F_SETLKW; 54 else 55 cmd = F_SETLK; 56 57 int rc = fcntl(tdb->fd, cmd, &fl); 58 // if the first lock doesn't work and it's a complete lock, 59 // we split it in 2 parts. first hash size*4 and then the rest 60 if (rc != 0 && off == FREELIST_TOP && len == 0) { 61 fl.l_len = tdb->header.hash_size * 4; 62 rc = fcntl(tdb->fd, cmd, &fl); 63 if (rc == 0) { 64 fl.l_start = off + tdb->header.hash_size * 4; 65 fl.l_len = LONG_MAX; 66 rc = fcntl(tdb->fd, cmd, &fl); 67 } 68 } 69 return rc; 70 #else 50 71 if (waitflag) 51 72 return fcntl(tdb->fd, F_SETLKW, &fl); 52 73 else 53 74 return fcntl(tdb->fd, F_SETLK, &fl); 54 } 55 56 static int fcntl_unlock(struct tdb_context *tdb, int rw, off_t off, off_t len) 75 #endif 76 } 77 78 static int fcntl_unlock(struct tdb_context *tdb, int rw, tdb_off_t off, size_t len) 57 79 { 58 80 struct flock fl; … … 248 270 while (count--) { 249 271 struct timeval tv; 272 #ifdef __OS2__ 273 // we need to remove locks, as upgrade doesn't work 274 tdb_brunlock(tdb, F_RDLCK, FREELIST_TOP, 0); 275 #endif 250 276 if (tdb_brlock(tdb, F_WRLCK, FREELIST_TOP, 0, 251 277 TDB_LOCK_WAIT|TDB_LOCK_PROBE) == 0) {
Note:
See TracChangeset
for help on using the changeset viewer.