📄 apr_thread_proc.h
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000-2001 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, 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. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * 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 (INCLUDING, 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. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */#ifndef APR_THREAD_PROC_H#define APR_THREAD_PROC_H#include "apr.h"#include "apr_file_io.h"#include "apr_pools.h"#include "apr_errno.h"#if APR_HAVE_STRUCT_RLIMIT#include <sys/time.h>#include <sys/resource.h>#endif#ifdef __cplusplusextern "C" {#endif /* __cplusplus *//** * @package APR Thread library */typedef enum {APR_SHELLCMD, APR_PROGRAM} apr_cmdtype_e;typedef enum {APR_WAIT, APR_NOWAIT} apr_wait_how_e;#define APR_NO_PIPE 0#define APR_FULL_BLOCK 1#define APR_FULL_NONBLOCK 2#define APR_PARENT_BLOCK 3#define APR_CHILD_BLOCK 4#define APR_LIMIT_CPU 0#define APR_LIMIT_MEM 1#define APR_LIMIT_NPROC 2#if APR_HAS_OTHER_CHILD#define APR_OC_REASON_DEATH 0 /* child has died, caller must call * unregister still */#define APR_OC_REASON_UNWRITABLE 1 /* write_fd is unwritable */#define APR_OC_REASON_RESTART 2 /* a restart is occuring, perform * any necessary cleanup (including * sending a special signal to child) */#define APR_OC_REASON_UNREGISTER 3 /* unregister has been called, do * whatever is necessary (including * kill the child) */#define APR_OC_REASON_LOST 4 /* somehow the child exited without * us knowing ... buggy os? */#endif /* APR_HAS_OTHER_CHILD */typedef struct apr_proc_t apr_proc_t;/** The APR process type */struct apr_proc_t { /** The process ID */ pid_t pid; /** Parent's side of pipe to child's stdin */ apr_file_t *in; /** Parent's side of pipe to child's stdout */ apr_file_t *out; /* Parent's side of pipe to child's stdouterr */ apr_file_t *err;};typedef struct apr_thread_t apr_thread_t;typedef struct apr_threadattr_t apr_threadattr_t;typedef struct apr_procattr_t apr_procattr_t;typedef struct apr_threadkey_t apr_threadkey_t;#if APR_HAS_OTHER_CHILDtypedef struct apr_other_child_rec_t apr_other_child_rec_t;#endif /* APR_HAS_OTHER_CHILD */typedef void *(APR_THREAD_FUNC *apr_thread_start_t)(void *);enum kill_conditions { kill_never, /* process is never sent any signals */ kill_always, /* process is sent SIGKILL on apr_pool_t cleanup */ kill_after_timeout, /* SIGTERM, wait 3 seconds, SIGKILL */ just_wait, /* wait forever for the process to complete */ kill_only_once /* send SIGTERM and then wait */};/** A list of processes */struct process_chain { /** The process ID */ apr_proc_t *pid; /** When the process should be sent a signal. <PRE> * kill_never -- process is never sent any signals * kill_always -- process is sent SIGKILL on apr_pool_t cleanup * kill_after_timeout -- SIGTERM, wait 3 seconds, SIGKILL * just_wait -- wait forever for the process to complete * kill_only_once -- send SIGTERM and then wait </PRE> */ enum kill_conditions kill_how; /** The next process in the list * @defvar process_chain *next */ struct process_chain *next;};/* Thread Function definitions */#if APR_HAS_THREADS/** * Create and initialize a new threadattr variable * @param new_attr The newly created threadattr. * @param cont The pool to use * @deffunc apr_status_t apr_threadattr_create(apr_threadattr_t **new_attr, apr_pool_t *cont) */APR_DECLARE(apr_status_t) apr_threadattr_create(apr_threadattr_t **new_attr, apr_pool_t *cont);/** * Set if newly created threads should be created in detach mode. * @param attr The threadattr to affect * @param on Thread detach state on or off * @deffunc apr_status_t apr_threadattr_detach_get(apr_threadattr_t *attr, apr_int32_t on) */APR_DECLARE(apr_status_t) apr_threadattr_detach_get(apr_threadattr_t *attr, apr_int32_t on);/** * Get the detach mode for this threadattr. * @param attr The threadattr to reference * @deffunc apr_status_t apr_threadattr_detach_set(apr_threadattr_t *attr) */APR_DECLARE(apr_status_t) apr_threadattr_detach_set(apr_threadattr_t *attr);/** * Create a new thread of execution * @param new_thread The newly created thread handle. * @param attr The threadattr to use to determine how to create the thread * @param func The function to start the new thread in * @param data Any data to be passed to the starting function * @param cont The pool to use * @deffunc apr_status_t apr_thread_create(apr_thread_t **new_thread, apr_threadattr_t *attr, apr_thread_start_t func, void *data, apr_pool_t *cont) */APR_DECLARE(apr_status_t) apr_thread_create(apr_thread_t **new_thread, apr_threadattr_t *attr, apr_thread_start_t func, void *data, apr_pool_t *cont);/** * stop the current thread * @param thd The thread to stop * @param retval The return value to pass back to any thread that cares * @deffunc apr_status_t apr_thread_exit(apr_thread_t *thd, apr_status_t *retval) */APR_DECLARE(apr_status_t) apr_thread_exit(apr_thread_t *thd, apr_status_t *retval);/** * block until the desired thread stops executing. * @param retval The return value from the dead thread. * @param thd The thread to join * @deffunc apr_status_t apr_thread_join(apr_status_t *retval, apr_thread_t *thd); */APR_DECLARE(apr_status_t) apr_thread_join(apr_status_t *retval, apr_thread_t *thd); /** * detach a thread * @param thd The thread to detach * @deffunc apr_status_t apr_thread_detach(apr_thread_t *thd) */APR_DECLARE(apr_status_t) apr_thread_detach(apr_thread_t *thd);/** * Return the pool associated with the current thread. * @param data The user data associated with the thread. * @param key The key to associate with the data * @param thread The currently open thread. * @deffunc apr_status_t apr_thread_data_get(void **data, const char *key, apr_thread_t *thread) */APR_DECLARE(apr_status_t) apr_thread_data_get(void **data, const char *key, apr_thread_t *thread);/** * Return the pool associated with the current thread. * @param data The user data to associate with the thread. * @param key The key to use for associating the data with the tread * @param cleanup The cleanup routine to use when the thread is destroyed. * @param thread The currently open thread. * @deffunc apr_status_t apr_thread_data_set(void *data, const char *key, apr_status_t (*cleanup) (void *), apr_thread_t *thread) */APR_DECLARE(apr_status_t) apr_thread_data_set(void *data, const char *key, apr_status_t (*cleanup) (void *), apr_thread_t *thread);/** * Create and initialize a new thread private address space * @param key The thread private handle. * @param dest The destructor to use when freeing the private memory. * @param cont The pool to use * @deffunc apr_status_t apr_threadkey_private_create(apr_threadkey_t **key, void (*dest)(void *), apr_pool_t *cont) */APR_DECLARE(apr_status_t) apr_threadkey_private_create(apr_threadkey_t **key, void (*dest)(void *), apr_pool_t *cont);/** * Get a pointer to the thread private memory * @param new_mem The data stored in private memory * @param key The handle for the desired thread private memory * @deffunc apr_status_t apr_threadkey_private_get(void **new_mem, apr_threadkey_t *key) */APR_DECLARE(apr_status_t) apr_threadkey_private_get(void **new_mem, apr_threadkey_t *key);/** * Set the data to be stored in thread private memory * @param priv The data to be stored in private memory * @param key The handle for the desired thread private memory * @deffunc apr_status_t apr_threadkey_private_set(void *priv, apr_threadkey_t *key) */APR_DECLARE(apr_status_t) apr_threadkey_private_set(void *priv, apr_threadkey_t *key);/** * Free the thread private memory * @param key The handle for the desired thread private memory * @deffunc apr_status_t apr_threadkey_private_delete(apr_threadkey_t *key) */APR_DECLARE(apr_status_t) apr_threadkey_private_delete(apr_threadkey_t *key);/** * Return the pool associated with the current threadkey. * @param data The user data associated with the threadkey. * @param key The key associated with the data * @param threadkey The currently open threadkey. * @deffunc apr_status_t apr_threadkey_data_get(void **data, const char *key, apr_threadkey_t *threadkey) */APR_DECLARE(apr_status_t) apr_threadkey_data_get(void **data, const char *key, apr_threadkey_t *threadkey);/** * Return the pool associated with the current threadkey. * @param data The data to set. * @param key The key to associate with the data. * @param cleanup The cleanup routine to use when the file is destroyed. * @param threadkey The currently open threadkey. * @deffunc apr_status_t apr_threadkey_data_set(void *data, const char *key, apr_status_t (*cleanup) (void *), apr_threadkey_t *threadkey) */APR_DECLARE(apr_status_t) apr_threadkey_data_set(void *data, const char *key, apr_status_t (*cleanup) (void *), apr_threadkey_t *threadkey);#endif/* Process Function definitions *//** * @package APR Process library *//** * Create and initialize a new procattr variable
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -