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