#include <taskqueue.h>
Public Member Functions | |
void | defer (MT mt) |
void | invoke () |
TaskQueue () | |
Private Types | |
typedef vector< MT > | Queue |
Private Member Functions | |
void | _drain (Queue &queue) |
Private Attributes | |
mongo::mutex | _invokeMutex |
Queue | _queues [2] |
int | _which |
defer work items by queueing them for invocation by another thread. presumption is that consumer thread is outside of locks more than the source thread. Additional presumption is that several objects or micro-tasks will be queued and that having a single thread processing them in batch is hepful as they (in the first use case) use a common data structure that can then be in local cpu classes.
this class is in db/ as it is dbMutex (mongomutex) specific (so far).
using a functor instead of go() might be more elegant too, once again, would like to test any performance differential. also worry that operator() hides things?
MT - copyable "micro task" object we can queue must have a static method void MT::go(const MT&)
see DefInvoke in dbtests/ for an example.
Definition at line 42 of file taskqueue.h.
typedef vector< MT > mongo::TaskQueue< MT >::Queue [private] |
Definition at line 89 of file taskqueue.h.
mongo::TaskQueue< MT >::TaskQueue | ( | ) | [inline] |
Definition at line 44 of file taskqueue.h.
void mongo::TaskQueue< MT >::_drain | ( | Queue & | queue | ) | [inline, private] |
Definition at line 95 of file taskqueue.h.
void mongo::TaskQueue< MT >::defer | ( | MT | mt | ) | [inline] |
Definition at line 46 of file taskqueue.h.
void mongo::TaskQueue< MT >::invoke | ( | ) | [inline] |
call to process deferrals.
concurrency: handled herein. multiple threads could call invoke(), but their efforts will be serialized. the common case is that there is a single processor calling invoke().
normally, you call this outside of any lock. but if you want to fully drain the queue, call from within a read lock. for example: { drain with minimal time in lock d.invoke(); readlock lk; d.invoke(); ... } you can also call invoke periodically to do some work and then pick up later on more.
Definition at line 70 of file taskqueue.h.
mongo::mutex mongo::TaskQueue< MT >::_invokeMutex [private] |
Definition at line 93 of file taskqueue.h.
Queue mongo::TaskQueue< MT >::_queues[2] [private] |
Definition at line 90 of file taskqueue.h.
int mongo::TaskQueue< MT >::_which [private] |
Definition at line 88 of file taskqueue.h.