sync.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * sync.h
  3. *
  4. * Copyright (C) 2018 Aleksandar Andrejevic <theflash@sdf.lonestar.org>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as
  8. * published by the Free Software Foundation, either version 3 of the
  9. * License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #ifndef _SYNC_H_
  20. #define _SYNC_H_
  21. #include <sdk/defs.h>
  22. #include <lock.h>
  23. #include <semaphore.h>
  24. /*
  25. * NOTE: This is the legacy interface for synchronization functions. New code
  26. * should use lock.h and semaphore.h instead.
  27. */
  28. #define lock_t qword_t
  29. #define resource_t qword_t
  30. static inline void acquire_lock(qword_t *lock)
  31. {
  32. void (*proc)(void*) = (void(*)(void*))lock_acquire;
  33. proc(lock);
  34. }
  35. static inline void release_lock(qword_t *lock)
  36. {
  37. void (*proc)(void*) = (void(*)(void*))lock_release;
  38. proc(lock);
  39. }
  40. static inline void acquire_resource_shared(qword_t *resource)
  41. {
  42. void (*proc)(void*) = (void(*)(void*))lock_acquire_shared;
  43. proc(resource);
  44. }
  45. static inline void acquire_resource_exclusive(qword_t *resource)
  46. {
  47. void (*proc)(void*) = (void(*)(void*))lock_acquire;
  48. proc(resource);
  49. }
  50. static inline void release_resource(qword_t *resource)
  51. {
  52. void (*proc)(void*) = (void(*)(void*))lock_release;
  53. proc(resource);
  54. }
  55. #endif