allocator.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * Copyright Institute of Communication and Computer Systems (ICCS)
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. /**
  18. * @file allocator.h
  19. * @author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * @date August 2012
  21. * @brief Basic structures needed for the dmmlib allocator.
  22. */
  23. #ifndef ALLOCATOR_H
  24. #define ALLOCATOR_H
  25. #include <dmmlib/config.h>
  26. #include "dmmlib/raw_block.h"
  27. #ifdef HAVE_LOCKS
  28. #include <pthread.h>
  29. #endif /* HAVE_LOCKS */
  30. #ifdef WITH_KNOBS
  31. #include "dmmlib/knobs.h"
  32. #endif /* WITH_KNOBS */
  33. #ifdef WITH_ALLOCATOR_STATS
  34. #include <dmmlib/dmmstats.h>
  35. #endif /* WITH_ALLOCATOR_STATS */
  36. #if defined PARSE_ENV || defined WITH_MEM_TRACE || defined WITH_STATS_TRACE \
  37. || defined WITH_DEBUG
  38. #include <stdbool.h>
  39. #endif /* PARSE_ENV || WITH_MEM_TRACE || WITH_STATS_TRACE || WITH_DEBUG */
  40. /** The allocator structure of dmmlib. */
  41. typedef struct allocator_s {
  42. /** The head of the raw blocks list. */
  43. struct rb_head_s rb_head;
  44. #ifdef WITH_DEBUG
  45. /** The head of the big blocks list. */
  46. struct rb_head_s bb_head;
  47. #endif /* WITH_DEBUG */
  48. #ifdef HAVE_LOCKS
  49. /** Mutex to allow the creation of new raw blocks. */
  50. pthread_mutex_t creation_mutex;
  51. #endif /* HAVE_LOCKS */
  52. #ifdef WITH_KNOBS
  53. dmm_knobs_t dmm_knobs; /**< Global knobs. */
  54. #endif /* WITH_KNOBS */
  55. #ifdef WITH_ALLOCATOR_STATS
  56. dmmstats_t dmm_stats; /**< Global statistics. */
  57. #endif /* WITH_ALLOCATOR_STATS */
  58. #if defined WITH_MEM_TRACE || defined WITH_STATS_TRACE || defined WITH_DEBUG \
  59. || defined PARSE_ENV
  60. /* During initialization it is possible that some files are being opened to
  61. * write the traces, so some dynamic memory is requested. For such cases the
  62. * trace functions should not be run. */
  63. bool initialized; /**< Initialization value. */
  64. #endif /* WITH_MEM_TRACE || WITH_STATS_TRACE || WITH_DEBUG || PARSE_ENV */
  65. } allocator_t;
  66. #endif /* ALLOCATOR_H */