bottleneck testcase based on rubbos
[bottlenecks.git] / rubbos / app / httpd-2.0.64 / include / ap_mpm.h
1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2  * contributor license agreements.  See the NOTICE file distributed with
3  * this work for additional information regarding copyright ownership.
4  * The ASF licenses this file to You under the Apache License, Version 2.0
5  * (the "License"); you may not use this file except in compliance with
6  * the License.  You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef AP_MPM_H
18 #define AP_MPM_H
19
20 #include "apr_thread_proc.h"
21
22 /**
23  * @package Multi-Processing Module library
24  */
25
26 /*
27     The MPM, "multi-processing model" provides an abstraction of the
28     interface with the OS for distributing incoming connections to
29     threads/process for processing.  http_main invokes the MPM, and
30     the MPM runs until a shutdown/restart has been indicated.
31     The MPM calls out to the apache core via the ap_process_connection
32     function when a connection arrives.
33
34     The MPM may or may not be multithreaded.  In the event that it is
35     multithreaded, at any instant it guarantees a 1:1 mapping of threads
36     ap_process_connection invocations.  
37
38     Note: In the future it will be possible for ap_process_connection
39     to return to the MPM prior to finishing the entire connection; and
40     the MPM will proceed with asynchronous handling for the connection;
41     in the future the MPM may call ap_process_connection again -- but
42     does not guarantee it will occur on the same thread as the first call.
43
44     The MPM further guarantees that no asynchronous behaviour such as
45     longjmps and signals will interfere with the user code that is
46     invoked through ap_process_connection.  The MPM may reserve some
47     signals for its use (i.e. SIGUSR1), but guarantees that these signals
48     are ignored when executing outside the MPM code itself.  (This
49     allows broken user code that does not handle EINTR to function
50     properly.)
51
52     The suggested server restart and stop behaviour will be "graceful".
53     However the MPM may choose to terminate processes when the user
54     requests a non-graceful restart/stop.  When this occurs, the MPM kills
55     all threads with extreme prejudice, and destroys the pchild pool.
56     User cleanups registered in the pchild apr_pool_t will be invoked at
57     this point.  (This can pose some complications, the user cleanups
58     are asynchronous behaviour not unlike longjmp/signal... but if the
59     admin is asking for a non-graceful shutdown, how much effort should
60     we put into doing it in a nice way?)
61
62     unix/posix notes:
63     - The MPM does not set a SIGALRM handler, user code may use SIGALRM.
64         But the preferred method of handling timeouts is to use the
65         timeouts provided by the BUFF abstraction.
66     - The proper setting for SIGPIPE is SIG_IGN, if user code changes it
67         for any of their own processing, it must be restored to SIG_IGN
68         prior to executing or returning to any apache code.
69     TODO: add SIGPIPE debugging check somewhere to make sure it's SIG_IGN
70 */
71
72 /**
73  * This is the function that MPMs must create.  This function is responsible
74  * for controlling the parent and child processes.  It will run until a 
75  * restart/shutdown is indicated.
76  * @param pconf the configuration pool, reset before the config file is read
77  * @param plog the log pool, reset after the config file is read
78  * @param server_conf the global server config.
79  * @return 1 for shutdown 0 otherwise.
80  * @deffunc int ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf)
81  */
82 AP_DECLARE(int) ap_mpm_run(apr_pool_t *pconf, apr_pool_t *plog, server_rec *server_conf);
83
84 /**
85  * predicate indicating if a graceful stop has been requested ...
86  * used by the connection loop 
87  * @return 1 if a graceful stop has been requested, 0 otherwise
88  * @deffunc int ap_graceful_stop_signalled(*void)
89  */
90 AP_DECLARE(int) ap_graceful_stop_signalled(void);
91
92 /**
93  * Spawn a process with privileges that another module has requested
94  * @param r The request_rec of the current request
95  * @param newproc The resulting process handle.
96  * @param progname The program to run 
97  * @param const_args the arguments to pass to the new program.  The first 
98  *                   one should be the program name.
99  * @param env The new environment apr_table_t for the new process.  This 
100  *            should be a list of NULL-terminated strings.
101  * @param attr the procattr we should use to determine how to create the new
102  *         process
103  * @param p The pool to use. 
104  */
105 AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
106     const request_rec *r,
107     apr_proc_t *newproc, 
108     const char *progname,
109     const char * const *args, 
110     const char * const *env,
111     apr_procattr_t *attr, 
112     apr_pool_t *p);
113
114 /* Subtypes/Values for AP_MPMQ_IS_THREADED and AP_MPMQ_IS_FORKED        */
115 #define AP_MPMQ_NOT_SUPPORTED      0  /* This value specifies whether */
116                                       /* an MPM is capable of         */
117                                       /* threading or forking.        */
118 #define AP_MPMQ_STATIC             1  /* This value specifies whether */
119                                       /* an MPM is using a static #   */
120                                       /* threads or daemons.          */
121 #define AP_MPMQ_DYNAMIC            2  /* This value specifies whether */
122                                       /* an MPM is using a dynamic #  */
123                                       /* threads or daemons.          */
124
125 /* Values returned for AP_MPMQ_MPM_STATE */
126 #define AP_MPMQ_STARTING              0
127 #define AP_MPMQ_RUNNING               1
128 #define AP_MPMQ_STOPPING              2
129
130 #define AP_MPMQ_MAX_DAEMON_USED       1  /* Max # of daemons used so far */
131 #define AP_MPMQ_IS_THREADED           2  /* MPM can do threading         */
132 #define AP_MPMQ_IS_FORKED             3  /* MPM can do forking           */
133 #define AP_MPMQ_HARD_LIMIT_DAEMONS    4  /* The compiled max # daemons   */
134 #define AP_MPMQ_HARD_LIMIT_THREADS    5  /* The compiled max # threads   */
135 #define AP_MPMQ_MAX_THREADS           6  /* # of threads/child by config */
136 #define AP_MPMQ_MIN_SPARE_DAEMONS     7  /* Min # of spare daemons       */
137 #define AP_MPMQ_MIN_SPARE_THREADS     8  /* Min # of spare threads       */
138 #define AP_MPMQ_MAX_SPARE_DAEMONS     9  /* Max # of spare daemons       */
139 #define AP_MPMQ_MAX_SPARE_THREADS    10  /* Max # of spare threads       */
140 #define AP_MPMQ_MAX_REQUESTS_DAEMON  11  /* Max # of requests per daemon */
141 #define AP_MPMQ_MAX_DAEMONS          12  /* Max # of daemons by config   */
142 #define AP_MPMQ_MPM_STATE            13  /* starting, running, stopping  */
143
144 /**
145  * Query a property of the current MPM.  
146  * @param query_code One of APM_MPMQ_*
147  * @param result A location to place the result of the query
148  * @return APR_SUCCESS or APR_ENOTIMPL
149  * @deffunc int ap_mpm_query(int query_code, int *result)
150  */
151 AP_DECLARE(apr_status_t) ap_mpm_query(int query_code, int *result);
152
153 /* Defining GPROF when compiling uses the moncontrol() function to
154  * disable gprof profiling in the parent, and enable it only for
155  * request processing in children (or in one_process mode).  It's
156  * absolutely required to get useful gprof results under linux
157  * because the profile itimers and such are disabled across a
158  * fork().  It's probably useful elsewhere as well.
159  */
160 #ifdef GPROF
161 extern void moncontrol(int);
162 #define AP_MONCONTROL(x) moncontrol(x)
163 #else
164 #define AP_MONCONTROL(x)
165 #endif
166
167 #if AP_ENABLE_EXCEPTION_HOOK
168 typedef struct ap_exception_info_t {
169     int sig;
170     pid_t pid;
171 } ap_exception_info_t;
172
173 AP_DECLARE_HOOK(int,fatal_exception,(ap_exception_info_t *ei))
174 #endif /*AP_ENABLE_EXCEPTION_HOOK*/
175
176 #endif