log4cplus  2.0.5
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 
73 
78  flags_type signal_exit (bool drain = true);
79 
80  // Consumer's methods.
81 
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
log4cplus::thread::Queue::signal_exit
flags_type signal_exit(bool drain=true)
Sets EXIT flag and DRAIN flag and sets internal event object into signaled state.
log4cplus
Definition: appender.h:46
log4cplus::thread::Queue
Single consumer, multiple producers queue.
Definition: queue.h:48
log4cplus::thread::Queue::flags
flags_type flags
State flags.
Definition: queue.h:142
log4cplus::helpers::SharedObjectPtr< Queue >
threads.h
log4cplus::thread::Queue::mutex
Mutex mutex
Mutex protecting queue and flags.
Definition: queue.h:133
log4cplus::thread::Queue::queue
queue_storage_type queue
Queue storage.
Definition: queue.h:130
log4cplus::thread::Queue::Queue
Queue(unsigned len=100)
log4cplus::thread::Queue::sem
Semaphore sem
Semaphore that limits the queue length.
Definition: queue.h:139
log4cplus::thread::Queue::get_events
flags_type get_events(queue_storage_type *buf)
The get_events() function is used by queue's consumer.
config.hxx
log4cplus::thread::ManualResetEvent
Definition: syncprims.h:107
loggingevent.h
log4cplus::thread::Queue::put_event
flags_type put_event(spi::InternalLoggingEvent const &ev)
Puts event ev into queue, sets QUEUE flag and sets internal event object into signaled state.
log4cplus::thread::Queue::queue_storage_type
std::deque< spi::InternalLoggingEvent > queue_storage_type
Queue storage type.
Definition: queue.h:54
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition: loggingevent.h:51
log4cplus::thread::QueuePtr
helpers::SharedObjectPtr< Queue > QueuePtr
Definition: queue.h:150
log4cplus::thread::Queue::flags_type
unsigned flags_type
Type of the state flags field.
Definition: queue.h:51
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition: win32.h:141
log4cplus::thread::Semaphore
Definition: syncprims.h:83
log4cplus::helpers::SharedObject
Definition: pointer.h:54
log4cplus::thread::Queue::ev_consumer
ManualResetEvent ev_consumer
Event on which consumer can wait if it finds queue empty.
Definition: queue.h:136
log4cplus::thread::Queue::Flags
Flags
Possible state flags.
Definition: queue.h:103
log4cplus::thread::Mutex
Definition: syncprims.h:64
log4cplus::thread::Queue::~Queue
virtual ~Queue()
syncprims.h