syslog message write to database optimized
[public/netxms.git] / include / nxqueue.h
1 /*
2 ** NetXMS - Network Management System
3 ** Copyright (C) 2003-2013 Victor Kirhenshtein
4 **
5 ** This program is free software; you can redistribute it and/or modify
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
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 **
15 ** You should have received a copy of the GNU Lesser General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 **
19 ** File: nxqueue.h
20 **
21 **/
22
23 #ifndef _nxqueue_h_
24 #define _nxqueue_h_
25
26 #include <nms_util.h>
27
28 /**
29 * Comparator for queue search
30 */
31 typedef bool (*QUEUE_COMPARATOR)(void *key, void *object);
32
33 /**
34 * Queue class
35 */
36 class LIBNETXMS_EXPORTABLE Queue
37 {
38 private:
39 MUTEX m_mutexQueueAccess;
40 CONDITION m_condWakeup;
41 void **m_pElements;
42 UINT32 m_dwNumElements;
43 UINT32 m_dwBufferSize;
44 UINT32 m_dwFirst;
45 UINT32 m_dwLast;
46 UINT32 m_dwBufferIncrement;
47 BOOL m_bShutdownFlag;
48
49 void commonInit();
50 void lock() { MutexLock(m_mutexQueueAccess); }
51 void unlock() { MutexUnlock(m_mutexQueueAccess); }
52
53 public:
54 Queue();
55 Queue(UINT32 dwInitialSize, UINT32 dwBufferIncrement = 32);
56 ~Queue();
57
58 void Put(void *pObject);
59 void Insert(void *pObject);
60 void SetShutdownMode();
61 void *Get();
62 void *GetOrBlock();
63 UINT32 Size() { return m_dwNumElements; }
64 void Clear();
65 void *find(void *key, QUEUE_COMPARATOR comparator);
66 bool remove(void *key, QUEUE_COMPARATOR comparator);
67 };
68
69 #endif /* _nxqueue_h_ */