queue.h
Go to the documentation of this file.
// -*- C++ -*-
// Copyright (C) 2009-2017, Vaclav Haisman. All rights reserved.
//
// Redistribution and use in source and binary forms, with or without modifica-
// tion, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
// APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
// DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
// ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
// THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef LOG4CPLUS_HELPERS_QUEUE_H
#define LOG4CPLUS_HELPERS_QUEUE_H
#include <log4cplus/config.hxx>
#if defined (LOG4CPLUS_HAVE_PRAGMA_ONCE)
#pragma once
#endif
#if ! defined (LOG4CPLUS_SINGLE_THREADED)
#include <deque>
#include <log4cplus/spi/loggingevent.h>
#include <log4cplus/thread/threads.h>
#include <log4cplus/thread/syncprims.h>
namespace log4cplus { namespace thread {
class LOG4CPLUS_EXPORT Queue
: public virtual helpers::SharedObject
{
public:
typedef unsigned flags_type;
typedef std::deque<spi::InternalLoggingEvent> queue_storage_type;
explicit Queue (unsigned len = 100);
virtual ~Queue ();
// Producers' methods.
flags_type put_event (spi::InternalLoggingEvent const & ev);
flags_type signal_exit (bool drain = true);
// Consumer's methods.
flags_type get_events (queue_storage_type * buf);
enum Flags
{
EVENT = 0x0001,
QUEUE = 0x0002,
EXIT = 0x0004,
DRAIN = 0x0008,
ERROR_BIT = 0x0010,
ERROR_AFTER = 0x0020
};
protected:
queue_storage_type queue;
Mutex mutex;
ManualResetEvent ev_consumer;
Semaphore sem;
flags_type flags;
private:
Queue (Queue const &);
Queue & operator = (Queue const &);
};
typedef helpers::SharedObjectPtr<Queue> QueuePtr;
} } // namespace log4cplus { namespace thread {
#endif // LOG4CPLUS_SINGLE_THREADED
#endif // LOG4CPLUS_HELPERS_QUEUE_H
log4cplus::helpers::SharedObjectPtr
Definition pointer.h:101
log4cplus::helpers::SharedObject
Definition pointer.h:54
log4cplus::spi::InternalLoggingEvent
The internal representation of logging events.
Definition loggingevent.h:51
log4cplus::thread::ManualResetEvent
Definition syncprims.h:126
log4cplus::thread::Mutex
Definition syncprims.h:83
log4cplus::thread::Queue::sem
Semaphore sem
Semaphore that limits the queue length.
Definition queue.h:139
log4cplus::thread::Queue::signal_exit
flags_type signal_exit(bool drain=true)
log4cplus::thread::Queue::Queue
Queue(unsigned len=100)
log4cplus::thread::Queue::queue
queue_storage_type queue
Queue storage.
Definition queue.h:130
log4cplus::thread::Queue::flags_type
unsigned flags_type
Type of the state flags field.
Definition queue.h:51
log4cplus::thread::Queue::Flags
Flags
Possible state flags.
Definition queue.h:103
log4cplus::thread::Queue::DRAIN
@ DRAIN
Definition queue.h:118
log4cplus::thread::Queue::ERROR_AFTER
@ ERROR_AFTER
Definition queue.h:125
log4cplus::thread::Queue::QUEUE
@ QUEUE
Definition queue.h:110
log4cplus::thread::Queue::EVENT
@ EVENT
Definition queue.h:106
log4cplus::thread::Queue::EXIT
@ EXIT
Definition queue.h:114
log4cplus::thread::Queue::ERROR_BIT
@ ERROR_BIT
ERROR_BIT signals error.
Definition queue.h:121
log4cplus::thread::Queue::put_event
flags_type put_event(spi::InternalLoggingEvent const &ev)
log4cplus::thread::Queue::get_events
flags_type get_events(queue_storage_type *buf)
log4cplus::thread::Queue::flags
flags_type flags
State flags.
Definition queue.h:142
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::~Queue
virtual ~Queue()
log4cplus::thread::Queue::queue_storage_type
std::deque< spi::InternalLoggingEvent > queue_storage_type
Queue storage type.
Definition queue.h:54
log4cplus::thread::Queue::mutex
Mutex mutex
Mutex protecting queue and flags.
Definition queue.h:133
log4cplus::thread::Semaphore
Definition syncprims.h:102
config.hxx
loggingevent.h
log4cplus::thread
Definition queue.h:42
log4cplus::thread::QueuePtr
helpers::SharedObjectPtr< Queue > QueuePtr
Definition queue.h:150
log4cplus
Definition appender.h:46
syncprims.h
threads.h
LOG4CPLUS_EXPORT
#define LOG4CPLUS_EXPORT
Definition win32.h:141