locks.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 locks.h
  19. * @author Ioannis Koutras (joko@microlab.ntua.gr)
  20. * @date September 2012
  21. * @brief Locking functions
  22. */
  23. #include <dmmlib/config.h>
  24. #ifndef LOCKS_H
  25. #define LOCKS_H
  26. #ifdef HAVE_LOCKS
  27. #include <pthread.h>
  28. /** Locks the systemallocator object */
  29. #define LOCK_GLOBAL() pthread_mutex_lock(&systemallocator.creation_mutex)
  30. /** Unlocks the systemallocator object */
  31. #define UNLOCK_GLOBAL() pthread_mutex_unlock(&systemallocator.creation_mutex)
  32. /** Locks a specific raw block */
  33. #define LOCK_RAW_BLOCK(rb) pthread_mutex_lock(&rb->mutex)
  34. /** Tries to lock a specific raw block */
  35. #define TRYLOCK_RAW_BLOCK(rb) pthread_mutex_trylock(&rb->mutex)
  36. /** Initializes a raw block lock */
  37. #define INIT_RAW_BLOCK_LOCK(rb) pthread_mutex_init(&rb->mutex, NULL);
  38. /** Destroys a raw block lock */
  39. #define DESTROY_RAW_BLOCK_LOCK(rb) pthread_mutex_destroy(&rb->mutex);
  40. /** Unlocks a specific raw block */
  41. #define UNLOCK_RAW_BLOCK(rb) pthread_mutex_unlock(&rb->mutex)
  42. #else /* HAVE_LOCKS */
  43. /** Does nothing. */
  44. #define LOCK_GLOBAL()
  45. /** Does nothing. */
  46. #define UNLOCK_GLOBAL()
  47. /** Does nothing. */
  48. #define LOCK_RAW_BLOCK(RB)
  49. /** Does nothing. */
  50. #define TRYLOCK_RAW_BLOCK(RB)
  51. /** Does nothing. */
  52. #define INIT_RAW_BLOCK_LOCK(RB)
  53. /** Does nothing. */
  54. #define DESTROY_RAW_BLOCK_LOCK(RB)
  55. /** Does nothing. */
  56. #define UNLOCK_RAW_BLOCK(RB)
  57. #endif /* HAVE_LOCKS */
  58. #endif /* LOCKS_H */