locks.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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 "dmm_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. /** Initialized a raw block lock */
  35. #define init_raw_block_lock(rb) pthread_mutex_init(&rb->mutex, NULL);
  36. /** Unlocks a specific raw block */
  37. #define unlock_raw_block(rb) pthread_mutex_unlock(&rb->mutex)
  38. #else /* HAVE_LOCKS */
  39. /** Does nothing. */
  40. #define lock_global()
  41. /** Does nothing. */
  42. #define unlock_global()
  43. /** Does nothing. */
  44. #define lock_raw_block(rb)
  45. /** Does nothing. */
  46. #define init_raw_block_lock(rb)
  47. /** Does nothing. */
  48. #define unlock_raw_block(rb)
  49. #endif /* HAVE_LOCKS */
  50. #endif /* LOCKS_H */