log4cplus  2.0.0
queue.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 // Copyright (C) 2009-2017, Vaclav Haisman. All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without modifica-
5 // tion, are permitted provided that the following conditions are met:
6 //
7 // 1. Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 //
10 // 2. Redistributions in binary form must reproduce the above copyright notice,
11 // this list of conditions and the following disclaimer in the documentation
12 // and/or other materials provided with the distribution.
13 //
14 // THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
15 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 // FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
17 // APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
18 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
19 // DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
20 // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
21 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 
25 #ifndef LOG4CPLUS_HELPERS_QUEUE_H
26 #define LOG4CPLUS_HELPERS_QUEUE_H
27 
28 #include <log4cplus/config.hxx>
29 
30 #if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
31 #pragma once
32 #endif
33 
34 #if ! defined (LOG4CPLUS_SINGLE_THREADED)
35 
36 #include <deque>
40 
41 
42 namespace log4cplus { namespace thread {
43 
44 
47  : public virtual helpers::SharedObject
48 {
49 public:
51  typedef unsigned flags_type;
52 
54  typedef std::deque<spi::InternalLoggingEvent> queue_storage_type;
55 
56  explicit Queue (unsigned len = 100);
57  virtual ~Queue ();
58 
59  // Producers' methods.
60 
72  flags_type put_event (spi::InternalLoggingEvent const & ev);
73 
78  flags_type signal_exit (bool drain = true);
79 
80  // Consumer's methods.
81 
99  flags_type get_events (queue_storage_type * buf);
100 
102  enum Flags
103  {
106  EVENT = 0x0001,
107 
110  QUEUE = 0x0002,
111 
114  EXIT = 0x0004,
115 
118  DRAIN = 0x0008,
119 
121  ERROR_BIT = 0x0010,
122 
125  ERROR_AFTER = 0x0020
126  };
127 
128 protected:
131 
134 
137 
140 
143 
144 private:
145  Queue (Queue const &);
146  Queue & operator = (Queue const &);
147 };
148 
149 
151 
152 
153 } } // namespace log4cplus { namespace thread {
154 
155 
156 #endif // LOG4CPLUS_SINGLE_THREADED
157 
158 #endif // LOG4CPLUS_HELPERS_QUEUE_H
ManualResetEvent ev_consumer
Event on which consumer can wait if it finds queue empty.
Definition: queue.h:136
The internal representation of logging events.
Definition: loggingevent.h:51
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
queue_storage_type queue
Queue storage.
Definition: queue.h:130
unsigned flags_type
Type of the state flags field.
Definition: queue.h:51
Single consumer, multiple producers queue.
Definition: queue.h:46
helpers::SharedObjectPtr< Queue > QueuePtr
Definition: queue.h:150
Semaphore sem
Semaphore that limits the queue length.
Definition: queue.h:139
Flags
Possible state flags.
Definition: queue.h:102
Mutex mutex
Mutex protecting queue and flags.
Definition: queue.h:133
std::deque< spi::InternalLoggingEvent > queue_storage_type
Queue storage type.
Definition: queue.h:54
flags_type flags
State flags.
Definition: queue.h:142