unrealircd

- supernets unrealircd source & configuration
git clone git://git.acid.vegas/unrealircd.git
Log | Files | Refs | Archive | README | LICENSE

mempool.h (3786B)

      1 /*
      2  * Copyright (c) 2007-2012, The Tor Project, Inc.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions are
      6  * met:
      7  *
      8  *   * Redistributions of source code must retain the above copyright
      9  *     notice, this list of conditions and the following disclaimer.
     10  *
     11  *   * Redistributions in binary form must reproduce the above
     12  *     copyright notice, this list of conditions and the following disclaimer
     13  *     in the documentation and/or other materials provided with the
     14  *     distribution.
     15  *
     16  *   * Neither the names of the copyright owners nor the names of its
     17  *     contributors may be used to endorse or promote products derived from
     18  *     this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
     23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     24  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     25  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
     26  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     30  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /* Imported from hybrid svn:
     34  * \file mempool.h
     35  * \brief Pooling allocator
     36  * \version $Id: mempool.h 1662 2012-11-17 20:11:33Z michael $
     37  */
     38 
     39 #ifndef TOR_MEMPOOL_H
     40 #define TOR_MEMPOOL_H
     41 
     42 #ifdef _WIN32
     43   #define uint64_t unsigned __int64
     44 #endif
     45 
     46 /** A memory pool is a context in which a large number of fixed-sized
     47 * objects can be allocated efficiently.  See mempool.c for implementation
     48 * details. */
     49 typedef struct mp_pool_t mp_pool_t;
     50 
     51 extern void mp_pool_init(void);
     52 extern void *mp_pool_get(mp_pool_t *);
     53 extern void mp_pool_release(void *);
     54 extern mp_pool_t *mp_pool_new(size_t, size_t);
     55 extern void mp_pool_clean(mp_pool_t *, int, int);
     56 extern void mp_pool_destroy(mp_pool_t *);
     57 extern void mp_pool_assert_ok(mp_pool_t *);
     58 extern void mp_pool_log_status(mp_pool_t *);
     59 extern void mp_pool_garbage_collect(void *);
     60 
     61 #define MEMPOOL_STATS
     62 
     63 struct mp_pool_t {
     64   /** Next pool. A pool is usually linked into the mp_allocated_pools list. */
     65   mp_pool_t *next;
     66 
     67   /** Doubly-linked list of chunks in which no items have been allocated.
     68    * The front of the list is the most recently emptied chunk. */
     69   struct mp_chunk_t *empty_chunks;
     70 
     71   /** Doubly-linked list of chunks in which some items have been allocated,
     72    * but which are not yet full. The front of the list is the chunk that has
     73    * most recently been modified. */
     74   struct mp_chunk_t *used_chunks;
     75 
     76   /** Doubly-linked list of chunks in which no more items can be allocated.
     77    * The front of the list is the chunk that has most recently become full. */
     78   struct mp_chunk_t *full_chunks;
     79 
     80   /** Length of <b>empty_chunks</b>. */
     81   int n_empty_chunks;
     82 
     83   /** Lowest value of <b>empty_chunks</b> since last call to
     84    * mp_pool_clean(-1). */
     85   int min_empty_chunks;
     86 
     87   /** Size of each chunk (in items). */
     88   int new_chunk_capacity;
     89 
     90   /** Size to allocate for each item, including overhead and alignment
     91    * padding. */
     92   size_t item_alloc_size;
     93 #ifdef MEMPOOL_STATS
     94   /** Total number of items allocated ever. */
     95   uint64_t total_items_allocated;
     96 
     97   /** Total number of chunks allocated ever. */
     98   uint64_t total_chunks_allocated;
     99 
    100   /** Total number of chunks freed ever. */
    101   uint64_t total_chunks_freed;
    102 #endif
    103 };
    104 
    105 #endif