core, lib, modules: restructured source code tree
[sip-router] / src / lib / cds / cds.c
1 #include <cds/cds.h>
2 #include <cds/memory.h>
3 #include <cds/sync.h>
4 #include <cds/logger.h>
5
6 #if 0
7
8 typedef struct {
9         int init_cnt;
10 } init_data_t;
11
12 static init_data_t *init = NULL;
13
14 /* these functions are internal and thus are not presented in headers !*/
15 int reference_counter_initialize();
16 void reference_counter_cleanup();
17         
18 int cds_initialize()
19 {
20         int res = 0;
21
22         /* initialization should be called from one process/thread 
23          * it is not synchronized because it is impossible ! */
24         if (!init) {
25                 init = (init_data_t*)cds_malloc(sizeof(init_data_t));
26                 if (!init) return -1;
27                 init->init_cnt = 0;
28         }
29
30         if (init->init_cnt > 0) { /* already initialized */
31                 init->init_cnt++;
32                 return 0;
33         }
34         else {
35                 DEBUG_LOG("init the content\n");
36                 
37                 /* !!! put the real initialization here !!! */
38                 res = reference_counter_initialize();
39         }
40                         
41         if (res == 0) init->init_cnt++;
42         return res;
43 }
44
45 void cds_cleanup()
46 {
47         if (init) {
48                 if (--init->init_cnt == 0) {
49                         DEBUG_LOG("cleaning the content\n");
50                         
51                         /* !!! put the real destruction here !!! */
52                         reference_counter_cleanup();
53                 
54                         cds_free(init);
55                         init = NULL;
56                 }
57         }
58 }
59
60 #endif