| 502 | |
| 503 | |
| 504 | frb* EventManager::alloc_global(UCHAR type, ULONG length, bool recurse) |
| 505 | { |
| 506 | /************************************** |
| 507 | * |
| 508 | * a l l o c _ g l o b a l |
| 509 | * |
| 510 | ************************************** |
| 511 | * |
| 512 | * Functional description |
| 513 | * Allocate a block in shared global region. |
| 514 | * |
| 515 | **************************************/ |
| 516 | frb* free; |
| 517 | SLONG best_tail = MAX_SLONG; |
| 518 | |
| 519 | length = FB_ALIGN(length, FB_ALIGNMENT); |
| 520 | SRQ_PTR* best = NULL; |
| 521 | |
| 522 | for (SRQ_PTR* ptr = &m_sharedMemory->getHeader()->evh_free; |
| 523 | (free = (frb*) SRQ_ABS_PTR(*ptr)) && *ptr; |
| 524 | ptr = &free->frb_next) |
| 525 | { |
| 526 | const SLONG tail = free->frb_header.hdr_length - length; |
| 527 | if (tail >= 0 && (!best || tail < best_tail)) |
| 528 | { |
| 529 | best = ptr; |
| 530 | best_tail = tail; |
| 531 | } |
| 532 | } |
| 533 | |
| 534 | #ifdef HAVE_OBJECT_MAP |
| 535 | if (!best && !recurse) |
| 536 | { |
| 537 | fb_assert(length <= m_sharedMemory->sh_mem_increment); |
| 538 | |
| 539 | const ULONG old_length = m_sharedMemory->sh_mem_length_mapped; |
| 540 | const ULONG ev_length = old_length + m_sharedMemory->sh_mem_increment; |
| 541 | |
| 542 | LocalStatus ls; |
| 543 | CheckStatusWrapper localStatus(&ls); |
| 544 | if (m_sharedMemory->remapFile(&localStatus, ev_length, true)) |
| 545 | { |
| 546 | free = (frb*) (((UCHAR*) m_sharedMemory->getHeader()) + old_length); |
| 547 | //free->frb_header.hdr_length = EVENT_EXTEND_SIZE - sizeof (struct evh); |
| 548 | free->frb_header.hdr_length = m_sharedMemory->sh_mem_length_mapped - old_length; |
| 549 | free->frb_header.hdr_type = type_frb; |
| 550 | free->frb_next = 0; |
| 551 | |
| 552 | m_sharedMemory->getHeader()->evh_length = m_sharedMemory->sh_mem_length_mapped; |
| 553 | |
| 554 | free_global(free); |
| 555 | |
| 556 | return alloc_global(type, length, true); |
| 557 | } |
| 558 | } |
| 559 | #endif |
| 560 | |
| 561 | if (!best) |