• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

ink_queue_ext.h

Go to the documentation of this file.
00001 /** @file
00002 
00003   A brief file description
00004 
00005   @section license License
00006 
00007   Licensed to the Apache Software Foundation (ASF) under one
00008   or more contributor license agreements.  See the NOTICE file
00009   distributed with this work for additional information
00010   regarding copyright ownership.  The ASF licenses this file
00011   to you under the Apache License, Version 2.0 (the
00012   "License"); you may not use this file except in compliance
00013   with the License.  You may obtain a copy of the License at
00014 
00015       http://www.apache.org/licenses/LICENSE-2.0
00016 
00017   Unless required by applicable law or agreed to in writing, software
00018   distributed under the License is distributed on an "AS IS" BASIS,
00019   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00020   See the License for the specific language governing permissions and
00021   limitations under the License.
00022  */
00023 
00024 #ifndef _ink_queue_ext_h_
00025 #define _ink_queue_ext_h_
00026 
00027 /***********************************************************************
00028 
00029     Head file of Reclaimable freelist
00030 
00031 ***********************************************************************/
00032 
00033 #include "List.h"
00034 #include "ink_queue.h"
00035 
00036 #ifdef __cplusplus
00037 extern "C"
00038 {
00039 #endif                          /* __cplusplus */
00040 #if TS_USE_RECLAIMABLE_FREELIST
00041   struct _InkThreadCache;
00042   struct _InkFreeList;
00043 
00044   typedef struct _InkChunkInfo
00045   {
00046     pthread_t tid;
00047 
00048     uint32_t type_size;
00049     uint32_t chunk_size;
00050     uint32_t allocated;
00051     uint32_t length;
00052 
00053     /*
00054      * inner free list will only be
00055      * accessed by creator-thread
00056      */
00057     void *inner_free_list;
00058     void *head;
00059 
00060     struct _InkThreadCache *pThreadCache;
00061 
00062     LINK(_InkChunkInfo, link);
00063 
00064 #ifdef DEBUG
00065     /*
00066      * magic code for each item,
00067      * it's used to check double-free issue.
00068      */
00069     unsigned char item_magic[0];
00070 #endif
00071   } InkChunkInfo;
00072 
00073   typedef struct _InkThreadCache
00074   {
00075     struct _InkFreeList *f;
00076 
00077     /* outer free list will be accessed by:
00078      * - creator-thread, asa producer-thread
00079      * - consumer-thread
00080      * - neighbor-thread
00081      */
00082     InkAtomicList outer_free_list;
00083 
00084     /* using for memory reclaim algorithm */
00085     float nr_average;
00086     uint32_t nr_total;
00087     uint32_t nr_free;
00088     uint32_t nr_min;
00089     uint32_t nr_overage;
00090     uint32_t nr_malloc;
00091 
00092     /* represent the status(state) of allocator: Malloc-ing(0) or Free-ing(1),
00093      * I use it as an simple state machine - calculating the minimum of free
00094      * memory only when the status change from Malloc-ing to Free-ing.
00095      */
00096     uint32_t status;
00097 
00098     uint32_t nr_free_chunks;
00099     DLL<InkChunkInfo> free_chunk_list;
00100 
00101     _InkThreadCache *prev, *next;
00102   } InkThreadCache;
00103 
00104   typedef struct _InkFreeList
00105   {
00106     uint32_t thread_cache_idx;
00107 
00108     uint32_t refcnt;
00109     const char *name;
00110 
00111     uint32_t type_size;
00112     uint32_t alignment;
00113 
00114     /* number of elements in one chunk */
00115     uint32_t chunk_size;
00116     /* total byte size of one chuck */
00117     uint32_t chunk_byte_size;
00118     /* chunk_addr = (uintptr_t)ptr & chunk_addr_mask */
00119     uintptr_t chunk_addr_mask;
00120 
00121     uint32_t used;
00122     uint32_t allocated;
00123     uint32_t allocated_base;
00124     uint32_t used_base;
00125     uint32_t chunk_size_base;
00126 
00127     uint32_t nr_thread_cache;
00128     InkThreadCache *pThreadCache;
00129     ink_mutex lock;
00130   } InkFreeList, *PInkFreeList;
00131 
00132   /* reclaimable freelist API */
00133   void reclaimable_freelist_init(InkFreeList **fl, const char *name,
00134                                  uint32_t type_size, uint32_t chunk_size,
00135                                  uint32_t alignment);
00136   void *reclaimable_freelist_new(InkFreeList *f);
00137   void reclaimable_freelist_free(InkFreeList *f, void *item);
00138 #endif /* END OF TS_USE_RECLAIMABLE_FREELIST */
00139 #ifdef __cplusplus
00140 }
00141 #endif /* __cplusplus */
00142 
00143 #endif /* _ink_queue_ext_h_ */

Generated by  doxygen 1.7.1