Changeset 846 for trunk/server/lib/tdb/common
- Timestamp:
- Feb 14, 2014, 3:12:09 PM (12 years ago)
- Location:
- trunk/server/lib/tdb/common
- Files:
-
- 3 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 -
trunk/server/lib/tdb/common/open.c
r834 r846 292 292 goto internal; 293 293 } 294 295 #ifdef __OS2__ 296 if (os2_crtSem(tdb, name, "tdb_open_ex") != 0) 297 goto fail; 298 #endif 294 299 295 300 if ((tdb->fd = open(name, open_flags, mode)) == -1) { … … 470 475 { int save_errno = errno; 471 476 477 #ifdef __OS2__ 478 DosCloseMutexSem(tdb->hActiveLock); 479 tdb->hActiveLock = 0; 480 #endif 472 481 if (!tdb) 473 482 return NULL; … … 538 547 } 539 548 549 #ifdef __OS2__ 550 DosCloseMutexSem(tdb->hActiveLock); 551 tdb->hActiveLock = 0; 552 #endif 553 540 554 #ifdef TDB_TRACE 541 555 close(tdb->tracefd); … … 605 619 #endif /* fake pread or pwrite */ 606 620 621 #ifdef __OS2__ 622 DosCloseMutexSem(tdb->hActiveLock); 623 tdb->hActiveLock = 0; 624 625 if (os2_crtSem(tdb, tdb->name, "tdb_reopen") != 0) 626 goto fail; 627 #endif 607 628 /* We may still think we hold the active lock. */ 608 629 tdb->num_lockrecs = 0; … … 658 679 return 0; 659 680 } 681 #ifdef __OS2__ 682 int os2_crtSem(struct tdb_context *tdb, const char *name, const char *caller) 683 { 684 // name could be null, so handle it 685 if (name == NULL) 686 return -1; 687 688 char szSem[_MAX_PATH]; 689 char drive[_MAX_DRIVE], dir[_MAX_DIR]; 690 char fname[_MAX_FNAME], ext[_MAX_EXT]; 691 APIRET rc; 692 // extract path info 693 _splitpath(name, drive, dir, fname, ext); 694 sprintf(szSem, "\\SEM32\\TDB_AL_%s%s%s", dir, fname, ext); 695 rc = DosCreateMutexSem(szSem, &tdb->hActiveLock, 0, FALSE); 696 if (rc == ERROR_DUPLICATE_NAME) 697 rc = DosOpenMutexSem(szSem, &tdb->hActiveLock); 698 if (rc != NO_ERROR) { 699 TDB_LOG((tdb, TDB_DEBUG_ERROR, "os2_crtSem: cannot create sem32 %s (rc=%d) called from %s\n", 700 szSem, rc, caller)); 701 errno = EINVAL; 702 return -1; 703 } 704 return 0; 705 } 706 #endif -
trunk/server/lib/tdb/common/tdb_private.h
r834 r846 23 23 License along with this library; if not, see <http://www.gnu.org/licenses/>. 24 24 */ 25 #ifdef __OS2__ 26 #define INCL_ERRORS 27 #define INCL_DOS 28 #include <os2.h> 29 #endif 25 30 26 31 #include "replace.h" … … 214 219 #endif 215 220 volatile sig_atomic_t *interrupt_sig_ptr; 221 #ifdef __OS2__ 222 HMTX hActiveLock; 223 #endif 216 224 }; 217 225
Note:
See TracChangeset
for help on using the changeset viewer.