]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/msgqueue.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxMessageQueue<T>
4 // Author: wxWidgets team
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
10 wxMessageQueue allows passing messages between threads.
12 This class should be typically used to communicate between the main and worker
13 threads. The main thread calls wxMessageQueue::Post and the worker thread
14 calls wxMessageQueue::Receive.
17 For this class a message is an object of arbitrary type T.
19 Notice that often there is a some special message indicating that the thread
20 should terminate as there is no other way to gracefully shutdown a thread
21 waiting on the message queue.
31 class wxMessageQueue
<T
>
35 Default and only constructor.
36 Use wxMessageQueue::IsOk to check if the object was successfully initialized.
41 Remove all messages from the queue.
43 This method is meant to be called from the same thread(s) that call
44 Post() to discard any still pending requests if they became
49 wxMessageQueueError
Clear();
52 Returns @true if the object had been initialized successfully, @false
58 Add a message to this queue and signal the threads waiting for messages
59 (i.e. the threads which called wxMessageQueue::Receive or
60 wxMessageQueue::ReceiveTimeout).
62 This method is safe to call from multiple threads in parallel.
64 wxMessageQueueError
Post(T
const& msg
);
67 Block until a message becomes available in the queue.
68 Waits indefinitely long or until an error occurs.
70 The message is returned in @a msg.
72 wxMessageQueueError
Receive(T
& msg
);
75 Block until a message becomes available in the queue, but no more than
76 @a timeout milliseconds has elapsed.
78 If no message is available after @a timeout milliseconds then returns
79 @b wxMSGQUEUE_TIMEOUT.
81 If @a timeout is 0 then checks for any messages present in the queue
82 and returns immediately without waiting.
84 The message is returned in @a msg.
86 wxMessageQueueError
ReceiveTimeout(long timeout
, T
& msg
);