tls_allocator.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 tls_allocator.h
  19. * @author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * @date February 2014
  21. * @brief Functions for TLS allocators
  22. */
  23. #ifndef DEALY_TLS_ALLOCATOR_H_
  24. #define DEALY_TLS_ALLOCATOR_H_
  25. #include <dmmlib/allocator.h>
  26. #include <pthread.h>
  27. /** Variable storing allocator's settings per thread. */
  28. extern __thread allocator_t *tls_allocator;
  29. /** Key to re-use the previous variable for other threads. */
  30. pthread_key_t destruction_key;
  31. /** Struct for head of a singly-linked list for allocator_t nodes */
  32. SLIST_HEAD(allocator_list_head_s, allocator_s);
  33. /** Singly-linked list for allocator_t nodes with a mutex lock */
  34. typedef struct locking_allocator_list_s {
  35. struct allocator_list_head_s head; /**< The head node. */
  36. locktype_t lock; /**< The lock. */
  37. } locking_allocator_list_t;
  38. /** List of destructed allocators that can be re-used */
  39. extern locking_allocator_list_t destructed_list;
  40. /** Pushes the soon-to-be-dead thread's allocator state to a list for reuse. */
  41. void push_to_destructed_list(void);
  42. /** Allocates in the heap space and initializes allocator state to be used by a
  43. * specific thread. */
  44. allocator_t * initialize_allocator(void);
  45. /** Gets the current thread's allocator. */
  46. void get_tls_allocator(void);
  47. #endif /* DEALY_TLS_ALLOCATOR_H_ */