Merge 4.14.261 into android-4.14-stable
Linux 4.14.261
* sctp: use call_rcu to free endpoint
include/net/sctp/sctp.h
include/net/sctp/structs.h
net/sctp/endpointola.c
net/sctp/sctp_diag.c
net/sctp/socket.c
* net: fix use-after-free in tw_timer_handler
net/ipv4/af_inet.c
Input: spaceball - fix parsing of movement data packets
Input: appletouch - initialize work before device registration
scsi: vmw_pvscsi: Set residual data length conditionally
* binder: fix async_free_space accounting for empty parcels
drivers/android/binder_alloc.c
* usb: gadget: f_fs: Clear ffs_eventfd in ffs_data_clear.
drivers/usb/gadget/function/f_fs.c
* xhci: Fresco FL1100 controller should not have BROKEN_MSI quirk set.
drivers/usb/host/xhci-pci.c
* uapi: fix linux/nfc.h userspace compilation errors
include/uapi/linux/nfc.h
* nfc: uapi: use kernel size_t to fix user-space builds
include/uapi/linux/nfc.h
fsl/fman: Fix missing put_device() call in fman_port_probe
NFC: st21nfca: Fix memory leak in device probe and remove
net: usb: pegasus: Do not drop long Ethernet frames
scsi: lpfc: Terminate string in lpfc_debugfs_nvmeio_trc_write()
* selinux: initialize proto variable in selinux_ip_postroute_compat()
security/selinux/hooks.c
recordmcount.pl: fix typo in s390 mcount regex
platform/x86: apple-gmux: use resource_size() with res
tee: handle lookup of shm with reference count 0
* HID: asus: Add depends on USB_HID to HID_ASUS Kconfig option
drivers/hid/Kconfig
Merge 4.14.260 into android-4.14-stable
Linux 4.14.260
phonet/pep: refuse to enable an unbound pipe
hamradio: improve the incomplete fix to avoid NPD
hamradio: defer ax25 kfree after unregister_netdev
ax25: NPD bug when detaching AX25 device
hwmon: (lm90) Do not report 'busy' status bit as alarm
KVM: VMX: Fix stale docs for kvm-intel.emulate_invalid_guest_state
* usb: gadget: u_ether: fix race in setting MAC address in setup phase
drivers/usb/gadget/function/u_ether.c
* f2fs: fix to do sanity check on last xattr entry in __f2fs_setxattr()
fs/f2fs/xattr.c
ARM: 9169/1: entry: fix Thumb2 bug in iWMMXt exception handling
pinctrl: stm32: consider the GPIO offset to expose all the GPIO lines
x86/pkey: Fix undefined behaviour with PKRU_WD_BIT
Input: atmel_mxt_ts - fix double free in mxt_read_info_block
ALSA: drivers: opl3: Fix incorrect use of vp->state
* ALSA: jack: Check the return value of kstrdup()
sound/core/jack.c
hwmon: (lm90) Fix usage of CONFIG2 register in detect function
sfc: falcon: Check null pointer of rx_queue->page_ring
drivers: net: smc911x: Check for error irq
fjes: Check for error irq
* bonding: fix ad_actor_system option setting to default
drivers/net/bonding/bond_options.c
* net: skip virtio_net_hdr_set_proto if protocol already set
include/linux/virtio_net.h
* net: accept UFOv6 packages in virtio_net_hdr_to_skb
include/linux/virtio_net.h
qlcnic: potential dereference null pointer of rx_queue->page_ring
* netfilter: fix regression in looped (broad|multi)cast's MAC handling
net/netfilter/nfnetlink_log.c
net/netfilter/nfnetlink_queue.c
IB/qib: Fix memory leak in qib_user_sdma_queue_pkts()
spi: change clk_disable_unprepare to clk_unprepare
HID: holtek: fix mouse probing
can: kvaser_usb: get CAN clock frequency from device
net: usb: lan78xx: add Allied Telesis AT29M2-AF
Merge 4.14.259 into android-4.14-stable
Linux 4.14.259
xen/netback: don't queue unlimited number of packages
xen/netback: fix rx queue stall detection
xen/console: harden hvc_xen against event channel storms
xen/netfront: harden netfront against event channel storms
xen/blkfront: harden blkfront against event channel storms
* Input: touchscreen - avoid bitwise vs logical OR warning
drivers/input/touchscreen/of_touchscreen.c
* ARM: 8800/1: use choice for kernel unwinders
lib/Kconfig.debug
mwifiex: Remove unnecessary braces from HostCmd_SET_SEQ_NO_BSS_INFO
ARM: 8805/2: remove unneeded naked function usage
net: lan78xx: Avoid unnecessary self assignment
scsi: scsi_debug: Sanity check block descriptor length in resp_mode_select()
* fuse: annotate lock in fuse_reverse_inval_entry()
fs/fuse/dir.c
ARM: dts: imx6ull-pinfunc: Fix CSI_DATA07__ESAI_TX0 pad name
firmware: arm_scpi: Fix string overflow in SCPI genpd driver
net: systemport: Add global locking for descriptor lifecycle
libata: if T_LENGTH is zero, dma direction should be DMA_NONE
* timekeeping: Really make sure wall_to_monotonic isn't positive
kernel/time/timekeeping.c
USB: serial: option: add Telit FN990 compositions
* PCI/MSI: Mask MSI-X vectors only on success
drivers/pci/msi.c
* PCI/MSI: Clear PCI_MSIX_FLAGS_MASKALL on error
drivers/pci/msi.c
* USB: gadget: bRequestType is a bitfield, not a enum
drivers/usb/gadget/composite.c
* sit: do not call ipip6_dev_free() from sit_init_net()
net/ipv6/sit.c
* net/packet: rx_owner_map depends on pg_vec
net/packet/af_packet.c
ixgbe: set X550 MDIO speed before talking to PHY
igbvf: fix double free in `igbvf_probe`
soc/tegra: fuse: Fix bitwise vs. logical OR warning
dmaengine: st_fdma: fix MODULE_ALIAS
ARM: socfpga: dts: fix qspi node compatible
x86/sme: Explicitly map new EFI memmap table as encrypted
* x86: Make ARCH_USE_MEMREMAP_PROT a generic Kconfig symbol
arch/Kconfig
nfsd: fix use-after-free due to delegation race
* audit: improve robustness of the audit queue handling
kernel/audit.c
dm btree remove: fix use after free in rebalance_children()
recordmcount.pl: look for jgnop instruction as well as bcrl on s390
mac80211: send ADDBA requests using the tid/queue of the aggregation session
hwmon: (dell-smm) Fix warning on /proc/i8k creation error
* bpf: fix panic due to oob in bpf_prog_test_run_skb
net/bpf/test_run.c
tracing: Fix a kmemleak false positive in tracing_map
* net: netlink: af_netlink: Prevent empty skb by adding a check on len.
net/netlink/af_netlink.c
i2c: rk3x: Handle a spurious start completion interrupt flag
parisc/agp: Annotate parisc agp init functions with __init
net/mlx4_en: Update reported link modes for 1/10G
drm/msm/dsi: set default num_data_lanes
nfc: fix segfault in nfc_genl_dump_devices_done
* FROMGIT: USB: gadget: bRequestType is a bitfield, not a enum
drivers/usb/gadget/composite.c
Merge 4.14.258 into android-4.14-stable
Linux 4.14.258
irqchip: nvic: Fix offset for Interrupt Priority Offsets
* irqchip/irq-gic-v3-its.c: Force synchronisation when issuing INVALL
drivers/irqchip/irq-gic-v3-its.c
irqchip/armada-370-xp: Fix support for Multi-MSI interrupts
irqchip/armada-370-xp: Fix return value of armada_370_xp_msi_alloc()
iio: accel: kxcjk-1013: Fix possible memory leak in probe and remove
iio: adc: axp20x_adc: fix charging current reporting on AXP22x
iio: dln2: Check return value of devm_iio_trigger_register()
iio: dln2-adc: Fix lockdep complaint
iio: itg3200: Call iio_trigger_notify_done() on error
iio: kxsd9: Don't return error code in trigger handler
iio: ltr501: Don't return error code in trigger handler
iio: mma8452: Fix trigger reference couting
iio: stk3310: Don't return error code in interrupt handler
iio: trigger: stm32-timer: fix MODULE_ALIAS
iio: trigger: Fix reference counting
* usb: core: config: using bit mask instead of individual bits
drivers/usb/core/config.c
* xhci: Remove CONFIG_USB_DEFAULT_PERSIST to prevent xHCI from runtime suspending
drivers/usb/host/xhci.c
* usb: core: config: fix validation of wMaxPacketValue entries
drivers/usb/core/config.c
* USB: gadget: zero allocate endpoint 0 buffers
drivers/usb/gadget/composite.c
* USB: gadget: detect too-big endpoint 0 requests
drivers/usb/gadget/composite.c
net/qla3xxx: fix an error code in ql_adapter_up()
* net, neigh: clear whole pneigh_entry at alloc time
net/core/neighbour.c
net: fec: only clear interrupt of handling queue in fec_enet_rx_queue()
net: altera: set a couple error code in probe()
* net: cdc_ncm: Allow for dwNtbOutMaxSize to be unset or zero
drivers/net/usb/cdc_ncm.c
qede: validate non LSO skb length
* block: fix ioprio_get(IOPRIO_WHO_PGRP) vs setuid(2)
block/ioprio.c
* tracefs: Set all files to the same group ownership as the mount option
fs/tracefs/inode.c
* signalfd: use wake_up_pollfree()
fs/signalfd.c
* binder: use wake_up_pollfree()
drivers/android/binder.c
* wait: add wake_up_pollfree()
include/linux/wait.h
kernel/sched/wait.c
libata: add horkage for ASMedia 1092
can: m_can: Disable and ignore ELO interrupt
can: pch_can: pch_can_rx_normal: fix use after free
* tracefs: Have new files inherit the ownership of their parent
fs/tracefs/inode.c
ALSA: pcm: oss: Handle missing errors in snd_pcm_oss_change_params*()
ALSA: pcm: oss: Limit the period size to 16MB
ALSA: pcm: oss: Fix negative period/buffer sizes
* ALSA: ctl: Fix copy of updated id with element read/write
sound/core/control_compat.c
* mm: bdi: initialize bdi_min_ratio when bdi is unregistered
mm/backing-dev.c
IB/hfi1: Correct guard on eager buffer deallocation
seg6: fix the iif in the IPv6 socket control block
nfp: Fix memory leak in nfp_cpp_area_cache_add()
* bpf: Fix the off-by-two error in range markings
kernel/bpf/verifier.c
nfc: fix potential NULL pointer deref in nfc_genl_dump_ses_done
can: sja1000: fix use after free in ems_pcmcia_add_card()
HID: check for valid USB device for many HID drivers
HID: wacom: fix problems when device is not a valid USB device
* HID: add USB_HID dependancy on some USB HID drivers
drivers/hid/Kconfig
* HID: add USB_HID dependancy to hid-chicony
drivers/hid/Kconfig
* HID: add USB_HID dependancy to hid-prodikeys
drivers/hid/Kconfig
* HID: add hid_is_usb() function to make it simpler for USB detection
include/linux/hid.h
* UPSTREAM: USB: gadget: zero allocate endpoint 0 buffers
drivers/usb/gadget/composite.c
* UPSTREAM: USB: gadget: detect too-big endpoint 0 requests
drivers/usb/gadget/composite.c
Bug: 213962841
Change-Id: I69af3b9152e218567ff363383d8cde53f6c9dd15
Signed-off-by: Lucas Wei <lucaswei@google.com>
1037 lines
36 KiB
C
1037 lines
36 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef _LINUX_WAIT_H
|
|
#define _LINUX_WAIT_H
|
|
/*
|
|
* Linux wait queue related types and methods
|
|
*/
|
|
#include <linux/list.h>
|
|
#include <linux/stddef.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/sched/debug.h>
|
|
|
|
#include <asm/current.h>
|
|
#include <uapi/linux/wait.h>
|
|
|
|
typedef struct wait_queue_entry wait_queue_entry_t;
|
|
|
|
typedef int (*wait_queue_func_t)(struct wait_queue_entry *wq_entry, unsigned mode, int flags, void *key);
|
|
int default_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int flags, void *key);
|
|
|
|
/* wait_queue_entry::flags */
|
|
#define WQ_FLAG_EXCLUSIVE 0x01
|
|
#define WQ_FLAG_WOKEN 0x02
|
|
#define WQ_FLAG_BOOKMARK 0x04
|
|
|
|
/*
|
|
* A single wait-queue entry structure:
|
|
*/
|
|
struct wait_queue_entry {
|
|
unsigned int flags;
|
|
void *private;
|
|
wait_queue_func_t func;
|
|
struct list_head entry;
|
|
};
|
|
|
|
struct wait_queue_head {
|
|
spinlock_t lock;
|
|
struct list_head head;
|
|
};
|
|
typedef struct wait_queue_head wait_queue_head_t;
|
|
|
|
struct task_struct;
|
|
|
|
/*
|
|
* Macros for declaration and initialisaton of the datatypes
|
|
*/
|
|
|
|
#define __WAITQUEUE_INITIALIZER(name, tsk) { \
|
|
.private = tsk, \
|
|
.func = default_wake_function, \
|
|
.entry = { NULL, NULL } }
|
|
|
|
#define DECLARE_WAITQUEUE(name, tsk) \
|
|
struct wait_queue_entry name = __WAITQUEUE_INITIALIZER(name, tsk)
|
|
|
|
#define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
|
|
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \
|
|
.head = { &(name).head, &(name).head } }
|
|
|
|
#define DECLARE_WAIT_QUEUE_HEAD(name) \
|
|
struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
|
|
|
|
extern void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *name, struct lock_class_key *);
|
|
|
|
#define init_waitqueue_head(wq_head) \
|
|
do { \
|
|
static struct lock_class_key __key; \
|
|
\
|
|
__init_waitqueue_head((wq_head), #wq_head, &__key); \
|
|
} while (0)
|
|
|
|
#ifdef CONFIG_LOCKDEP
|
|
# define __WAIT_QUEUE_HEAD_INIT_ONSTACK(name) \
|
|
({ init_waitqueue_head(&name); name; })
|
|
# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \
|
|
struct wait_queue_head name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name)
|
|
#else
|
|
# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name)
|
|
#endif
|
|
|
|
static inline void init_waitqueue_entry(struct wait_queue_entry *wq_entry, struct task_struct *p)
|
|
{
|
|
wq_entry->flags = 0;
|
|
wq_entry->private = p;
|
|
wq_entry->func = default_wake_function;
|
|
}
|
|
|
|
static inline void
|
|
init_waitqueue_func_entry(struct wait_queue_entry *wq_entry, wait_queue_func_t func)
|
|
{
|
|
wq_entry->flags = 0;
|
|
wq_entry->private = NULL;
|
|
wq_entry->func = func;
|
|
}
|
|
|
|
/**
|
|
* waitqueue_active -- locklessly test for waiters on the queue
|
|
* @wq_head: the waitqueue to test for waiters
|
|
*
|
|
* returns true if the wait list is not empty
|
|
*
|
|
* NOTE: this function is lockless and requires care, incorrect usage _will_
|
|
* lead to sporadic and non-obvious failure.
|
|
*
|
|
* Use either while holding wait_queue_head::lock or when used for wakeups
|
|
* with an extra smp_mb() like:
|
|
*
|
|
* CPU0 - waker CPU1 - waiter
|
|
*
|
|
* for (;;) {
|
|
* @cond = true; prepare_to_wait(&wq_head, &wait, state);
|
|
* smp_mb(); // smp_mb() from set_current_state()
|
|
* if (waitqueue_active(wq_head)) if (@cond)
|
|
* wake_up(wq_head); break;
|
|
* schedule();
|
|
* }
|
|
* finish_wait(&wq_head, &wait);
|
|
*
|
|
* Because without the explicit smp_mb() it's possible for the
|
|
* waitqueue_active() load to get hoisted over the @cond store such that we'll
|
|
* observe an empty wait list while the waiter might not observe @cond.
|
|
*
|
|
* Also note that this 'optimization' trades a spin_lock() for an smp_mb(),
|
|
* which (when the lock is uncontended) are of roughly equal cost.
|
|
*/
|
|
static inline int waitqueue_active(struct wait_queue_head *wq_head)
|
|
{
|
|
return !list_empty(&wq_head->head);
|
|
}
|
|
|
|
/**
|
|
* wq_has_sleeper - check if there are any waiting processes
|
|
* @wq_head: wait queue head
|
|
*
|
|
* Returns true if wq_head has waiting processes
|
|
*
|
|
* Please refer to the comment for waitqueue_active.
|
|
*/
|
|
static inline bool wq_has_sleeper(struct wait_queue_head *wq_head)
|
|
{
|
|
/*
|
|
* We need to be sure we are in sync with the
|
|
* add_wait_queue modifications to the wait queue.
|
|
*
|
|
* This memory barrier should be paired with one on the
|
|
* waiting side.
|
|
*/
|
|
smp_mb();
|
|
return waitqueue_active(wq_head);
|
|
}
|
|
|
|
extern void add_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
|
|
extern void add_wait_queue_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
|
|
extern void remove_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
|
|
|
|
static inline void __add_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
|
|
{
|
|
list_add(&wq_entry->entry, &wq_head->head);
|
|
}
|
|
|
|
/*
|
|
* Used for wake-one threads:
|
|
*/
|
|
static inline void
|
|
__add_wait_queue_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
|
|
{
|
|
wq_entry->flags |= WQ_FLAG_EXCLUSIVE;
|
|
__add_wait_queue(wq_head, wq_entry);
|
|
}
|
|
|
|
static inline void __add_wait_queue_entry_tail(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
|
|
{
|
|
list_add_tail(&wq_entry->entry, &wq_head->head);
|
|
}
|
|
|
|
static inline void
|
|
__add_wait_queue_entry_tail_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
|
|
{
|
|
wq_entry->flags |= WQ_FLAG_EXCLUSIVE;
|
|
__add_wait_queue_entry_tail(wq_head, wq_entry);
|
|
}
|
|
|
|
static inline void
|
|
__remove_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
|
|
{
|
|
list_del(&wq_entry->entry);
|
|
}
|
|
|
|
void __wake_up(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key);
|
|
void __wake_up_locked_key(struct wait_queue_head *wq_head, unsigned int mode, void *key);
|
|
void __wake_up_locked_key_bookmark(struct wait_queue_head *wq_head,
|
|
unsigned int mode, void *key, wait_queue_entry_t *bookmark);
|
|
void __wake_up_sync_key(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key);
|
|
void __wake_up_locked(struct wait_queue_head *wq_head, unsigned int mode, int nr);
|
|
void __wake_up_sync(struct wait_queue_head *wq_head, unsigned int mode, int nr);
|
|
void __wake_up_pollfree(struct wait_queue_head *wq_head);
|
|
|
|
#define wake_up(x) __wake_up(x, TASK_NORMAL, 1, NULL)
|
|
#define wake_up_nr(x, nr) __wake_up(x, TASK_NORMAL, nr, NULL)
|
|
#define wake_up_all(x) __wake_up(x, TASK_NORMAL, 0, NULL)
|
|
#define wake_up_locked(x) __wake_up_locked((x), TASK_NORMAL, 1)
|
|
#define wake_up_all_locked(x) __wake_up_locked((x), TASK_NORMAL, 0)
|
|
|
|
#define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
|
|
#define wake_up_interruptible_nr(x, nr) __wake_up(x, TASK_INTERRUPTIBLE, nr, NULL)
|
|
#define wake_up_interruptible_all(x) __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
|
|
#define wake_up_interruptible_sync(x) __wake_up_sync((x), TASK_INTERRUPTIBLE, 1)
|
|
|
|
/*
|
|
* Wakeup macros to be used to report events to the targets.
|
|
*/
|
|
#define wake_up_poll(x, m) \
|
|
__wake_up(x, TASK_NORMAL, 1, (void *) (m))
|
|
#define wake_up_locked_poll(x, m) \
|
|
__wake_up_locked_key((x), TASK_NORMAL, (void *) (m))
|
|
#define wake_up_interruptible_poll(x, m) \
|
|
__wake_up(x, TASK_INTERRUPTIBLE, 1, (void *) (m))
|
|
#define wake_up_interruptible_sync_poll(x, m) \
|
|
__wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
|
|
|
|
/**
|
|
* wake_up_pollfree - signal that a polled waitqueue is going away
|
|
* @wq_head: the wait queue head
|
|
*
|
|
* In the very rare cases where a ->poll() implementation uses a waitqueue whose
|
|
* lifetime is tied to a task rather than to the 'struct file' being polled,
|
|
* this function must be called before the waitqueue is freed so that
|
|
* non-blocking polls (e.g. epoll) are notified that the queue is going away.
|
|
*
|
|
* The caller must also RCU-delay the freeing of the wait_queue_head, e.g. via
|
|
* an explicit synchronize_rcu() or call_rcu(), or via SLAB_TYPESAFE_BY_RCU.
|
|
*/
|
|
static inline void wake_up_pollfree(struct wait_queue_head *wq_head)
|
|
{
|
|
/*
|
|
* For performance reasons, we don't always take the queue lock here.
|
|
* Therefore, we might race with someone removing the last entry from
|
|
* the queue, and proceed while they still hold the queue lock.
|
|
* However, rcu_read_lock() is required to be held in such cases, so we
|
|
* can safely proceed with an RCU-delayed free.
|
|
*/
|
|
if (waitqueue_active(wq_head))
|
|
__wake_up_pollfree(wq_head);
|
|
}
|
|
|
|
#define ___wait_cond_timeout(condition) \
|
|
({ \
|
|
bool __cond = (condition); \
|
|
if (__cond && !__ret) \
|
|
__ret = 1; \
|
|
__cond || !__ret; \
|
|
})
|
|
|
|
#define ___wait_is_interruptible(state) \
|
|
(!__builtin_constant_p(state) || \
|
|
state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE) \
|
|
|
|
extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);
|
|
|
|
/*
|
|
* The below macro ___wait_event() has an explicit shadow of the __ret
|
|
* variable when used from the wait_event_*() macros.
|
|
*
|
|
* This is so that both can use the ___wait_cond_timeout() construct
|
|
* to wrap the condition.
|
|
*
|
|
* The type inconsistency of the wait_event_*() __ret variable is also
|
|
* on purpose; we use long where we can return timeout values and int
|
|
* otherwise.
|
|
*/
|
|
|
|
#define ___wait_event(wq_head, condition, state, exclusive, ret, cmd) \
|
|
({ \
|
|
__label__ __out; \
|
|
struct wait_queue_entry __wq_entry; \
|
|
long __ret = ret; /* explicit shadow */ \
|
|
\
|
|
init_wait_entry(&__wq_entry, exclusive ? WQ_FLAG_EXCLUSIVE : 0); \
|
|
for (;;) { \
|
|
long __int = prepare_to_wait_event(&wq_head, &__wq_entry, state);\
|
|
\
|
|
if (condition) \
|
|
break; \
|
|
\
|
|
if (___wait_is_interruptible(state) && __int) { \
|
|
__ret = __int; \
|
|
goto __out; \
|
|
} \
|
|
\
|
|
cmd; \
|
|
} \
|
|
finish_wait(&wq_head, &__wq_entry); \
|
|
__out: __ret; \
|
|
})
|
|
|
|
#define __wait_event(wq_head, condition) \
|
|
(void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
|
|
schedule())
|
|
|
|
/**
|
|
* wait_event - sleep until a condition gets true
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
*
|
|
* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
|
|
* @condition evaluates to true. The @condition is checked each time
|
|
* the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*/
|
|
#define wait_event(wq_head, condition) \
|
|
do { \
|
|
might_sleep(); \
|
|
if (condition) \
|
|
break; \
|
|
__wait_event(wq_head, condition); \
|
|
} while (0)
|
|
|
|
#define __io_wait_event(wq_head, condition) \
|
|
(void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
|
|
io_schedule())
|
|
|
|
/*
|
|
* io_wait_event() -- like wait_event() but with io_schedule()
|
|
*/
|
|
#define io_wait_event(wq_head, condition) \
|
|
do { \
|
|
might_sleep(); \
|
|
if (condition) \
|
|
break; \
|
|
__io_wait_event(wq_head, condition); \
|
|
} while (0)
|
|
|
|
#define __wait_event_freezable(wq_head, condition) \
|
|
___wait_event(wq_head, condition, TASK_INTERRUPTIBLE, 0, 0, \
|
|
schedule(); try_to_freeze())
|
|
|
|
/**
|
|
* wait_event_freezable - sleep (or freeze) until a condition gets true
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE -- so as not to contribute
|
|
* to system load) until the @condition evaluates to true. The
|
|
* @condition is checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*/
|
|
#define wait_event_freezable(wq_head, condition) \
|
|
({ \
|
|
int __ret = 0; \
|
|
might_sleep(); \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_freezable(wq_head, condition); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_timeout(wq_head, condition, timeout) \
|
|
___wait_event(wq_head, ___wait_cond_timeout(condition), \
|
|
TASK_UNINTERRUPTIBLE, 0, timeout, \
|
|
__ret = schedule_timeout(__ret))
|
|
|
|
/**
|
|
* wait_event_timeout - sleep until a condition gets true or a timeout elapses
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @timeout: timeout, in jiffies
|
|
*
|
|
* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
|
|
* @condition evaluates to true. The @condition is checked each time
|
|
* the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* Returns:
|
|
* 0 if the @condition evaluated to %false after the @timeout elapsed,
|
|
* 1 if the @condition evaluated to %true after the @timeout elapsed,
|
|
* or the remaining jiffies (at least 1) if the @condition evaluated
|
|
* to %true before the @timeout elapsed.
|
|
*/
|
|
#define wait_event_timeout(wq_head, condition, timeout) \
|
|
({ \
|
|
long __ret = timeout; \
|
|
might_sleep(); \
|
|
if (!___wait_cond_timeout(condition)) \
|
|
__ret = __wait_event_timeout(wq_head, condition, timeout); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_freezable_timeout(wq_head, condition, timeout) \
|
|
___wait_event(wq_head, ___wait_cond_timeout(condition), \
|
|
TASK_INTERRUPTIBLE, 0, timeout, \
|
|
__ret = schedule_timeout(__ret); try_to_freeze())
|
|
|
|
/*
|
|
* like wait_event_timeout() -- except it uses TASK_INTERRUPTIBLE to avoid
|
|
* increasing load and is freezable.
|
|
*/
|
|
#define wait_event_freezable_timeout(wq_head, condition, timeout) \
|
|
({ \
|
|
long __ret = timeout; \
|
|
might_sleep(); \
|
|
if (!___wait_cond_timeout(condition)) \
|
|
__ret = __wait_event_freezable_timeout(wq_head, condition, timeout); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_exclusive_cmd(wq_head, condition, cmd1, cmd2) \
|
|
(void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 1, 0, \
|
|
cmd1; schedule(); cmd2)
|
|
/*
|
|
* Just like wait_event_cmd(), except it sets exclusive flag
|
|
*/
|
|
#define wait_event_exclusive_cmd(wq_head, condition, cmd1, cmd2) \
|
|
do { \
|
|
if (condition) \
|
|
break; \
|
|
__wait_event_exclusive_cmd(wq_head, condition, cmd1, cmd2); \
|
|
} while (0)
|
|
|
|
#define __wait_event_cmd(wq_head, condition, cmd1, cmd2) \
|
|
(void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
|
|
cmd1; schedule(); cmd2)
|
|
|
|
/**
|
|
* wait_event_cmd - sleep until a condition gets true
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @cmd1: the command will be executed before sleep
|
|
* @cmd2: the command will be executed after sleep
|
|
*
|
|
* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
|
|
* @condition evaluates to true. The @condition is checked each time
|
|
* the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*/
|
|
#define wait_event_cmd(wq_head, condition, cmd1, cmd2) \
|
|
do { \
|
|
if (condition) \
|
|
break; \
|
|
__wait_event_cmd(wq_head, condition, cmd1, cmd2); \
|
|
} while (0)
|
|
|
|
#define __wait_event_interruptible(wq_head, condition) \
|
|
___wait_event(wq_head, condition, TASK_INTERRUPTIBLE, 0, 0, \
|
|
schedule())
|
|
|
|
/**
|
|
* wait_event_interruptible - sleep until a condition gets true
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* The function will return -ERESTARTSYS if it was interrupted by a
|
|
* signal and 0 if @condition evaluated to true.
|
|
*/
|
|
#define wait_event_interruptible(wq_head, condition) \
|
|
({ \
|
|
int __ret = 0; \
|
|
might_sleep(); \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_interruptible(wq_head, condition); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_interruptible_timeout(wq_head, condition, timeout) \
|
|
___wait_event(wq_head, ___wait_cond_timeout(condition), \
|
|
TASK_INTERRUPTIBLE, 0, timeout, \
|
|
__ret = schedule_timeout(__ret))
|
|
|
|
/**
|
|
* wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @timeout: timeout, in jiffies
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* Returns:
|
|
* 0 if the @condition evaluated to %false after the @timeout elapsed,
|
|
* 1 if the @condition evaluated to %true after the @timeout elapsed,
|
|
* the remaining jiffies (at least 1) if the @condition evaluated
|
|
* to %true before the @timeout elapsed, or -%ERESTARTSYS if it was
|
|
* interrupted by a signal.
|
|
*/
|
|
#define wait_event_interruptible_timeout(wq_head, condition, timeout) \
|
|
({ \
|
|
long __ret = timeout; \
|
|
might_sleep(); \
|
|
if (!___wait_cond_timeout(condition)) \
|
|
__ret = __wait_event_interruptible_timeout(wq_head, \
|
|
condition, timeout); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_hrtimeout(wq_head, condition, timeout, state) \
|
|
({ \
|
|
int __ret = 0; \
|
|
struct hrtimer_sleeper __t; \
|
|
\
|
|
hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); \
|
|
hrtimer_init_sleeper(&__t, current); \
|
|
if ((timeout) != KTIME_MAX) \
|
|
hrtimer_start_range_ns(&__t.timer, timeout, \
|
|
current->timer_slack_ns, \
|
|
HRTIMER_MODE_REL); \
|
|
\
|
|
__ret = ___wait_event(wq_head, condition, state, 0, 0, \
|
|
if (!__t.task) { \
|
|
__ret = -ETIME; \
|
|
break; \
|
|
} \
|
|
schedule()); \
|
|
\
|
|
hrtimer_cancel(&__t.timer); \
|
|
destroy_hrtimer_on_stack(&__t.timer); \
|
|
__ret; \
|
|
})
|
|
|
|
/**
|
|
* wait_event_hrtimeout - sleep until a condition gets true or a timeout elapses
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @timeout: timeout, as a ktime_t
|
|
*
|
|
* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* The function returns 0 if @condition became true, or -ETIME if the timeout
|
|
* elapsed.
|
|
*/
|
|
#define wait_event_hrtimeout(wq_head, condition, timeout) \
|
|
({ \
|
|
int __ret = 0; \
|
|
might_sleep(); \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_hrtimeout(wq_head, condition, timeout, \
|
|
TASK_UNINTERRUPTIBLE); \
|
|
__ret; \
|
|
})
|
|
|
|
/**
|
|
* wait_event_interruptible_hrtimeout - sleep until a condition gets true or a timeout elapses
|
|
* @wq: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @timeout: timeout, as a ktime_t
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* The function returns 0 if @condition became true, -ERESTARTSYS if it was
|
|
* interrupted by a signal, or -ETIME if the timeout elapsed.
|
|
*/
|
|
#define wait_event_interruptible_hrtimeout(wq, condition, timeout) \
|
|
({ \
|
|
long __ret = 0; \
|
|
might_sleep(); \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_hrtimeout(wq, condition, timeout, \
|
|
TASK_INTERRUPTIBLE); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_interruptible_exclusive(wq, condition) \
|
|
___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \
|
|
schedule())
|
|
|
|
#define wait_event_interruptible_exclusive(wq, condition) \
|
|
({ \
|
|
int __ret = 0; \
|
|
might_sleep(); \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_interruptible_exclusive(wq, condition); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_killable_exclusive(wq, condition) \
|
|
___wait_event(wq, condition, TASK_KILLABLE, 1, 0, \
|
|
schedule())
|
|
|
|
#define wait_event_killable_exclusive(wq, condition) \
|
|
({ \
|
|
int __ret = 0; \
|
|
might_sleep(); \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_killable_exclusive(wq, condition); \
|
|
__ret; \
|
|
})
|
|
|
|
|
|
#define __wait_event_freezable_exclusive(wq, condition) \
|
|
___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \
|
|
schedule(); try_to_freeze())
|
|
|
|
#define wait_event_freezable_exclusive(wq, condition) \
|
|
({ \
|
|
int __ret = 0; \
|
|
might_sleep(); \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_freezable_exclusive(wq, condition); \
|
|
__ret; \
|
|
})
|
|
|
|
extern int do_wait_intr(wait_queue_head_t *, wait_queue_entry_t *);
|
|
extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *);
|
|
|
|
#define __wait_event_interruptible_locked(wq, condition, exclusive, fn) \
|
|
({ \
|
|
int __ret; \
|
|
DEFINE_WAIT(__wait); \
|
|
if (exclusive) \
|
|
__wait.flags |= WQ_FLAG_EXCLUSIVE; \
|
|
do { \
|
|
__ret = fn(&(wq), &__wait); \
|
|
if (__ret) \
|
|
break; \
|
|
} while (!(condition)); \
|
|
__remove_wait_queue(&(wq), &__wait); \
|
|
__set_current_state(TASK_RUNNING); \
|
|
__ret; \
|
|
})
|
|
|
|
|
|
/**
|
|
* wait_event_interruptible_locked - sleep until a condition gets true
|
|
* @wq: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq is woken up.
|
|
*
|
|
* It must be called with wq.lock being held. This spinlock is
|
|
* unlocked while sleeping but @condition testing is done while lock
|
|
* is held and when this macro exits the lock is held.
|
|
*
|
|
* The lock is locked/unlocked using spin_lock()/spin_unlock()
|
|
* functions which must match the way they are locked/unlocked outside
|
|
* of this macro.
|
|
*
|
|
* wake_up_locked() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* The function will return -ERESTARTSYS if it was interrupted by a
|
|
* signal and 0 if @condition evaluated to true.
|
|
*/
|
|
#define wait_event_interruptible_locked(wq, condition) \
|
|
((condition) \
|
|
? 0 : __wait_event_interruptible_locked(wq, condition, 0, do_wait_intr))
|
|
|
|
/**
|
|
* wait_event_interruptible_locked_irq - sleep until a condition gets true
|
|
* @wq: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq is woken up.
|
|
*
|
|
* It must be called with wq.lock being held. This spinlock is
|
|
* unlocked while sleeping but @condition testing is done while lock
|
|
* is held and when this macro exits the lock is held.
|
|
*
|
|
* The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
|
|
* functions which must match the way they are locked/unlocked outside
|
|
* of this macro.
|
|
*
|
|
* wake_up_locked() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* The function will return -ERESTARTSYS if it was interrupted by a
|
|
* signal and 0 if @condition evaluated to true.
|
|
*/
|
|
#define wait_event_interruptible_locked_irq(wq, condition) \
|
|
((condition) \
|
|
? 0 : __wait_event_interruptible_locked(wq, condition, 0, do_wait_intr_irq))
|
|
|
|
/**
|
|
* wait_event_interruptible_exclusive_locked - sleep exclusively until a condition gets true
|
|
* @wq: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq is woken up.
|
|
*
|
|
* It must be called with wq.lock being held. This spinlock is
|
|
* unlocked while sleeping but @condition testing is done while lock
|
|
* is held and when this macro exits the lock is held.
|
|
*
|
|
* The lock is locked/unlocked using spin_lock()/spin_unlock()
|
|
* functions which must match the way they are locked/unlocked outside
|
|
* of this macro.
|
|
*
|
|
* The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
|
|
* set thus when other process waits process on the list if this
|
|
* process is awaken further processes are not considered.
|
|
*
|
|
* wake_up_locked() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* The function will return -ERESTARTSYS if it was interrupted by a
|
|
* signal and 0 if @condition evaluated to true.
|
|
*/
|
|
#define wait_event_interruptible_exclusive_locked(wq, condition) \
|
|
((condition) \
|
|
? 0 : __wait_event_interruptible_locked(wq, condition, 1, do_wait_intr))
|
|
|
|
/**
|
|
* wait_event_interruptible_exclusive_locked_irq - sleep until a condition gets true
|
|
* @wq: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq is woken up.
|
|
*
|
|
* It must be called with wq.lock being held. This spinlock is
|
|
* unlocked while sleeping but @condition testing is done while lock
|
|
* is held and when this macro exits the lock is held.
|
|
*
|
|
* The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
|
|
* functions which must match the way they are locked/unlocked outside
|
|
* of this macro.
|
|
*
|
|
* The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
|
|
* set thus when other process waits process on the list if this
|
|
* process is awaken further processes are not considered.
|
|
*
|
|
* wake_up_locked() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* The function will return -ERESTARTSYS if it was interrupted by a
|
|
* signal and 0 if @condition evaluated to true.
|
|
*/
|
|
#define wait_event_interruptible_exclusive_locked_irq(wq, condition) \
|
|
((condition) \
|
|
? 0 : __wait_event_interruptible_locked(wq, condition, 1, do_wait_intr_irq))
|
|
|
|
|
|
#define __wait_event_killable(wq, condition) \
|
|
___wait_event(wq, condition, TASK_KILLABLE, 0, 0, schedule())
|
|
|
|
/**
|
|
* wait_event_killable - sleep until a condition gets true
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
*
|
|
* The process is put to sleep (TASK_KILLABLE) until the
|
|
* @condition evaluates to true or a signal is received.
|
|
* The @condition is checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* The function will return -ERESTARTSYS if it was interrupted by a
|
|
* signal and 0 if @condition evaluated to true.
|
|
*/
|
|
#define wait_event_killable(wq_head, condition) \
|
|
({ \
|
|
int __ret = 0; \
|
|
might_sleep(); \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_killable(wq_head, condition); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_killable_timeout(wq_head, condition, timeout) \
|
|
___wait_event(wq_head, ___wait_cond_timeout(condition), \
|
|
TASK_KILLABLE, 0, timeout, \
|
|
__ret = schedule_timeout(__ret))
|
|
|
|
/**
|
|
* wait_event_killable_timeout - sleep until a condition gets true or a timeout elapses
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @timeout: timeout, in jiffies
|
|
*
|
|
* The process is put to sleep (TASK_KILLABLE) until the
|
|
* @condition evaluates to true or a kill signal is received.
|
|
* The @condition is checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* Returns:
|
|
* 0 if the @condition evaluated to %false after the @timeout elapsed,
|
|
* 1 if the @condition evaluated to %true after the @timeout elapsed,
|
|
* the remaining jiffies (at least 1) if the @condition evaluated
|
|
* to %true before the @timeout elapsed, or -%ERESTARTSYS if it was
|
|
* interrupted by a kill signal.
|
|
*
|
|
* Only kill signals interrupt this process.
|
|
*/
|
|
#define wait_event_killable_timeout(wq_head, condition, timeout) \
|
|
({ \
|
|
long __ret = timeout; \
|
|
might_sleep(); \
|
|
if (!___wait_cond_timeout(condition)) \
|
|
__ret = __wait_event_killable_timeout(wq_head, \
|
|
condition, timeout); \
|
|
__ret; \
|
|
})
|
|
|
|
|
|
#define __wait_event_lock_irq(wq_head, condition, lock, cmd) \
|
|
(void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
|
|
spin_unlock_irq(&lock); \
|
|
cmd; \
|
|
schedule(); \
|
|
spin_lock_irq(&lock))
|
|
|
|
/**
|
|
* wait_event_lock_irq_cmd - sleep until a condition gets true. The
|
|
* condition is checked under the lock. This
|
|
* is expected to be called with the lock
|
|
* taken.
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @lock: a locked spinlock_t, which will be released before cmd
|
|
* and schedule() and reacquired afterwards.
|
|
* @cmd: a command which is invoked outside the critical section before
|
|
* sleep
|
|
*
|
|
* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
|
|
* @condition evaluates to true. The @condition is checked each time
|
|
* the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* This is supposed to be called while holding the lock. The lock is
|
|
* dropped before invoking the cmd and going to sleep and is reacquired
|
|
* afterwards.
|
|
*/
|
|
#define wait_event_lock_irq_cmd(wq_head, condition, lock, cmd) \
|
|
do { \
|
|
if (condition) \
|
|
break; \
|
|
__wait_event_lock_irq(wq_head, condition, lock, cmd); \
|
|
} while (0)
|
|
|
|
/**
|
|
* wait_event_lock_irq - sleep until a condition gets true. The
|
|
* condition is checked under the lock. This
|
|
* is expected to be called with the lock
|
|
* taken.
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @lock: a locked spinlock_t, which will be released before schedule()
|
|
* and reacquired afterwards.
|
|
*
|
|
* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
|
|
* @condition evaluates to true. The @condition is checked each time
|
|
* the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* This is supposed to be called while holding the lock. The lock is
|
|
* dropped before going to sleep and is reacquired afterwards.
|
|
*/
|
|
#define wait_event_lock_irq(wq_head, condition, lock) \
|
|
do { \
|
|
if (condition) \
|
|
break; \
|
|
__wait_event_lock_irq(wq_head, condition, lock, ); \
|
|
} while (0)
|
|
|
|
|
|
#define __wait_event_interruptible_lock_irq(wq_head, condition, lock, cmd) \
|
|
___wait_event(wq_head, condition, TASK_INTERRUPTIBLE, 0, 0, \
|
|
spin_unlock_irq(&lock); \
|
|
cmd; \
|
|
schedule(); \
|
|
spin_lock_irq(&lock))
|
|
|
|
/**
|
|
* wait_event_interruptible_lock_irq_cmd - sleep until a condition gets true.
|
|
* The condition is checked under the lock. This is expected to
|
|
* be called with the lock taken.
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @lock: a locked spinlock_t, which will be released before cmd and
|
|
* schedule() and reacquired afterwards.
|
|
* @cmd: a command which is invoked outside the critical section before
|
|
* sleep
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or a signal is received. The @condition is
|
|
* checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* This is supposed to be called while holding the lock. The lock is
|
|
* dropped before invoking the cmd and going to sleep and is reacquired
|
|
* afterwards.
|
|
*
|
|
* The macro will return -ERESTARTSYS if it was interrupted by a signal
|
|
* and 0 if @condition evaluated to true.
|
|
*/
|
|
#define wait_event_interruptible_lock_irq_cmd(wq_head, condition, lock, cmd) \
|
|
({ \
|
|
int __ret = 0; \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_interruptible_lock_irq(wq_head, \
|
|
condition, lock, cmd); \
|
|
__ret; \
|
|
})
|
|
|
|
/**
|
|
* wait_event_interruptible_lock_irq - sleep until a condition gets true.
|
|
* The condition is checked under the lock. This is expected
|
|
* to be called with the lock taken.
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @lock: a locked spinlock_t, which will be released before schedule()
|
|
* and reacquired afterwards.
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or signal is received. The @condition is
|
|
* checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* This is supposed to be called while holding the lock. The lock is
|
|
* dropped before going to sleep and is reacquired afterwards.
|
|
*
|
|
* The macro will return -ERESTARTSYS if it was interrupted by a signal
|
|
* and 0 if @condition evaluated to true.
|
|
*/
|
|
#define wait_event_interruptible_lock_irq(wq_head, condition, lock) \
|
|
({ \
|
|
int __ret = 0; \
|
|
if (!(condition)) \
|
|
__ret = __wait_event_interruptible_lock_irq(wq_head, \
|
|
condition, lock,); \
|
|
__ret; \
|
|
})
|
|
|
|
#define __wait_event_interruptible_lock_irq_timeout(wq_head, condition, \
|
|
lock, timeout) \
|
|
___wait_event(wq_head, ___wait_cond_timeout(condition), \
|
|
TASK_INTERRUPTIBLE, 0, timeout, \
|
|
spin_unlock_irq(&lock); \
|
|
__ret = schedule_timeout(__ret); \
|
|
spin_lock_irq(&lock));
|
|
|
|
/**
|
|
* wait_event_interruptible_lock_irq_timeout - sleep until a condition gets
|
|
* true or a timeout elapses. The condition is checked under
|
|
* the lock. This is expected to be called with the lock taken.
|
|
* @wq_head: the waitqueue to wait on
|
|
* @condition: a C expression for the event to wait for
|
|
* @lock: a locked spinlock_t, which will be released before schedule()
|
|
* and reacquired afterwards.
|
|
* @timeout: timeout, in jiffies
|
|
*
|
|
* The process is put to sleep (TASK_INTERRUPTIBLE) until the
|
|
* @condition evaluates to true or signal is received. The @condition is
|
|
* checked each time the waitqueue @wq_head is woken up.
|
|
*
|
|
* wake_up() has to be called after changing any variable that could
|
|
* change the result of the wait condition.
|
|
*
|
|
* This is supposed to be called while holding the lock. The lock is
|
|
* dropped before going to sleep and is reacquired afterwards.
|
|
*
|
|
* The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it
|
|
* was interrupted by a signal, and the remaining jiffies otherwise
|
|
* if the condition evaluated to true before the timeout elapsed.
|
|
*/
|
|
#define wait_event_interruptible_lock_irq_timeout(wq_head, condition, lock, \
|
|
timeout) \
|
|
({ \
|
|
long __ret = timeout; \
|
|
if (!___wait_cond_timeout(condition)) \
|
|
__ret = __wait_event_interruptible_lock_irq_timeout( \
|
|
wq_head, condition, lock, timeout); \
|
|
__ret; \
|
|
})
|
|
|
|
/*
|
|
* Waitqueues which are removed from the waitqueue_head at wakeup time
|
|
*/
|
|
void prepare_to_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state);
|
|
void prepare_to_wait_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state);
|
|
long prepare_to_wait_event(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state);
|
|
void finish_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
|
|
long __sched wait_woken(struct wait_queue_entry *wq_entry, unsigned mode, long timeout);
|
|
int __sched woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
|
|
int __sched autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
|
|
|
|
#define DEFINE_WAIT_FUNC(name, function) \
|
|
struct wait_queue_entry name = { \
|
|
.private = current, \
|
|
.func = function, \
|
|
.entry = LIST_HEAD_INIT((name).entry), \
|
|
}
|
|
|
|
#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
|
|
|
|
#define init_wait(wait) \
|
|
do { \
|
|
(wait)->private = current; \
|
|
(wait)->func = autoremove_wake_function; \
|
|
INIT_LIST_HEAD(&(wait)->entry); \
|
|
(wait)->flags = 0; \
|
|
} while (0)
|
|
|
|
#endif /* _LINUX_WAIT_H */
|