1
// ---------------------------------------------------------------------
2
// pion: a Boost C++ framework for building lightweight HTTP interfaces
3
// ---------------------------------------------------------------------
4
// Copyright (C) 2007-2012 Cloudmeter, Inc. (http://www.cloudmeter.com)
6
// Distributed under the Boost Software License, Version 1.0.
7
// See http://www.boost.org/LICENSE_1_0.txt
10
#ifndef __PION_PROCESS_HEADER__
11
#define __PION_PROCESS_HEADER__
14
#include <boost/noncopyable.hpp>
15
#include <boost/thread/once.hpp>
16
#include <boost/thread/mutex.hpp>
17
#include <boost/thread/condition.hpp>
18
#include <pion/config.hpp>
21
namespace pion { // begin namespace pion
24
/// process: class for managing process/service related functions
26
class PION_API process :
27
private boost::noncopyable
34
/// default constructor
37
/// signals the shutdown condition
38
static void shutdown(void);
40
/// blocks until the shutdown condition has been signaled
41
static void wait_for_shutdown(void);
43
/// sets up basic signal handling for the process
44
static void initialize(void);
46
/// fork process and run as a background daemon
47
static void daemonize(void);
52
/// data type for static/global process configuration information
54
/// constructor just initializes native types
55
config_type() : shutdown_now(false) {}
57
/// true if we should shutdown now
60
/// triggered when it is time to shutdown
61
boost::condition shutdown_cond;
63
/// used to protect the shutdown condition
64
boost::mutex shutdown_mutex;
68
/// returns a singleton instance of config_type
69
static inline config_type& get_config(void) {
70
boost::call_once(process::create_config, m_instance_flag);
77
/// creates the config_type singleton
78
static void create_config(void);
81
/// used to ensure thread safety of the config_type singleton
82
static boost::once_flag m_instance_flag;
84
/// pointer to the config_type singleton
85
static config_type * m_config_ptr;
89
} // end namespace pion