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

apr_thread_proc.h

Go to the documentation of this file.
00001 /* Copyright 2000-2004 The Apache Software Foundation
00002  *
00003  * Licensed under the Apache License, Version 2.0 (the "License");
00004  * you may not use this file except in compliance with the License.
00005  * You may obtain a copy of the License at
00006  *
00007  *     http://www.apache.org/licenses/LICENSE-2.0
00008  *
00009  * Unless required by applicable law or agreed to in writing, software
00010  * distributed under the License is distributed on an "AS IS" BASIS,
00011  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00012  * See the License for the specific language governing permissions and
00013  * limitations under the License.
00014  */
00015 
00016 #ifndef APR_THREAD_PROC_H
00017 #define APR_THREAD_PROC_H
00018 
00024 #include "apr.h"
00025 #include "apr_file_io.h"
00026 #include "apr_pools.h"
00027 #include "apr_errno.h"
00028 
00029 #if APR_HAVE_STRUCT_RLIMIT
00030 #include <sys/time.h>
00031 #include <sys/resource.h>
00032 #endif
00033 
00034 #ifdef __cplusplus
00035 extern "C" {
00036 #endif /* __cplusplus */
00037 
00044 typedef enum {
00045     APR_SHELLCMD,       
00046     APR_PROGRAM,        
00047     APR_PROGRAM_ENV,    
00048     APR_PROGRAM_PATH    
00049 } apr_cmdtype_e;
00050 
00051 typedef enum {
00052     APR_WAIT,           
00053     APR_NOWAIT          
00054 } apr_wait_how_e;
00055 
00056 /* I am specifically calling out the values so that the macros below make
00057  * more sense.  Yes, I know I don't need to, but I am hoping this makes what
00058  * I am doing more clear.  If you want to add more reasons to exit, continue
00059  * to use bitmasks.
00060  */
00061 typedef enum {
00062     APR_PROC_EXIT = 1,          
00063     APR_PROC_SIGNAL = 2,        
00064     APR_PROC_SIGNAL_CORE = 4    
00065 } apr_exit_why_e;
00066 
00068 #define APR_PROC_CHECK_EXIT(x)        (x & APR_PROC_EXIT)
00069 
00070 #define APR_PROC_CHECK_SIGNALED(x)    (x & APR_PROC_SIGNAL)
00071 
00072 #define APR_PROC_CHECK_CORE_DUMP(x)   (x & APR_PROC_SIGNAL_CORE)
00073 
00075 #define APR_NO_PIPE          0
00076 
00078 #define APR_FULL_BLOCK       1
00079 
00080 #define APR_FULL_NONBLOCK    2
00081 
00082 #define APR_PARENT_BLOCK     3
00083 
00084 #define APR_CHILD_BLOCK      4
00085 
00087 #define APR_LIMIT_CPU        0
00088 
00089 #define APR_LIMIT_MEM        1
00090 
00091 #define APR_LIMIT_NPROC      2
00092 
00093 #define APR_LIMIT_NOFILE     3
00094 
00099 #define APR_OC_REASON_DEATH         0     
00101 #define APR_OC_REASON_UNWRITABLE    1     
00102 #define APR_OC_REASON_RESTART       2     
00106 #define APR_OC_REASON_UNREGISTER    3     
00109 #define APR_OC_REASON_LOST          4     
00111 #define APR_OC_REASON_RUNNING       5     
00118 typedef struct apr_proc_t {
00119 
00120     pid_t pid;
00122     apr_file_t *in;
00124     apr_file_t *out;
00126     apr_file_t *err;
00127 #if APR_HAS_PROC_INVOKED || defined(DOXYGEN)
00128 
00135     char *invoked;
00136 #endif
00137 #if defined(WIN32) || defined(DOXYGEN)
00138 
00144     HANDLE hproc;
00145 #endif
00146 } apr_proc_t;
00147 
00158 typedef void (apr_child_errfn_t)(apr_pool_t *proc, apr_status_t err,
00159                                  const char *description);
00160 
00162 typedef struct apr_thread_t           apr_thread_t;
00163 
00165 typedef struct apr_threadattr_t       apr_threadattr_t;
00166 
00168 typedef struct apr_procattr_t         apr_procattr_t;
00169 
00171 typedef struct apr_thread_once_t      apr_thread_once_t;
00172 
00174 typedef struct apr_threadkey_t        apr_threadkey_t;
00175 
00177 typedef struct apr_other_child_rec_t  apr_other_child_rec_t;
00178 
00182 typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(apr_thread_t*, void*);
00183 
00184 typedef enum {
00185     APR_KILL_NEVER,             
00186     APR_KILL_ALWAYS,            
00187     APR_KILL_AFTER_TIMEOUT,     
00188     APR_JUST_WAIT,              
00189     APR_KILL_ONLY_ONCE          
00190 } apr_kill_conditions_e;
00191 
00192 /* Thread Function definitions */
00193 
00194 #if APR_HAS_THREADS
00195 
00201 APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr, 
00202                                                 apr_pool_t *cont);
00203 
00209 APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr, 
00210                                                    apr_int32_t on);
00211 
00216 APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr);
00217 
00223 APR_DECLARE(apr_status_t) apr_threadattr_stacksize_set(apr_threadattr_t *attr,
00224                                                        apr_size_t stacksize);
00225 
00236 APR_DECLARE(apr_status_t) apr_threadattr_guardsize_set(apr_threadattr_t *attr,
00237                                                        apr_size_t guardsize);
00238 
00247 APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread, 
00248                                             apr_threadattr_t *attr, 
00249                                             apr_thread_start_t func, 
00250                                             void *data, apr_pool_t *cont);
00251 
00257 APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, 
00258                                           apr_status_t retval);
00259 
00265 APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, 
00266                                           apr_thread_t *thd); 
00267 
00271 APR_DECLARE(void) apr_thread_yield(void);
00272 
00279 APR_DECLARE(apr_status_t) apr_thread_once_init(apr_thread_once_t **control,
00280                                                apr_pool_t *p);
00281 
00291 APR_DECLARE(apr_status_t) apr_thread_once(apr_thread_once_t *control,
00292                                           void (*func)(void));
00293 
00298 APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd);
00299 
00306 APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key,
00307                                              apr_thread_t *thread);
00308 
00316 APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key,
00317                                              apr_status_t (*cleanup) (void *),
00318                                              apr_thread_t *thread);
00319 
00326 APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key, 
00327                                                     void (*dest)(void *),
00328                                                     apr_pool_t *cont);
00329 
00335 APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem, 
00336                                                  apr_threadkey_t *key);
00337 
00343 APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, 
00344                                                  apr_threadkey_t *key);
00345 
00350 APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key);
00351 
00358 APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key,
00359                                                 apr_threadkey_t *threadkey);
00360 
00368 APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key,
00369                                                 apr_status_t (*cleanup) (void *),
00370                                                 apr_threadkey_t *threadkey);
00371 
00372 #endif
00373 
00379 APR_DECLARE(apr_status_t) apr_procattr_create(apr_procattr_t **new_attr,
00380                                                   apr_pool_t *cont);
00381 
00390 APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr, 
00391                                              apr_int32_t in, apr_int32_t out,
00392                                              apr_int32_t err);
00393 
00406 APR_DECLARE(apr_status_t) apr_procattr_child_in_set(struct apr_procattr_t *attr,
00407                                                   apr_file_t *child_in,
00408                                                   apr_file_t *parent_in);
00409 
00420 APR_DECLARE(apr_status_t) apr_procattr_child_out_set(struct apr_procattr_t *attr,
00421                                                    apr_file_t *child_out,
00422                                                    apr_file_t *parent_out);
00423 
00434 APR_DECLARE(apr_status_t) apr_procattr_child_err_set(struct apr_procattr_t *attr,
00435                                                    apr_file_t *child_err,
00436                                                    apr_file_t *parent_err);
00437 
00445 APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr, 
00446                                               const char *dir);
00447 
00459 APR_DECLARE(apr_status_t) apr_procattr_cmdtype_set(apr_procattr_t *attr,
00460                                                   apr_cmdtype_e cmd);
00461 
00467 APR_DECLARE(apr_status_t) apr_procattr_detach_set(apr_procattr_t *attr, 
00468                                                  apr_int32_t detach);
00469 
00470 #if APR_HAVE_STRUCT_RLIMIT
00471 
00483 APR_DECLARE(apr_status_t) apr_procattr_limit_set(apr_procattr_t *attr, 
00484                                                 apr_int32_t what,
00485                                                 struct rlimit *limit);
00486 #endif
00487 
00499 APR_DECLARE(apr_status_t) apr_procattr_child_errfn_set(apr_procattr_t *attr,
00500                                                        apr_child_errfn_t *errfn);
00501 
00514 APR_DECLARE(apr_status_t) apr_procattr_error_check_set(apr_procattr_t *attr,
00515                                                        apr_int32_t chk);
00516 
00517 #if APR_HAS_FORK
00518 
00524 APR_DECLARE(apr_status_t) apr_proc_fork(apr_proc_t *proc, apr_pool_t *cont);
00525 #endif
00526 
00541 APR_DECLARE(apr_status_t) apr_proc_create(apr_proc_t *new_proc,
00542                                              const char *progname,
00543                                              const char * const *args,
00544                                              const char * const *env, 
00545                                              apr_procattr_t *attr, 
00546                                              apr_pool_t *cont);
00547 
00574 APR_DECLARE(apr_status_t) apr_proc_wait(apr_proc_t *proc,
00575                                         int *exitcode, apr_exit_why_e *exitwhy,
00576                                         apr_wait_how_e waithow);
00577 
00604 APR_DECLARE(apr_status_t) apr_proc_wait_all_procs(apr_proc_t *proc,
00605                                                   int *exitcode,
00606                                                   apr_exit_why_e *exitwhy,
00607                                                   apr_wait_how_e waithow,
00608                                                   apr_pool_t *p);
00609 
00610 #define APR_PROC_DETACH_FOREGROUND 0    
00611 #define APR_PROC_DETACH_DAEMONIZE 1     
00619 APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize);
00620 
00638 APR_DECLARE(void) apr_proc_other_child_register(apr_proc_t *proc, 
00639                                            void (*maintenance) (int reason, 
00640                                                                 void *, 
00641                                                                 int status),
00642                                            void *data, apr_file_t *write_fd,
00643                                            apr_pool_t *p);
00644 
00654 APR_DECLARE(void) apr_proc_other_child_unregister(void *data);
00655 
00676 APR_DECLARE(apr_status_t) apr_proc_other_child_alert(apr_proc_t *proc, 
00677                                                      int reason,
00678                                                      int status);
00679 
00687 APR_DECLARE(void) apr_proc_other_child_refresh(apr_other_child_rec_t *ocr,
00688                                                int reason);
00689 
00696 APR_DECLARE(void) apr_proc_other_child_refresh_all(int reason);
00697 
00704 APR_DECLARE(void) apr_proc_other_child_check(void);
00705 
00709 APR_DECLARE(apr_status_t) apr_proc_other_child_read(apr_proc_t *proc, int status);
00710 
00711 
00717 APR_DECLARE(apr_status_t) apr_proc_kill(apr_proc_t *proc, int sig);
00718 
00732 APR_DECLARE(void) apr_pool_note_subprocess(apr_pool_t *a, apr_proc_t *proc,
00733                                            apr_kill_conditions_e how);
00734 
00735 #if APR_HAS_THREADS 
00736 
00737 #if (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2)
00738 
00743 APR_DECLARE(apr_status_t) apr_setup_signal_thread(void);
00744 
00752 APR_DECLARE(apr_status_t) apr_signal_thread(int(*signal_handler)(int signum));
00753 
00754 #endif /* (APR_HAVE_SIGWAIT || APR_HAVE_SIGSUSPEND) && !defined(OS2) */
00755 
00760 APR_POOL_DECLARE_ACCESSOR(thread);
00761 
00762 #endif /* APR_HAS_THREADS */
00763 
00766 #ifdef __cplusplus
00767 }
00768 #endif
00769 
00770 #endif  /* ! APR_THREAD_PROC_H */
00771 

Generated on Fri Sep 17 11:18:21 2004 for Apache Portable Runtime by doxygen 1.3.5