MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / alloc_request

Function alloc_request

src/remote/server/server.cpp:1523–1585  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1521
1522
1523static server_req_t* alloc_request()
1524{
1525/**************************************
1526 *
1527 * a l l o c _ r e q u e s t
1528 *
1529 **************************************
1530 *
1531 * Functional description
1532 * Get request block from the free blocks list,
1533 * if empty - allocate the new one.
1534 *
1535 **************************************/
1536 MutexEnsureUnlock queGuard(request_que_mutex, FB_FUNCTION);
1537 queGuard.enter();
1538
1539 server_req_t* request = free_requests;
1540#if defined(DEV_BUILD) && defined(DEBUG)
1541 int request_count = 0;
1542#endif
1543
1544 // Allocate a memory block to store the request in
1545 if (request)
1546 {
1547 free_requests = request->req_next;
1548 }
1549 else
1550 {
1551 // No block on the free list - allocate some new memory
1552 for (;;)
1553 {
1554 try
1555 {
1556 request = FB_NEW server_req_t;
1557 break;
1558 }
1559 catch (const BadAlloc&)
1560 { }
1561
1562#if defined(DEV_BUILD) && defined(DEBUG)
1563 if (request_count++ > 4)
1564 BadAlloc::raise();
1565#endif
1566
1567 // System is out of memory, let's delay processing this
1568 // request and hope another thread will free memory or
1569 // request blocks that we can then use.
1570
1571 queGuard.leave();
1572 Thread::sleep(1 * 1000);
1573 queGuard.enter();
1574 }
1575 zap_packet(&request->req_send, true);
1576 zap_packet(&request->req_receive, true);
1577#ifdef DEBUG_REMOTE_MEMORY
1578 printf("alloc_request allocate request %x\n", request);
1579#endif
1580 }

Callers 2

SRVR_multi_threadFunction · 0.85
loopThreadFunction · 0.85

Calls 5

raiseFunction · 0.85
zap_packetFunction · 0.70
sleepFunction · 0.50
enterMethod · 0.45
leaveMethod · 0.45

Tested by

no test coverage detected