xoreos
0.0.5
|
The request manager, handling all requests. More...
#include <requests.h>
Public Member Functions | |
~RequestManager () | |
void | init () |
void | deinit () |
void | dispatch (RequestID request) |
Dispatch a request. More... | |
void | waitReply (RequestID request) |
Wait for a request to be answered. More... | |
void | forget (RequestID request) |
Ignore any answer we get. More... | |
void | dispatchAndWait (RequestID request) |
Dispatch a request and wait for the answer. More... | |
void | dispatchAndForget (RequestID request) |
Dispatch a request and ignore the answer. More... | |
void | sync () |
Request a sync, letting all prior requests finish. More... | |
template<typename T > | |
T | callInMainThread (const MainThreadFunctor< T > &f) |
Call this function in the main thread. More... | |
RequestID | rebuild (Graphics::GLContainer &glContainer) |
Request that a GL container shall be rebuilt. More... | |
RequestID | destroy (Graphics::GLContainer &glContainer) |
Request that a GL container shall be destroyed. More... | |
Public Member Functions inherited from Common::Thread | |
Thread () | |
virtual | ~Thread () |
bool | createThread (const UString &name="") |
bool | destroyThread () |
Static Public Member Functions | |
static void | destroy () |
Static Public Member Functions inherited from Common::Singleton< RequestManager > | |
static RequestManager & | instance () |
static void | destroy () |
Private Member Functions | |
RequestID | newRequest (ITCEvent type) |
Create a new, empty request of that type. More... | |
void | clearList () |
void | collectGarbage () |
void | threadMethod () |
void | callInMainThread (const MainThreadCallerFunctor &caller) |
Private Attributes | |
Common::Mutex | _mutexUse |
The mutex locking the use of the manager. More... | |
RequestList | _requests |
All currently active requests. More... | |
Additional Inherited Members | |
Protected Types inherited from Common::Singleton< RequestManager > | |
typedef RequestManager | SingletonBaseType |
Protected Member Functions inherited from Common::Singleton< RequestManager > | |
Singleton () | |
virtual | ~Singleton () |
Protected Attributes inherited from Common::Thread | |
boost::atomic< bool > | _killThread |
The request manager, handling all requests.
Requests are the main means of communication between the game thread and the main thread, which handles all low-level event and graphics operations.
The idea behind requests is that, as soon as the game thread knows exactly what it needs, it creates and dispatches a specific request. Then it does other things, until it needs what it requested for, issuing a waitReply on the request. That way, the actual fulfilling of the request can happen asynchronously, without it unnecessarily blocking further execution of the game thread.
Definition at line 65 of file requests.h.
Events::RequestManager::~RequestManager | ( | ) |
Definition at line 38 of file requests.cpp.
References clearList().
|
inline |
Call this function in the main thread.
Definition at line 88 of file requests.h.
References Common::StackException::empty(), Events::MainThreadFunctor< T >::getError(), and Events::MainThreadFunctor< T >::getReturnValue().
|
private |
Definition at line 152 of file requests.cpp.
References dispatchAndWait(), Events::kITCEventCallInMainThread, and newRequest().
|
private |
Definition at line 160 of file requests.cpp.
References _mutexUse, _requests, and Common::PtrList< T, Deallocator >::clear().
Referenced by deinit(), init(), and ~RequestManager().
|
private |
Definition at line 170 of file requests.cpp.
References _mutexUse, _requests, Common::PtrList< T, Deallocator >::remove_if(), and Events::requestIsGarbage().
Referenced by threadMethod().
void Events::RequestManager::deinit | ( | ) |
Definition at line 49 of file requests.cpp.
References clearList(), and Common::Thread::destroyThread().
RequestID Events::RequestManager::destroy | ( | Graphics::GLContainer & | glContainer | ) |
Request that a GL container shall be destroyed.
Definition at line 136 of file requests.cpp.
References Events::kITCEventDestroyGLContainer, and newRequest().
|
static |
Definition at line 183 of file requests.cpp.
References Common::Singleton< T >::destroy().
Referenced by deinit().
void Events::RequestManager::dispatch | ( | RequestID | request | ) |
Dispatch a request.
Definition at line 55 of file requests.cpp.
References _mutexUse, EventMan, and Common::isMainThread().
Referenced by dispatchAndForget(), and dispatchAndWait().
void Events::RequestManager::dispatchAndForget | ( | RequestID | request | ) |
Dispatch a request and ignore the answer.
Definition at line 117 of file requests.cpp.
References dispatch(), and forget().
void Events::RequestManager::dispatchAndWait | ( | RequestID | request | ) |
Dispatch a request and wait for the answer.
Definition at line 112 of file requests.cpp.
References dispatch(), and waitReply().
Referenced by callInMainThread(), and sync().
void Events::RequestManager::forget | ( | RequestID | request | ) |
Ignore any answer we get.
Definition at line 106 of file requests.cpp.
References _mutexUse.
Referenced by dispatchAndForget().
void Events::RequestManager::init | ( | ) |
Definition at line 42 of file requests.cpp.
References clearList(), and Common::Thread::createThread().
Create a new, empty request of that type.
Definition at line 144 of file requests.cpp.
References _mutexUse, and _requests.
Referenced by callInMainThread(), destroy(), rebuild(), and sync().
RequestID Events::RequestManager::rebuild | ( | Graphics::GLContainer & | glContainer | ) |
Request that a GL container shall be rebuilt.
Definition at line 128 of file requests.cpp.
References Events::kITCEventRebuildGLContainer, and newRequest().
void Events::RequestManager::sync | ( | ) |
Request a sync, letting all prior requests finish.
Definition at line 122 of file requests.cpp.
References dispatchAndWait(), Events::kITCEventSync, and newRequest().
|
privatevirtual |
Implements Common::Thread.
Definition at line 176 of file requests.cpp.
References Common::Thread::_killThread, collectGarbage(), and EventMan.
void Events::RequestManager::waitReply | ( | RequestID | request | ) |
Wait for a request to be answered.
Definition at line 74 of file requests.cpp.
References _mutexUse, Common::Mutex::lock(), and Common::Mutex::unlock().
Referenced by dispatchAndWait().
|
private |
The mutex locking the use of the manager.
Definition at line 108 of file requests.h.
Referenced by clearList(), collectGarbage(), dispatch(), forget(), newRequest(), and waitReply().
|
private |
All currently active requests.
Definition at line 110 of file requests.h.
Referenced by clearList(), collectGarbage(), and newRequest().