Main Page | Modules | Data Structures | File List | Data Fields | Globals | Related Pages

apr_thread_proc.h

Go to the documentation of this file.
00001 /* ====================================================================
00002  * The Apache Software License, Version 1.1
00003  *
00004  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
00005  * reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  *
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in
00016  *    the documentation and/or other materials provided with the
00017  *    distribution.
00018  *
00019  * 3. The end-user documentation included with the redistribution,
00020  *    if any, must include the following acknowledgment:
00021  *       "This product includes software developed by the
00022  *        Apache Software Foundation (http://www.apache.org/)."
00023  *    Alternately, this acknowledgment may appear in the software itself,
00024  *    if and wherever such third-party acknowledgments normally appear.
00025  *
00026  * 4. The names "Apache" and "Apache Software Foundation" must
00027  *    not be used to endorse or promote products derived from this
00028  *    software without prior written permission. For written
00029  *    permission, please contact apache@apache.org.
00030  *
00031  * 5. Products derived from this software may not be called "Apache",
00032  *    nor may "Apache" appear in their name, without prior written
00033  *    permission of the Apache Software Foundation.
00034  *
00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00046  * SUCH DAMAGE.
00047  * ====================================================================
00048  *
00049  * This software consists of voluntary contributions made by many
00050  * individuals on behalf of the Apache Software Foundation.  For more
00051  * information on the Apache Software Foundation, please see
00052  * <http://www.apache.org/>.
00053  */
00054 
00055 #ifndef APR_THREAD_PROC_H
00056 #define APR_THREAD_PROC_H
00057 
00063 #include "apr.h"
00064 #include "apr_file_io.h"
00065 #include "apr_pools.h"
00066 #include "apr_errno.h"
00067 
00068 #if APR_HAVE_STRUCT_RLIMIT
00069 #include <sys/time.h>
00070 #include <sys/resource.h>
00071 #endif
00072 
00073 #ifdef __cplusplus
00074 extern "C" {
00075 #endif /* __cplusplus */
00076 
00083 typedef enum {
00084     APR_SHELLCMD,       
00085     APR_PROGRAM,        
00086     APR_PROGRAM_ENV,    
00087     APR_PROGRAM_PATH    
00088 } apr_cmdtype_e;
00089 
00090 typedef enum {
00091     APR_WAIT,           
00092     APR_NOWAIT          
00093 } apr_wait_how_e;
00094 
00095 /* I am specifically calling out the values so that the macros below make
00096  * more sense.  Yes, I know I don't need to, but I am hoping this makes what
00097  * I am doing more clear.  If you want to add more reasons to exit, continue
00098  * to use bitmasks.
00099  */
00100 typedef enum {
00101     APR_PROC_EXIT = 1,          
00102     APR_PROC_SIGNAL = 2,        
00103     APR_PROC_SIGNAL_CORE = 4    
00104 } apr_exit_why_e;
00105 
00107 #define APR_PROC_CHECK_EXIT(x)        (x & APR_PROC_EXIT)
00108 
00109 #define APR_PROC_CHECK_SIGNALED(x)    (x & APR_PROC_SIGNAL)
00110 
00111 #define APR_PROC_CHECK_CORE_DUMP(x)   (x & APR_PROC_SIGNAL_CORE)
00112 
00114 #define APR_NO_PIPE          0
00115 
00117 #define APR_FULL_BLOCK       1
00118 
00119 #define APR_FULL_NONBLOCK    2
00120 
00121 #define APR_PARENT_BLOCK     3
00122 
00123 #define APR_CHILD_BLOCK      4
00124 
00126 #define APR_LIMIT_CPU        0
00127 
00128 #define APR_LIMIT_MEM        1
00129 
00130 #define APR_LIMIT_NPROC      2
00131 
00132 #define APR_LIMIT_NOFILE     3
00133 
00138 #define APR_OC_REASON_DEATH         0     
00140 #define APR_OC_REASON_UNWRITABLE    1     
00141 #define APR_OC_REASON_RESTART       2     
00145 #define APR_OC_REASON_UNREGISTER    3     
00148 #define APR_OC_REASON_LOST          4     
00150 #define APR_OC_REASON_RUNNING       5     
00157 typedef struct apr_proc_t {
00158 
00159     pid_t pid;
00161     apr_file_t *in;
00163     apr_file_t *out;
00165     apr_file_t *err;
00166 #if APR_HAS_PROC_INVOKED || defined(DOXYGEN)
00167 
00174     char *invoked;
00175 #endif
00176 #if defined(WIN32) || defined(DOXYGEN)
00177 
00183     HANDLE hproc;
00184 #endif
00185 } apr_proc_t;
00186 
00197 typedef void (apr_child_errfn_t)(apr_pool_t *proc, apr_status_t err,
00198                                  const char *description);
00199 
00201 typedef struct apr_thread_t           apr_thread_t;
00202 
00204 typedef struct apr_threadattr_t       apr_threadattr_t;
00205 
00207 typedef struct apr_procattr_t         apr_procattr_t;
00208 
00210 typedef struct apr_thread_once_t      apr_thread_once_t;
00211 
00213 typedef struct apr_threadkey_t        apr_threadkey_t;
00214 
00216 typedef struct apr_other_child_rec_t  apr_other_child_rec_t;
00217 
00221 typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*);
00222 
00223 typedef enum {
00224     APR_KILL_NEVER,             
00225     APR_KILL_ALWAYS,            
00226     APR_KILL_AFTER_TIMEOUT,     
00227     APR_JUST_WAIT,              
00228     APR_KILL_ONLY_ONCE          
00229 } apr_kill_conditions_e;
00230 
00231 /* Thread Function definitions */
00232 
00233 #if APR_HAS_THREADS
00234 
00240 APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr, 
00241                                                 apr_pool_t *cont);
00242 
00248 APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr, 
00249                                                    apr_int32_t on);
00250 
00255 APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr);
00256 
00265 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread, 
00266                                             apr_threadattr_t *attr, 
00267                                             apr_thread_start_t func, 
00268                                             void *data, apr_pool_t *cont);
00269 
00275 APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, 
00276                                           apr_status_t retval);
00277 
00283 APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, 
00284                                           apr_thread_t *thd); 
00285 
00289 APR_DECLARE(void) apr_thread_yield(void);
00290 
00297 APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
00298                                                apr_pool_t *p);
00299 
00309 APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
00310                                           void (*func)(void));
00311 
00316 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd);
00317 
00324 APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
00325                                              apr_thread_t *thread);
00326 
00334 APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
00335                                              apr_status_t (*cleanup) (void *),
00336                                              apr_thread_t *thread);
00337 
00344 APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key, 
00345                                                     void (*dest)(void *),
00346                                                     apr_pool_t *cont);
00347 
00353 APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem, 
00354                                                  apr_threadkey_t *key);
00355 
00361 APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, 
00362                                                  apr_threadkey_t *key);
00363 
00368 APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key);
00369 
00376 APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
00377                                                 apr_threadkey_t *threadkey);
00378 
00386 APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
00387                                                 apr_status_t (*cleanup) (void *),
00388                                                 apr_threadkey_t *threadkey);
00389 
00390 #endif
00391 
00397 APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new_attr,
00398                                                   apr_pool_t *cont);
00399 
00408 APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, 
00409                                              apr_int32_t in, apr_int32_t out,
00410                                              apr_int32_t err);
00411 
00424 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(struct apr_procattr_t *attr,
00425                                                   apr_file_t *child_in,
00426                                                   apr_file_t *parent_in);
00427 
00438 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(struct apr_procattr_t *attr,
00439                                                    apr_file_t *child_out,
00440                                                    apr_file_t *parent_out);
00441 
00452 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(struct apr_procattr_t *attr,
00453                                                    apr_file_t *child_err,
00454                                                    apr_file_t *parent_err);
00455 
00463 APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr, 
00464                                               const char *dir);
00465 
00477 APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
00478                                                   apr_cmdtype_e cmd);
00479 
00485 APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, 
00486                                                  apr_int32_t detach);
00487 
00488 #if APR_HAVE_STRUCT_RLIMIT
00489 
00501 APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, 
00502                                                 apr_int32_t what,
00503                                                 struct rlimit *limit);
00504 #endif
00505 
00517 APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr,
00518                                                        apr_child_errfn_t *errfn);
00519 
00532 APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr,
00533                                                        apr_int32_t chk);
00534 
00535 #if APR_HAS_FORK
00536 
00542 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont);
00543 #endif
00544 
00559 APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new_proc,
00560                                              const char *progname,
00561                                              const char * const *args,
00562                                              const char * const *env, 
00563                                              apr_procattr_t *attr, 
00564                                              apr_pool_t *cont);
00565 
00592 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
00593                                         int *exitcode, apr_exit_why_e *exitwhy,
00594                                         apr_wait_how_e waithow);
00595 
00622 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
00623                                                   int *exitcode,
00624                                                   apr_exit_why_e *exitwhy,
00625                                                   apr_wait_how_e waithow,
00626                                                   apr_pool_t *p);
00627 
00628 #define APR_PROC_DETACH_FOREGROUND 0    
00629 #define APR_PROC_DETACH_DAEMONIZE 1     
00637 APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize);
00638 
00656 APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc, 
00657                                            void (*maintenance) (int reason, 
00658                                                                 void *, 
00659                                                                 int status),
00660                                            void *data, apr_file_t *write_fd,
00661                                            apr_pool_t *p);
00662 
00672 APR_DECLARE(void) apr_proc_other_child_unregister(void *data);
00673 
00694 APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc, 
00695                                                      int reason,
00696                                                      int status);
00697 
00705 APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
00706                                                int reason);
00707 
00714 APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason);
00715 
00722 APR_DECLARE(void) apr_proc_other_child_check(void);
00723 
00727 APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *proc, int status);
00728 
00729 
00735 APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int sig);
00736 
00750 APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc,
00751                                            apr_kill_conditions_e how);
00752 
00753 #if APR_HAS_THREADS 
00754 
00755 #if (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2)
00756 
00761 APR_DECLARE(apr_status_t) apr_setup_signal_thread(void);
00762 
00770 APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum));
00771 
00772 #endif /* (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2) */
00773 
00778 APR_POOL_DECLARE_ACCESSOR(thread);
00779 
00780 #endif /* APR_HAS_THREADS */
00781 
00784 #ifdef __cplusplus
00785 }
00786 #endif
00787 
00788 #endif  /* ! APR_THREAD_PROC_H */
00789 

Generated on Thu May 27 00:41:27 2004 for Apache Portable Runtime by doxygen 1.3.4