xref: /haiku/src/servers/registrar/PriorityMessageQueue.h (revision 2f470aec1c92ce6917b8a903e343795dc77af41f)
1 //----------------------------------------------------------------------
2 //  This software is part of the OpenBeOS distribution and is covered
3 //  by the OpenBeOS license.
4 //---------------------------------------------------------------------
5 
6 #ifndef PRIORITY_MESSAGE_QUEUE_H
7 #define PRIORITY_MESSAGE_QUEUE_H
8 
9 #include <Locker.h>
10 #include <ObjectList.h>
11 
12 class BMessage;
13 
14 class PriorityMessageQueue {
15 public:
16 	PriorityMessageQueue();
17 	~PriorityMessageQueue();
18 
19 	bool Lock();
20 	void Unlock();
21 
22 	bool PushMessage(BMessage *message, int32 priority = 0);
23 	BMessage *PopMessage();
24 
25 	int32 CountMessages() const;
26 	bool IsEmpty() const;
27 
28 private:
29 	int32 _FindInsertionIndex(int32 priority);
30 
31 private:
32 	class MessageInfo;
33 
34 private:
35 	mutable BLocker				fLock;
36 	BObjectList<MessageInfo>	fMessages;
37 };
38 
39 #endif	// PRIORITY_MESSAGE_QUEUE_H
40