| 1044 | |
| 1045 | |
| 1046 | void LockManager::acquire_shmem(SRQ_PTR owner_offset) |
| 1047 | { |
| 1048 | /************************************** |
| 1049 | * |
| 1050 | * a c q u i r e |
| 1051 | * |
| 1052 | ************************************** |
| 1053 | * |
| 1054 | * Functional description |
| 1055 | * Acquire the lock file. If it's busy, wait for it. |
| 1056 | * |
| 1057 | **************************************/ |
| 1058 | LocalStatus ls; |
| 1059 | CheckStatusWrapper localStatus(&ls); |
| 1060 | |
| 1061 | // Perform a spin wait on the lock table mutex. This should only |
| 1062 | // be used on SMP machines; it doesn't make much sense otherwise. |
| 1063 | |
| 1064 | const ULONG spins_to_try = m_acquireSpins ? m_acquireSpins : 1; |
| 1065 | bool locked = false; |
| 1066 | ULONG spins = 0; |
| 1067 | while (spins++ < spins_to_try) |
| 1068 | { |
| 1069 | if (m_sharedMemory->mutexLockCond()) |
| 1070 | { |
| 1071 | locked = true; |
| 1072 | break; |
| 1073 | } |
| 1074 | |
| 1075 | m_blockage = true; |
| 1076 | } |
| 1077 | |
| 1078 | // If the spin wait didn't succeed then wait forever |
| 1079 | |
| 1080 | if (!locked) |
| 1081 | m_sharedMemory->mutexLock(); |
| 1082 | |
| 1083 | // Reattach if someone has just deleted the shared file |
| 1084 | |
| 1085 | while (m_sharedMemory->getHeader()->isDeleted()) |
| 1086 | { |
| 1087 | fb_assert(!m_process); |
| 1088 | if (m_process) |
| 1089 | bug(NULL, "Process disappeared in LockManager::acquire_shmem"); |
| 1090 | |
| 1091 | // Shared memory must be empty at this point |
| 1092 | fb_assert(SRQ_EMPTY(m_sharedMemory->getHeader()->lhb_processes)); |
| 1093 | |
| 1094 | // no sense thinking about statistics now |
| 1095 | m_blockage = false; |
| 1096 | |
| 1097 | m_sharedMemory->mutexUnlock(); |
| 1098 | m_sharedMemory.reset(); |
| 1099 | |
| 1100 | Thread::yield(); |
| 1101 | |
| 1102 | if (!init_shared_file(&localStatus)) |
| 1103 | bug(NULL, "ISC_map_file failed (reattach shared file)"); |
no test coverage detected