19 #include <shared_mutex>
20 #include <unordered_map>
27 namespace ExecutorResourceMgr_Namespace {
37 std::unordered_map<RequestId, SemaphoreShim_Namespace::BinarySemaphore>;
49 wait_semaphore.try_acquire();
62 const size_t max_wait_in_ms) {
66 const bool did_timeout = !(wait_semaphore.try_acquire_for(max_wait_in_ms));
80 std::vector<RequestId> outstanding_request_ids;
84 outstanding_request_ids.emplace_back(request_entry.first);
86 return outstanding_request_ids;
101 request_itr->second.release();
Stores and allows access to a binary semaphore per RequestId (using an std::unordered_map), as well as accessing all outstanding RequestIds for waiting requests.
SemaphoreShim_Namespace::BinarySemaphore & get_semaphore_for_request(const RequestId request_id)
Creates a new entry in outstanding_requests_map_, assigning a BinarySemaphore for the given requestin...
void queue_request_and_wait(const RequestId request_id)
Submits a request with id request_id into the queue, waiting on a BinarySemaphore until ExecutorResou...
void delete_semaphore_for_request(const RequestId request_id)
Internal method: removes a RequestId-BinarySemaphore entry from outstanding_requests_map_. Invoked after a request thread is awoken (including on timeout).
OutstandingQueueRequestsMap outstanding_requests_map_
Stores a map of RequestId to BinarySemaphore
std::vector< RequestId > get_outstanding_request_ids()
Get the RequestIds of all outsanding requests in the queue.
void wake_request_by_id(const RequestId request_id)
Wakes a waiting thread in the queue. Invoked by ExecutorResourceMgr::process_queue_loop() ...
Utility type that implemnts behavior of a blocking binary semaphore, with an optional timeout...
void queue_request_and_wait_with_timeout(const RequestId request_id, const size_t max_wait_in_ms)
Submits a request with id request_id into the queue, waiting on a BinarySemaphore until ExecutorResou...
std::unordered_map< RequestId, SemaphoreShim_Namespace::BinarySemaphore > OutstandingQueueRequestsMap
std::shared_mutex requests_map_mutex_
Read-write lock protecting the outstanding_requests_map_
std::shared_timed_mutex shared_mutex