Changeset 895 for trunk/server/lib/tdb/common/io.c
- Timestamp:
- Mar 18, 2016, 7:53:30 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/tdb/common/io.c
r878 r895 91 91 return -1; 92 92 93 #ifdef __OS2__94 // YD we must upgrade read locks to write locks (exclusive), as otherwise95 // the owner (us) is not allowed to write to the file (different from unix)96 // if a wider previous lock is in effect, we cannot write lock our segment97 // (e.g. a lock_upgrade locks all the file), so we hope the previous lock98 // is a write lock: do not wait for lock.99 // so this is what we try here:100 // 1. add a write lock and see it it works101 // 2. if the write lock wasn't set, we try to unlock the segment102 // first and add the write lock afterwards103 // 3. we remove the write lock further down104 // 4. we add the removed lock from step #2 again105 int upgradeLockRC = 0;106 int unlockRC = -1;107 upgradeLockRC = tdb_brlock(tdb, F_WRLCK, off, len, TDB_LOCK_NOWAIT);108 if (upgradeLockRC != 0) {109 unlockRC = tdb_brunlock(tdb, F_RDLCK, off, 1);110 upgradeLockRC = tdb_brlock(tdb, F_WRLCK, off, len, TDB_LOCK_NOWAIT);111 }112 // no need to log a successful upgrade113 if (upgradeLockRC != 0)114 TDB_LOG((tdb, TDB_DEBUG_TRACE,"upgrading lock at %d len=%d "115 "before writing %s (rc=%d).\n", off, len,116 upgradeLockRC ? "failed":"was successful", upgradeLockRC));117 #endif118 93 if (tdb->map_ptr) { 119 94 memcpy(off + (char *)tdb->map_ptr, buf, len); … … 141 116 "write %d bytes at %d in two attempts\n", 142 117 len, off)); 143 #ifdef __OS2__ // remove our lock, if upgrade succeded 144 if (upgradeLockRC == 0) 145 tdb_brunlock( tdb, F_WRLCK, off, len); 146 if (unlockRC == 0) 147 tdb_brlock( tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT); 148 #endif 149 return -1; 150 } 151 } 152 #ifdef __OS2__ // remove our lock, if upgrade succeded 153 if (upgradeLockRC == 0) 154 tdb_brunlock( tdb, F_WRLCK, off, len); 155 if (unlockRC == 0) 156 tdb_brlock( tdb, F_RDLCK, off, 1, TDB_LOCK_WAIT); 157 #endif 118 return -1; 119 } 120 } 158 121 return 0; 159 122 }
Note:
See TracChangeset
for help on using the changeset viewer.