原创 2006年06月16日 23:33:00



#ifdef __cplusplus
extern "C" {

 * Resource allocation routines...
 * designed so that we don't have to keep track of EVERYTHING so that
 * it can be explicitly freed later (a fundamentally unsound strategy ---
 * particularly in the presence of die()).
 * Instead, we maintain pools, and allocate items (both memory and I/O
 * handlers) from the pools --- currently there are two, one for per
 * transaction info, and one for config info.  When a transaction is over,
 * we can delete everything in the per-transaction pool without fear, and
 * without thinking too hard about it either.
 * rst

/* Arenas for configuration info and transaction info
 * --- actual layout of the pool structure is private to
 * alloc.c. 

 /* Need declaration of DIR on Win32 */
#ifdef WIN32
#include "../os/win32/readdir.h"

typedef struct pool pool;
typedef struct pool ap_pool;

pool * ap_init_alloc(void);  /* Set up everything */
API_EXPORT(pool *) ap_make_sub_pool(pool *); /* All pools are subpools of permanent_pool */
API_EXPORT(void) ap_destroy_pool(pool *);

/* used to guarantee to the pool debugging code that the sub pool will not be
 * destroyed before the parent pool
#ifndef POOL_DEBUG
#ifdef ap_pool_join
#undef ap_pool_join
#define ap_pool_join(a,b)
API_EXPORT(void) ap_pool_join(pool *p, pool *sub);
API_EXPORT(pool *) ap_find_pool(const void *ts);
API_EXPORT(int) ap_pool_is_ancestor(pool *a, pool *b);

/* Clearing out EVERYTHING in an pool... destroys any sub-pools */

API_EXPORT(void) ap_clear_pool(struct pool *);

/* Preparing for exec() --- close files, etc., but *don't* flush I/O
 * buffers, *don't* wait for subprocesses, and *don't* free any memory.

API_EXPORT(void) ap_cleanup_for_exec(void);

/* routines to allocate memory from an pool... */

API_EXPORT(void *) ap_palloc(struct pool *, int nbytes);
API_EXPORT(void *) ap_pcalloc(struct pool *, int nbytes);
API_EXPORT(char *) ap_pstrdup(struct pool *, const char *s);
/* make a nul terminated copy of the n characters starting with s */
API_EXPORT(char *) ap_pstrndup(struct pool *, const char *s, int n);
API_EXPORT_NONSTD(char *) ap_pstrcat(struct pool *,...); /* all '...' must be char* */
API_EXPORT_NONSTD(char *) ap_psprintf(struct pool *, const char *fmt, ...)
API_EXPORT(char *) ap_pvsprintf(struct pool *, const char *fmt, va_list);

/* array and alist management... keeping lists of things.
 * Common enough to want common support code ...

typedef struct {
    ap_pool *pool;
    int elt_size;
    int nelts;
    int nalloc;
    char *elts;
} array_header;

API_EXPORT(array_header *) ap_make_array(pool *p, int nelts, int elt_size);
API_EXPORT(void *) ap_push_array(array_header *);
API_EXPORT(void) ap_array_cat(array_header *dst, const array_header *src);
API_EXPORT(array_header *) ap_append_arrays(pool *, const array_header *,
      const array_header *);

/* copy_array copies the *entire* array.  copy_array_hdr just copies
 * the header, and arranges for the elements to be copied if (and only
 * if) the code subsequently does a push or arraycat.

API_EXPORT(array_header *) ap_copy_array(pool *p, const array_header *src);
API_EXPORT(array_header *) ap_copy_array_hdr(pool *p, const array_header *src);

/* Tables.  Implemented alist style, for now, though we try to keep
 * it so that imposing a hash table structure on top in the future
 * wouldn't be *too* hard...
 * Note that key comparisons for these are case-insensitive, largely
 * because that's what's appropriate and convenient everywhere they're
 * currently being used...

typedef struct table table;

typedef struct {
    char *key;  /* maybe NULL in future;
    * check when iterating thru table_elts
    char *val;
} table_entry;

API_EXPORT(table *) ap_make_table(pool *p, int nelts);
API_EXPORT(table *) ap_copy_table(pool *p, const table *);
API_EXPORT(void) ap_clear_table(table *);
API_EXPORT(const char *) ap_table_get(const table *, const char *);
API_EXPORT(void) ap_table_set(table *, const char *name, const char *val);
API_EXPORT(void) ap_table_setn(table *, const char *name, const char *val);
API_EXPORT(void) ap_table_merge(table *, const char *name, const char *more_val);
API_EXPORT(void) ap_table_mergen(table *, const char *name, const char *more_val);
API_EXPORT(void) ap_table_unset(table *, const char *key);
API_EXPORT(void) ap_table_add(table *, const char *name, const char *val);
API_EXPORT(void) ap_table_addn(table *, const char *name, const char *val);
API_EXPORT(void) ap_table_do(int (*comp) (void *, const char *, const char *), void *rec,
     const table *t,...);

API_EXPORT(table *) ap_overlay_tables(pool *p, const table *overlay, const table *base);

/* Conceptually, ap_overlap_tables does this:

    array_header *barr = ap_table_elts(b);
    table_entry *belt = (table_entry *)barr->elts;
    int i;

    for (i = 0; i < barr->nelts; ++i) {
     ap_table_mergen(a, belt[i].key, belt[i].val);
 else {
     ap_table_setn(a, belt[i].key, belt[i].val);

    Except that it is more efficient (less space and cpu-time) especially
    when b has many elements.

    Notice the assumptions on the keys and values in b -- they must be
    in an ancestor of a's pool.  In practice b and a are usually from
    the same pool.
API_EXPORT(void) ap_overlap_tables(table *a, const table *b, unsigned flags);

/* XXX: these know about the definition of struct table in alloc.c.  That
 * definition is not here because it is supposed to be private, and by not
 * placing it here we are able to get compile-time diagnostics from modules
 * written which assume that a table is the same as an array_header. -djg
#define ap_table_elts(t) ((array_header *)(t))
#define ap_is_empty_table(t) (((t) == NULL)||(((array_header *)(t))->nelts == 0))

/* routines to remember allocation of other sorts of things...
 * generic interface first.  Note that we want to have two separate
 * cleanup functions in the general case, one for exec() preparation,
 * to keep CGI scripts and the like from inheriting access to things
 * they shouldn't be able to touch, and one for actually cleaning up,
 * when the actual server process wants to get rid of the thing,
 * whatever it is. 
 * kill_cleanup disarms a cleanup, presumably because the resource in
 * question has been closed, freed, or whatever, and it's scarce
 * enough to want to reclaim (e.g., descriptors).  It arranges for the
 * resource not to be cleaned up a second time (it might have been
 * reallocated).  run_cleanup does the same, but runs it first.
 * Cleanups are identified for purposes of finding & running them off by the
 * plain_cleanup and data, which should presumably be unique.
 * NB any code which invokes register_cleanup or kill_cleanup directly
 * is a critical section which should be guarded by block_alarms() and
 * unblock_alarms() below...

API_EXPORT(void) ap_register_cleanup(pool *p, void *data,
      void (*plain_cleanup) (void *),
      void (*child_cleanup) (void *));

API_EXPORT(void) ap_kill_cleanup(pool *p, void *data, void (*plain_cleanup) (void *));
API_EXPORT(void) ap_run_cleanup(pool *p, void *data, void (*cleanup) (void *));

/* A "do-nothing" cleanup, for register_cleanup; it's faster to do
 * things this way than to test for NULL. */
API_EXPORT_NONSTD(void) ap_null_cleanup(void *data);

/* The time between when a resource is actually allocated, and when it
 * its cleanup is registered is a critical section, during which the
 * resource could leak if we got interrupted or timed out.  So, anything
 * which registers cleanups should bracket resource allocation and the
 * cleanup registry with these.  (This is done internally by run_cleanup).
 * NB they are actually implemented in http_main.c, since they are bound
 * up with timeout handling in general...

API_EXPORT(void) ap_block_alarms(void);
API_EXPORT(void) ap_unblock_alarms(void);

/* Common cases which want utility support..
 * the note_cleanups_for_foo routines are for

API_EXPORT(FILE *) ap_pfopen(struct pool *, const char *name, const char *fmode);
API_EXPORT(FILE *) ap_pfdopen(struct pool *, int fd, const char *fmode);
API_EXPORT(int) ap_popenf(struct pool *, const char *name, int flg, int mode);

API_EXPORT(void) ap_note_cleanups_for_file(pool *, FILE *);
API_EXPORT(void) ap_note_cleanups_for_fd(pool *, int);
#ifdef WIN32
API_EXPORT(void) ap_note_cleanups_for_h(pool *, HANDLE);
API_EXPORT(void) ap_kill_cleanups_for_fd(pool *p, int fd);

API_EXPORT(void) ap_note_cleanups_for_socket(pool *, int);
API_EXPORT(void) ap_kill_cleanups_for_socket(pool *p, int sock);
API_EXPORT(int) ap_psocket(pool *p, int, int, int);
API_EXPORT(int) ap_pclosesocket(pool *a, int sock);

API_EXPORT(regex_t *) ap_pregcomp(pool *p, const char *pattern, int cflags);
API_EXPORT(void) ap_pregfree(pool *p, regex_t * reg);

/* routines to note closes... file descriptors are constrained enough
 * on some systems that we want to support this.

API_EXPORT(int) ap_pfclose(struct pool *, FILE *);
API_EXPORT(int) ap_pclosef(struct pool *, int fd);
#ifdef WIN32
API_EXPORT(int) ap_pcloseh(struct pool *, HANDLE hDevice);

/* routines to deal with directories */
API_EXPORT(DIR *) ap_popendir(pool *p, const char *name);
API_EXPORT(void) ap_pclosedir(pool *p, DIR * d);

/* ... even child processes (which we may want to wait for,
 * or to kill outright, on unexpected termination).
 * ap_spawn_child is a utility routine which handles an awful lot of
 * the rigamarole associated with spawning a child --- it arranges
 * for pipes to the child's stdin and stdout, if desired (if not,
 * set the associated args to NULL).  It takes as args a function
 * to call in the child, and an argument to be passed to the function.

enum kill_conditions {
    kill_never,   /* process is never sent any signals */
    kill_always,  /* process is sent SIGKILL on pool 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 */

typedef struct child_info child_info;
API_EXPORT(void) ap_note_subprocess(pool *a, int pid,
        enum kill_conditions how);
API_EXPORT(int) ap_spawn_child(pool *, int (*)(void *, child_info *),
       void *, enum kill_conditions,
       FILE **pipe_in, FILE **pipe_out,
       FILE **pipe_err);

/* magic numbers --- min free bytes to consider a free pool block useable,
 * and the min amount to allocate if we have to go to malloc() */

#define BLOCK_MINFREE 4096
#define BLOCK_MINALLOC 8192

/* Finally, some accounting */

API_EXPORT(long) ap_bytes_in_pool(pool *p);
API_EXPORT(long) ap_bytes_in_free_blocks(void);

#ifdef __cplusplus

#endif /* !APACHE_ALLOC_H */







问题描述: 1>------ 已启动生成: 项目: interpolation, 配置: Debug Win32 ------1>正在编译...1>interpolation.cpp1>c:/docu...
  • jayxbja
  • jayxbja
  • 2010年05月24日 16:45
  • 4575

STL源码剖析 [特殊的空间配置器](内存配置stl_alloc.h)

这一部分的学习将按照《STL源码剖析》来记录。我下载的STL源码是。 source code中包括STL标准头文件(无...
  • langb2014
  • langb2014
  • 2015年08月26日 12:39
  • 734


1.1 brk()--重置数据段存储空间函数 第1章 动态内存管理函数:alloc.h 动态内存管理函数在程序执行过程中为程序中的数据分配内存,这些函数都通过指针来指明内存地址。 ...
  • holandstone
  • holandstone
  • 2013年02月22日 17:26
  • 495


无线Trace的格式 1.老版本的Trace格式 目前,无线模拟的Trace支持使用cmu-trace对象,该对象有三种类型,分别为:CMUTrace/Drop、CMUTrace/Recv和CMU...
  • pengtwelve
  • pengtwelve
  • 2011年10月08日 17:16
  • 4440


  • KangRoger
  • KangRoger
  • 2014年08月11日 00:13
  • 4054


前面介绍如如何用WinDBG 生成crash dump 《WinDBG 技巧:如何生成Dump 文件(.dump 命令) 》,但是用户机器上通常不安装WinDBG, 而且多数用户也不知道怎么使用Wi...
  • nui111
  • nui111
  • 2014年06月29日 22:09
  • 2814


  • jiangguangchao
  • jiangguangchao
  • 2017年02月07日 12:32
  • 6246

iOS 提交审核的时候无法上传 生成的api分析文件太大

估计这是苹果的bug,我修改了version 才成功上传 可以先修改build   如果还不行  就改个version 版本号 再试试...
  • binbin15951
  • binbin15951
  • 2017年12月08日 10:15
  • 107


ns2, trace file.
  • bennyfun79
  • bennyfun79
  • 2010年07月01日 09:56
  • 4212

上传ipa出现的错误提示“application loader上传出错 生成的API分析文件太大”解决方法

使用Application Loader 上传ipa出现的错误提示“application loader上传出错 生成的API分析文件太大”解决方法 如下图: 解决办法就是修改Xcode里面的因为...
  • 2016年04月13日 18:23
  • 6549