| 1222 | |
| 1223 | |
| 1224 | UCHAR* LockManager::alloc(USHORT size, CheckStatusWrapper* statusVector) |
| 1225 | { |
| 1226 | /************************************** |
| 1227 | * |
| 1228 | * a l l o c |
| 1229 | * |
| 1230 | ************************************** |
| 1231 | * |
| 1232 | * Functional description |
| 1233 | * Allocate a block of given size. |
| 1234 | * |
| 1235 | **************************************/ |
| 1236 | LocalStatus ls; |
| 1237 | CheckStatusWrapper localStatus(&ls); |
| 1238 | |
| 1239 | if (!statusVector) |
| 1240 | statusVector = &localStatus; |
| 1241 | |
| 1242 | size = FB_ALIGN(size, FB_ALIGNMENT); |
| 1243 | ASSERT_ACQUIRED; |
| 1244 | ULONG block = m_sharedMemory->getHeader()->lhb_used; |
| 1245 | ULONG memorySize = m_memorySize; |
| 1246 | |
| 1247 | // Make sure we haven't overflowed the lock table. If so, bump the size of the table. |
| 1248 | |
| 1249 | if (m_sharedMemory->getHeader()->lhb_used + size > m_sharedMemory->getHeader()->lhb_length) |
| 1250 | { |
| 1251 | // New table size shouldn't exceed max table length |
| 1252 | if (m_sharedMemory->getHeader()->lhb_length + memorySize > MAX_TABLE_LENGTH) |
| 1253 | { |
| 1254 | if (m_sharedMemory->getHeader()->lhb_used + size <= MAX_TABLE_LENGTH) |
| 1255 | memorySize = MAX_TABLE_LENGTH - m_sharedMemory->getHeader()->lhb_length; |
| 1256 | else |
| 1257 | { |
| 1258 | // Return an error if can't alloc enough memory |
| 1259 | (Arg::Gds(isc_lockmanerr) << |
| 1260 | Arg::Gds(isc_random) << Arg::Str("lock table size exceeds limit") << |
| 1261 | Arg::StatusVector(statusVector)).copyTo(statusVector); |
| 1262 | |
| 1263 | return NULL; |
| 1264 | } |
| 1265 | } |
| 1266 | #ifdef USE_SHMEM_EXT |
| 1267 | // round up so next object starts at beginning of next extent |
| 1268 | block = m_sharedMemory->getHeader()->lhb_used = m_sharedMemory->getHeader()->lhb_length; |
| 1269 | if (createExtent(*statusVector, memorySize)) |
| 1270 | { |
| 1271 | m_sharedMemory->getHeader()->lhb_length += memorySize; |
| 1272 | } |
| 1273 | else |
| 1274 | #elif (defined HAVE_OBJECT_MAP) |
| 1275 | WriteLockGuard guard(m_remapSync, FB_FUNCTION); |
| 1276 | // Post remapping notifications |
| 1277 | remap_local_owners(); |
| 1278 | // Remap the shared memory region |
| 1279 | const ULONG new_length = m_sharedMemory->sh_mem_length_mapped + memorySize; |
| 1280 | if (m_sharedMemory->remapFile(statusVector, new_length, true)) |
| 1281 | { |