]> git.saurik.com Git - wxWidgets.git/blob - interface/msgqueue.h
1a22c706aa44a638d2a3d76e8f073d29ee3b293a
[wxWidgets.git] / interface / msgqueue.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msgqueue.h
3 // Purpose: documentation for wxMessageQueue<T> class
4 // Author: wxWidgets team
5 // RCS-ID: $Id$
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
8
9 /**
10 @class wxMessageQueueT
11 @wxheader{msgqueue.h}
12
13 wxMessageQueue allows passing messages between threads.
14
15 This class should be typically used to communicate between the main and worker
16 threads. The main thread calls wxMessageQueue::Post and
17 the worker thread calls wxMessageQueue::Receive.
18
19 For this class a message is an object of arbitrary type T. Notice that
20 often there is a some special message indicating that the thread
21 should terminate as there is no other way to gracefully shutdown a thread
22 waiting on the message queue.
23
24 @nolibrary
25 @category{FIXME}
26
27 @seealso
28 wxThread
29 */
30 class wxMessageQueue<T>
31 {
32 public:
33 /**
34 Returns @true if the object had been initialized successfully, @false
35 if an error occurred.
36 */
37 bool IsOk() const;
38
39 /**
40 Add a message to this queue and signal the threads waiting for messages
41 (i.e. the threads which called wxMessageQueue::Receive or
42 wxMessageQueue::ReceiveTimeout).
43 This method is safe to call from multiple threads in parallel.
44 */
45 wxMessageQueueError Post(T const& msg);
46
47 /**
48 Block until a message becomes available in the queue. Waits indefinitely long
49 or until an error occurs.
50 The message is returned in @e msg.
51 */
52 wxMessageQueueError Receive(T& msg);
53
54 /**
55 Block until a message becomes available in the queue, but no more than
56 @a timeout milliseconds has elapsed.
57 If no message is available after @a timeout milliseconds then returns
58 @b wxMSGQUEUE_TIMEOUT.
59 If @a timeout is 0 then checks for any messages present in the queue
60 and returns immediately without waiting.
61 The message is returned in @e msg.
62 */
63 wxMessageQueueError ReceiveTimeout(long timeout, T& msg);
64
65 /**
66 Default and only constructor. Use wxMessageQueue::IsOk to check
67 if the object was successfully initialized.
68 */
69 wxMessageQueue();
70 };