CUBRID Engine  latest
area_alloc.h
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 
20 /*
21  * area_alloc.h - Area memory manager manager
22  *
23  * Note:
24  */
25 
26 #ifndef _AREA_ALLOC_H_
27 #define _AREA_ALLOC_H_
28 
29 #ident "$Id$"
30 
31 #ifndef __cplusplus
32 #error C++ is required
33 #endif
34 
35 #if !defined (SERVER_MODE)
36 #else /* SERVER_MODE */
37 #include "connection_defs.h"
38 #endif /* SERVER_MODE */
39 #include "lockfree_bitmap.hpp"
40 #include "porting.h"
41 
42 #define AREA_BLOCKSET_SIZE 256
43 
44 /*
45  * AREA_BLOCK - Structure used in the implementation of workspace areas.
46  * Maintains information about a block of allocation in an area.
47  * This structure should not be used by external modules but is needed
48  * for the definition of ws_area.
49  */
50 typedef struct area_block AREA_BLOCK;
51 struct area_block
52 {
54  char *data;
55 };
56 
57 /*
58  * AREA_BLOCKSET_LIST - Structure used in the implementation of workspace
59  * areas. It includes a group of blocks pointers. These pointers are
60  * sorted by their address.
61  */
64 {
68 };
69 
70 /*
71  * AREA - Primary structure for an allocation area.
72  */
73 typedef struct area AREA;
74 struct area
75 {
77 
78  char *name;
79  size_t element_size; /* the element size, including prefix */
80  size_t alloc_count;
81  size_t block_size;
82 
83  AREA_BLOCKSET_LIST *blockset_list; /* the blockset list */
84  AREA_BLOCK *hint_block; /* the hint block which may include free slot */
85  pthread_mutex_t area_mutex; /* only used for insert new block */
86 
87  /* for dumping */
88  size_t n_allocs; /* total alloc element count */
89  size_t n_frees; /* total free element count */
90 
91  void (*failure_function) (void);
92 };
93 
94 #ifdef __cplusplus
95 extern "C"
96 {
97 #endif
98 
99 /* system startup, shutdown */
100  extern void area_init (void);
101  extern void area_final (void);
102 
103 /* area definition */
104  extern AREA *area_create (const char *name, size_t element_size, size_t alloc_count);
105  extern void area_destroy (AREA * area);
106 
107 /* allocation functions */
108  extern void *area_alloc (AREA * area);
109  extern int area_validate (AREA * area, const void *address);
110  extern int area_free (AREA * area, void *ptr);
111  extern void area_flush (AREA * area);
112 
113 /* debug functions */
114  extern void area_dump (FILE * fpp);
115 
116 #ifdef __cplusplus
117 }
118 #endif
119 
120 
121 #endif /* _AREA_ALLOC_H_ */
LF_BITMAP bitmap
Definition: area_alloc.h:53
AREA_BLOCK * hint_block
Definition: area_alloc.h:84
AREA * area_create(const char *name, size_t element_size, size_t alloc_count)
Definition: area_alloc.c:146
void area_final(void)
Definition: area_alloc.c:119
size_t alloc_count
Definition: area_alloc.h:80
char * data
Definition: area_alloc.h:54
AREA * next
Definition: area_alloc.h:76
int area_free(AREA *area, void *ptr)
Definition: area_alloc.c:514
size_t n_frees
Definition: area_alloc.h:89
AREA_BLOCKSET_LIST * next
Definition: area_alloc.h:65
void * area_alloc(AREA *area)
Definition: area_alloc.c:360
AREA_BLOCKSET_LIST * blockset_list
Definition: area_alloc.h:83
size_t element_size
Definition: area_alloc.h:79
pthread_mutex_t area_mutex
Definition: area_alloc.h:85
size_t n_allocs
Definition: area_alloc.h:88
int area_validate(AREA *area, const void *address)
Definition: area_alloc.c:487
void area_flush(AREA *area)
Definition: area_alloc.c:597
void area_destroy(AREA *area)
Definition: area_alloc.c:247
#define AREA_BLOCKSET_SIZE
Definition: area_alloc.h:42
size_t block_size
Definition: area_alloc.h:81
void area_dump(FILE *fpp)
Definition: area_alloc.c:853
void area_init(void)
Definition: area_alloc.c:100
char * name
Definition: area_alloc.h:78