Further non-Unicode fixes; LoraWAN subagent refactoring
[public/netxms.git] / include / nxqueue.h
CommitLineData
c25cb4a0
VK
1/*
2** NetXMS - Network Management System
1499848d 3** Copyright (C) 2003-2013 Victor Kirhenshtein
c25cb4a0
VK
4**
5** This program is free software; you can redistribute it and/or modify
68f384ea
VK
6** it under the terms of the GNU Lesser General Public License as published
7** by the Free Software Foundation; either version 3 of the License, or
c25cb4a0
VK
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
68f384ea 15** You should have received a copy of the GNU Lesser General Public License
c25cb4a0
VK
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
cd4c8ca3 19** File: nxqueue.h
c25cb4a0
VK
20**
21**/
22
23#ifndef _nxqueue_h_
24#define _nxqueue_h_
25
b160350d 26#include <nms_util.h>
77312b6f 27
1499848d
VK
28/**
29 * Comparator for queue search
30 */
85f1fea1
VK
31typedef bool (*QUEUE_COMPARATOR)(void *key, void *object);
32
1499848d
VK
33/**
34 * Queue class
35 */
b160350d 36class LIBNETXMS_EXPORTABLE Queue
c25cb4a0
VK
37{
38private:
cd4c8ca3
VK
39 MUTEX m_mutexQueueAccess;
40 CONDITION m_condWakeup;
19dbc8ef
VK
41 void **m_elements;
42 UINT32 m_numElements;
43 UINT32 m_bufferSize;
44 UINT32 m_initialSize;
45 UINT32 m_first;
46 UINT32 m_last;
47 UINT32 m_bufferIncrement;
48 bool m_shutdownFlag;
c25cb4a0 49
1499848d
VK
50 void commonInit();
51 void lock() { MutexLock(m_mutexQueueAccess); }
52 void unlock() { MutexUnlock(m_mutexQueueAccess); }
19dbc8ef 53 void shrink();
c25cb4a0
VK
54
55public:
bb7a686c 56 Queue();
19dbc8ef 57 Queue(UINT32 initialSize, UINT32 bufferIncrement = 32);
c25cb4a0
VK
58 ~Queue();
59
19dbc8ef
VK
60 void put(void *object);
61 void insert(void *object);
62 void setShutdownMode();
63 void *get();
7e1816e5 64 void *getOrBlock(UINT32 timeout = INFINITE);
19dbc8ef
VK
65 int size() { return (int)m_numElements; }
66 int allocated() { return (int)m_bufferSize; }
67 void clear();
85f1fea1 68 void *find(void *key, QUEUE_COMPARATOR comparator);
46117060 69 bool remove(void *key, QUEUE_COMPARATOR comparator);
c25cb4a0
VK
70};
71
72#endif /* _nxqueue_h_ */