irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

region.h
Go to the documentation of this file.
1 /* For copyright information please refer to files in the COPYRIGHT directory
2  */
3 #ifndef _REGION_H__
4 #define _REGION_H__
5 
6 #include <stdio.h>
7 #include <setjmp.h>
8 
9 #define DEFAULT_BLOCK_SIZE 1024
10 /* the alignment in the region in bytes */
11 #define REGION_ALIGNMENT 8
12 #define roundToAlignment(x) ((x)%REGION_ALIGNMENT == 0?(x):(((x)/REGION_ALIGNMENT)+1)*REGION_ALIGNMENT)
13 /* the point the elem i of type t starting from p in the cache, aligned */
14 #define CACHE_ELEM(t, p, i) (((t)p)+i)
15 /* the size of an array of type t and length i in the cache, aligned */
16 #define CACHE_SIZE(t, l) roundToAlignment(sizeof(t)*l)
17 
18 struct region_error {
19  int code;
20  char msg[1024];
21  void *obj; /* a generic point to an object which is the source of the error */
22 };
23 
24 /* #define REGION_MALLOC */
25 #ifdef REGION_MALLOC
26 struct region_node {
27  size_t size;
28  void *ptr;
29  struct region_node *next;
30 };
31 
32 typedef struct region {
33  struct region_node *head, *tail;
34 } Region;
35 #else
36 struct region_node {
37  unsigned char *block; /* pointer to memory block */
38  size_t size; /* size of the memory block in bytes */
39  size_t used; /* used bytes of the memory block */
40  struct region_node *next; /* pointer to the next region */
41 
42 };
43 
44 
45 typedef struct region {
46  struct region_node *head, *active;
47  jmp_buf *label;
48  struct region_error error;
50 #endif
51 typedef struct region_desc {
53  size_t size;
54  int del;
56 
57 #define IN_REGION(x,r) (((RegionDesc *)(((const unsigned char*)(x))-CACHE_SIZE(RegionDesc, 1)))->region == (r))
58 #define SET_DELETE(x) (((RegionDesc *)(((const unsigned char*)(x))-CACHE_SIZE(RegionDesc, 1)))->del=1)
59 #define DELETED(x) (((RegionDesc *)(((const unsigned char*)(x))-CACHE_SIZE(RegionDesc, 1)))->del)
60 #define SIZE(x) (((RegionDesc *)(((const unsigned char*)(x))-CACHE_SIZE(RegionDesc, 1)))->size)
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 /* create a region with initial size is */
67 /* if s == 0 then the initial size is DEFAULT_BLOCK_SIZE */
68 /* returns NULL if it runs out of memory */
69 Region *make_region( size_t is, jmp_buf *label );
70 /* allocation s bytes in region r */
71 /* return NULL if it runs out of memory */
72 void *region_alloc( Region *r, size_t s );
73 /* free region r */
74 void region_free( Region *r );
75 size_t region_size( Region *r );
76 
77 #ifdef __cplusplus
78 }
79 #endif
80 
81 #endif // REGION_H__
region_node::block
unsigned char * block
Definition: region.h:37
region_error::msg
char msg[1024]
Definition: region.h:20
region_error::obj
void * obj
Definition: region.h:21
region_node::size
size_t size
Definition: region.h:38
region_size
size_t region_size(Region *r)
Definition: region.cpp:157
region_alloc
void * region_alloc(Region *r, size_t s)
Definition: region.cpp:138
region_desc::size
size_t size
Definition: region.h:53
make_region
Region * make_region(size_t is, jmp_buf *label)
Definition: region.cpp:85
region_error::code
int code
Definition: region.h:19
region_desc::region
Region * region
Definition: region.h:52
region_node
Definition: region.h:36
region_desc::del
int del
Definition: region.h:54
region::head
struct region_node * head
Definition: region.h:46
RegionDesc
struct region_desc RegionDesc
region
Definition: region.h:45
region_error
Definition: region.h:18
region::active
struct region_node * active
Definition: region.h:46
region_node::next
struct region_node * next
Definition: region.h:40
region_node::used
size_t used
Definition: region.h:39
region::label
jmp_buf * label
Definition: region.h:47
region_free
void region_free(Region *r)
Definition: region.cpp:146
region_desc
Definition: region.h:51
label
Definition: restructs.hpp:288
region::error
struct region_error error
Definition: region.h:48
Region
struct region Region