lock.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * lock.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 _LOCK_H_
  20. #define _LOCK_H_
  21. #include <sdk/defs.h>
  22. #define DECLARE_LOCK(x) lock_t x = {0}
  23. typedef uint8_t critical_t;
  24. typedef struct
  25. {
  26. uintptr_t holder;
  27. int32_t count;
  28. } lock_t;
  29. static inline void lock_init(lock_t *lock)
  30. {
  31. lock->holder = lock->count = 0;
  32. }
  33. void enter_critical(critical_t *critical);
  34. void leave_critical(critical_t *critical);
  35. void lock_acquire(lock_t *lock);
  36. void lock_acquire_smart(lock_t *lock);
  37. void lock_acquire_shared(lock_t *lock);
  38. void lock_release(lock_t *lock);
  39. #endif