Changeset 456 for trunk/server/lib/tdb/common/open.c
- Timestamp:
- Jun 7, 2010, 9:08:40 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server/lib/tdb/common/open.c
r414 r456 27 27 28 28 #include "tdb_private.h" 29 30 #ifdef __OS2__ 31 // nmbd.c sets it to 1 32 int global_Sem32Add = 0; 33 #endif 29 34 30 35 /* all contexts, to ensure no double-opens (fcntl locks don't nest!) */ … … 179 184 tdb->hash_fn = hash_fn ? hash_fn : default_tdb_hash; 180 185 186 #ifdef __OS2__ 187 if (os2_crtsem(tdb, name, "tdb_open_ex") != 0) { 188 goto fail; 189 } 190 #endif 191 181 192 /* cache the page size */ 182 193 tdb->page_size = getpagesize(); … … 250 261 /* we need to zero database if we are the only one with it open */ 251 262 if ((tdb_flags & TDB_CLEAR_IF_FIRST) && 252 (!tdb->read_only) && 253 (locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0))) { 263 (!tdb->read_only) 264 #ifndef __OS2__ 265 && (locked = (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_WRLCK, F_SETLK, 0, 1) == 0)) 266 #endif 267 ) { 254 268 open_flags |= O_CREAT; 255 269 if (ftruncate(tdb->fd, 0) == -1) { … … 314 328 tdb_mmap(tdb); 315 329 if (locked) { 330 #ifndef __OS2__ 316 331 if (tdb->methods->tdb_brlock(tdb, ACTIVE_LOCK, F_UNLCK, F_SETLK, 0, 1) == -1) { 317 332 TDB_LOG((tdb, TDB_DEBUG_ERROR, "tdb_open_ex: " … … 321 336 } 322 337 338 #endif 323 339 } 324 340 … … 327 343 users know we're using it. */ 328 344 345 #ifndef __OS2__ 329 346 if (tdb_flags & TDB_CLEAR_IF_FIRST) { 330 347 /* leave this lock in place to indicate it's in use */ … … 332 349 goto fail; 333 350 } 351 #endif 334 352 335 353 /* if needed, run recovery */ … … 337 355 goto fail; 338 356 } 357 358 #ifdef __OS2__ 359 // YD internal databases do not get global lock! 360 if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1) == -1) 361 goto fail; 362 #endif 339 363 340 364 #ifdef TDB_TRACE … … 358 382 * do with disk files, and resume here by releasing their 359 383 * global lock and hooking into the active list. */ 384 #ifndef __OS2__ 360 385 if (tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLKW, 0, 1) == -1) 361 386 goto fail; 387 #endif 362 388 tdb->next = tdbs; 363 tdbs = tdb;389 tdbs = tdb; 364 390 return tdb; 365 391 … … 380 406 } 381 407 SAFE_FREE(tdb->name); 408 #ifdef __OS2__ 409 DosCloseMutexSem( tdb->hGlobalLock); 410 tdb->hGlobalLock = 0; 411 DosCloseMutexSem( tdb->hActiveLock); 412 tdb->hActiveLock = 0; 413 DosCloseMutexSem( tdb->hTransactionLock); 414 tdb->hTransactionLock = 0; 415 #endif 382 416 if (tdb->fd != -1) 383 417 if (close(tdb->fd) != 0) … … 420 454 } 421 455 SAFE_FREE(tdb->name); 456 #ifdef __OS2__ 457 // YD internal databases do not have a global lock 458 if (!(tdb->flags & TDB_INTERNAL)) 459 tdb->methods->tdb_brlock(tdb, GLOBAL_LOCK, F_UNLCK, F_SETLK, 0, 1); 460 #endif 422 461 if (tdb->fd != -1) { 423 462 ret = close(tdb->fd); … … 425 464 } 426 465 SAFE_FREE(tdb->lockrecs); 466 #ifdef __OS2__ 467 DosCloseMutexSem( tdb->hGlobalLock); 468 tdb->hGlobalLock = 0; 469 DosCloseMutexSem( tdb->hActiveLock); 470 tdb->hActiveLock = 0; 471 DosCloseMutexSem( tdb->hTransactionLock); 472 tdb->hTransactionLock = 0; 473 #endif 427 474 428 475 /* Remove from contexts list */ … … 465 512 return 0; /* Nothing to do. */ 466 513 } 514 515 #ifdef __OS2__ 516 DosCloseMutexSem( tdb->hGlobalLock); 517 tdb->hGlobalLock = 0; 518 DosCloseMutexSem( tdb->hActiveLock); 519 tdb->hActiveLock = 0; 520 DosCloseMutexSem( tdb->hTransactionLock); 521 tdb->hTransactionLock = 0; 522 523 if (os2_crtsem(tdb, tdb->name, "tdb_reopen") != 0) { 524 goto fail; 525 } 526 #endif 467 527 468 528 if (tdb->num_locks != 0 || tdb->global_lock.count) { … … 551 611 return 0; 552 612 } 613 614 #ifdef __OS2__ 615 int os2_crtsem(struct tdb_context *tdb, const char *name, const char *caller) 616 { 617 if (!(tdb->flags & TDB_INTERNAL)) 618 { 619 char szSem[_MAX_PATH]; 620 char drive[_MAX_DRIVE], dir[_MAX_DIR]; 621 char fname[_MAX_FNAME], ext[_MAX_EXT]; 622 APIRET rc; 623 // extract path info 624 _splitpath( name, drive, dir, fname, ext); 625 sprintf( szSem, "\\SEM32\\TDB_GL_%s%s%s%i", dir, fname, ext, global_Sem32Add); 626 rc = DosCreateMutexSem( szSem, &tdb->hGlobalLock, 0, FALSE); 627 if (rc == ERROR_DUPLICATE_NAME) 628 rc = DosOpenMutexSem( szSem, &tdb->hGlobalLock); 629 if (rc != NO_ERROR) { 630 TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc)); 631 errno = EINVAL; 632 return -1; 633 } 634 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d global handle %d\n", caller, getpid(), tdb->hGlobalLock)); 635 636 sprintf( szSem, "\\SEM32\\TDB_AL_%s%s%s%i", dir, fname, ext, global_Sem32Add); 637 rc = DosCreateMutexSem( szSem, &tdb->hActiveLock, 0, FALSE); 638 if (rc == ERROR_DUPLICATE_NAME) 639 rc = DosOpenMutexSem( szSem, &tdb->hActiveLock); 640 if (rc != NO_ERROR) { 641 TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc)); 642 errno = EINVAL; 643 return -1; 644 } 645 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d active handle %d\n", caller, getpid(), tdb->hActiveLock)); 646 647 sprintf( szSem, "\\SEM32\\TDB_TL_%s%s%s%i", dir, fname, ext, global_Sem32Add); 648 rc = DosCreateMutexSem( szSem, &tdb->hTransactionLock, 0, FALSE); 649 if (rc == ERROR_DUPLICATE_NAME) 650 rc = DosOpenMutexSem( szSem, &tdb->hTransactionLock); 651 if (rc != NO_ERROR) { 652 TDB_LOG((tdb, TDB_DEBUG_ERROR, "cannot open %s %d\n", szSem, rc)); 653 errno = EINVAL; 654 return -1; 655 } 656 TDB_LOG((tdb, TDB_DEBUG_TRACE,"%s pid %d transaction handle %d\n", caller, getpid(), tdb->hTransactionLock)); 657 } 658 return 0; 659 } 660 #endif 661
Note:
See TracChangeset
for help on using the changeset viewer.