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