class
SingleConsumerQueue
Allows you to queue sequential commands safely from any thread/fiber, which are then processed by a single worker thread/fiber.
Public
Constructors
SingleConsumerQueue
Methods
~SingleConsumerQueue
GetThreadId
Returns the thread id on which the queue commands are being processed on.
Only valid after RunUntilShutdown() is called.
GetSchedulerThread
Returns the scheduler thread that the queue is executing commands on.
May be null if not scheduler is associated with the thread.
PostCommand
Posts a command for execution on the queue.
Optionally blocks the calling fiber/thread until the command completes. Thread safe.
PostRequestShutdownCommand
Posts a special command that requests shutdown.
Optionally blocks the calling fiber/thread until the command completes. Thread safe.
RunUntilIdle
Processes all currently queued commands and then returns.
Optionally if timeout is specified, it returns if the duration is reached even if not all commands have been processed.
- startTime
- Start time used for checking when the timeout happens compared to current time. Only relevant if timeout is specified.
- timeout
- If non-zero, the method will return even if not all commands have been processed, but the timeout was reached.
Returns: True if timeout was reached, false if all commands were processed.
RunUntilShutdown
Runs an infinite loop that processes commands until shutdown is requested via RequestShutdown().
You must call this method or the other overload once on a thread or fiber that will be processing the commands. Note that if running this on the fiber, a busy queue can completely block other tasks from running on the fiber thread - consider using ScheduleRunUntilShutdown() instead.
ScheduleRunUntilShutdown
Schedules a task that processes commands until shutdown is requested via RequestShutdown().
Optionally yields the fiber at specified intervals, allowing other tasks on the thread to execute.
- scheduler
- Scheduler on which to post the task on.
- runOnCallingThread
- If true, the task will run on the calling thread, otherwise an arbitrary thread assigned by the scheduler.
- yieldInterval
- If non-zero, the scheduler task will end after this interval is reached, and it will be re-queued with the scheduler. This puts it back in the scheduler's task queue, allowing other tasks to run.
- blockUntilDone
- If true, the calling fiber will be blocked until shutdown is requested.
Private
Fields
mThreadId
mSchedulerThread
mCommandQueue
mEmptyCommandQueues
List of empty queues for reuse.