unicode.cpp refactoring started.
[public/netxms.git] / include / nxqueue.h
CommitLineData
c25cb4a0
VK
1/*
2** NetXMS - Network Management System
68f384ea 3** Copyright (C) 2003-2010 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
c25cb4a0
VK
28
29//
30// Queue class
31//
32
85f1fea1
VK
33typedef bool (*QUEUE_COMPARATOR)(void *key, void *object);
34
b160350d 35class LIBNETXMS_EXPORTABLE Queue
c25cb4a0
VK
36{
37private:
cd4c8ca3
VK
38 MUTEX m_mutexQueueAccess;
39 CONDITION m_condWakeup;
c25cb4a0 40 void **m_pElements;
967893bb
VK
41 UINT32 m_dwNumElements;
42 UINT32 m_dwBufferSize;
43 UINT32 m_dwFirst;
44 UINT32 m_dwLast;
45 UINT32 m_dwBufferIncrement;
25c85230 46 BOOL m_bShutdownFlag;
c25cb4a0 47
c17f6cbc
VK
48 void CommonInit();
49 void Lock() { MutexLock(m_mutexQueueAccess); }
25c85230 50 void Unlock() { MutexUnlock(m_mutexQueueAccess); }
c25cb4a0
VK
51
52public:
bb7a686c 53 Queue();
967893bb 54 Queue(UINT32 dwInitialSize, UINT32 dwBufferIncrement = 32);
c25cb4a0
VK
55 ~Queue();
56
57 void Put(void *pObject);
25c85230
VK
58 void Insert(void *pObject);
59 void SetShutdownMode();
60 void *Get();
61 void *GetOrBlock();
967893bb 62 UINT32 Size() { return m_dwNumElements; }
25c85230 63 void Clear();
85f1fea1 64 void *find(void *key, QUEUE_COMPARATOR comparator);
46117060 65 bool remove(void *key, QUEUE_COMPARATOR comparator);
c25cb4a0
VK
66};
67
68#endif /* _nxqueue_h_ */