Subversion Repositories Kolibri OS

Rev

Rev 5192 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1.  
  2. #ifndef _SYS_LOCK_H_
  3. #define _SYS_LOCK_H_
  4.  
  5. #include <sys/cdefs.h>
  6. #include <stddef.h>
  7. #include <sys/gthr.h>
  8.  
  9. typedef __gthread_mutex_t _LOCK_T;
  10.  
  11. typedef __gthread_recursive_mutex_t _LOCK_RECURSIVE_T;
  12.  
  13. #define _MUTEX_INITIALIZER { 0, -1 }
  14.  
  15. #define _MUTEX_RECURSIVE_INITIALIZER { 0,-1,0,0 }
  16.  
  17. #define __LOCK_INIT(_qualifier, _designator) \
  18.     _qualifier _LOCK_T _designator = _MUTEX_INITIALIZER
  19.  
  20. #define __LOCK_INIT_RECURSIVE(_qualifier, _designator) \
  21.     _qualifier _LOCK_RECURSIVE_T _designator = _MUTEX_RECURSIVE_INITIALIZER
  22.  
  23. static inline int __libc_lock_acquire(_LOCK_T *lock)
  24. {
  25.     if(lock->handle == -1)
  26.         __gthread_mutex_init_function(lock);
  27.  
  28.     return __gthread_mutex_lock(lock);
  29. }
  30.  
  31. static inline int __libc_lock_acquire_recursive(_LOCK_RECURSIVE_T *lock)
  32. {
  33.     if(lock->handle == -1)
  34.         __gthread_recursive_mutex_init_function(lock);
  35.  
  36.     return __gthread_recursive_mutex_lock(lock);
  37. }
  38.  
  39. #define __lock_acquire(_lock) __libc_lock_acquire(&_lock)
  40. #define __lock_release(_lock) __gthread_mutex_unlock(&_lock)
  41.  
  42. #define __lock_init_recursive(_lock) __gthread_recursive_mutex_init_function(&_lock)
  43. #define __lock_acquire_recursive(_lock) __libc_lock_acquire_recursive(&_lock)
  44. #define __lock_release_recursive(_lock) __gthread_recursive_mutex_unlock(&_lock)
  45. #define __lock_close_recursive(_lock) __gthread_recursive_mutex_destroy(&_lock)
  46.  
  47. #endif /* _SYS_LOCK_H_ */
  48.