jfs_lock.h 883 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) International Business Machines Corp., 2000-2001
  4. * Portions Copyright (C) Christoph Hellwig, 2001-2002
  5. */
  6. #ifndef _H_JFS_LOCK
  7. #define _H_JFS_LOCK
  8. #include <linux/spinlock.h>
  9. #include <linux/mutex.h>
  10. #include <linux/sched.h>
  11. /*
  12. * jfs_lock.h
  13. */
  14. /*
  15. * Conditional sleep where condition is protected by spinlock
  16. *
  17. * lock_cmd and unlock_cmd take and release the spinlock
  18. */
  19. #define __SLEEP_COND(wq, cond, lock_cmd, unlock_cmd) \
  20. do { \
  21. DECLARE_WAITQUEUE(__wait, current); \
  22. \
  23. add_wait_queue(&wq, &__wait); \
  24. for (;;) { \
  25. set_current_state(TASK_UNINTERRUPTIBLE);\
  26. if (cond) \
  27. break; \
  28. unlock_cmd; \
  29. io_schedule(); \
  30. lock_cmd; \
  31. } \
  32. __set_current_state(TASK_RUNNING); \
  33. remove_wait_queue(&wq, &__wait); \
  34. } while (0)
  35. #endif /* _H_JFS_LOCK */