cds.c 1.1 KB

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