wait.h revision 289644
1219820Sjeff/*- 2219820Sjeff * Copyright (c) 2010 Isilon Systems, Inc. 3219820Sjeff * Copyright (c) 2010 iX Systems, Inc. 4219820Sjeff * Copyright (c) 2010 Panasas, Inc. 5270710Shselasky * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd. 6219820Sjeff * All rights reserved. 7219820Sjeff * 8219820Sjeff * Redistribution and use in source and binary forms, with or without 9219820Sjeff * modification, are permitted provided that the following conditions 10219820Sjeff * are met: 11219820Sjeff * 1. Redistributions of source code must retain the above copyright 12219820Sjeff * notice unmodified, this list of conditions, and the following 13219820Sjeff * disclaimer. 14219820Sjeff * 2. Redistributions in binary form must reproduce the above copyright 15219820Sjeff * notice, this list of conditions and the following disclaimer in the 16219820Sjeff * documentation and/or other materials provided with the distribution. 17219820Sjeff * 18219820Sjeff * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 19219820Sjeff * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 20219820Sjeff * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 21219820Sjeff * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 22219820Sjeff * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23219820Sjeff * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24219820Sjeff * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25219820Sjeff * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26219820Sjeff * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27219820Sjeff * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28289644Shselasky * 29289644Shselasky * $FreeBSD: head/sys/ofed/include/linux/wait.h 289644 2015-10-20 19:08:26Z hselasky $ 30219820Sjeff */ 31219820Sjeff#ifndef _LINUX_WAIT_H_ 32219820Sjeff#define _LINUX_WAIT_H_ 33219820Sjeff 34219820Sjeff#include <linux/spinlock.h> 35219820Sjeff#include <linux/sched.h> 36219820Sjeff#include <linux/list.h> 37219820Sjeff 38219820Sjeff#include <sys/param.h> 39219820Sjeff#include <sys/systm.h> 40219820Sjeff#include <sys/sleepqueue.h> 41219820Sjeff#include <sys/kernel.h> 42219820Sjeff#include <sys/proc.h> 43219820Sjeff 44289564Shselaskytypedef struct { 45289564Shselasky} wait_queue_t; 46289564Shselasky 47289564Shselaskytypedef struct { 48219820Sjeff unsigned int wchan; 49289564Shselasky} wait_queue_head_t; 50219820Sjeff 51289564Shselasky#define init_waitqueue_head(x) \ 52289564Shselasky do { } while (0) 53219820Sjeff 54219820Sjeffstatic inline void 55289564Shselasky__wake_up(wait_queue_head_t *q, int all) 56219820Sjeff{ 57219820Sjeff int wakeup_swapper; 58219820Sjeff void *c; 59219820Sjeff 60219820Sjeff c = &q->wchan; 61219820Sjeff sleepq_lock(c); 62219820Sjeff if (all) 63219820Sjeff wakeup_swapper = sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0); 64219820Sjeff else 65219820Sjeff wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0); 66219820Sjeff sleepq_release(c); 67219820Sjeff if (wakeup_swapper) 68219820Sjeff kick_proc0(); 69219820Sjeff} 70219820Sjeff 71219820Sjeff#define wake_up(q) __wake_up(q, 0) 72219820Sjeff#define wake_up_nr(q, nr) __wake_up(q, 1) 73219820Sjeff#define wake_up_all(q) __wake_up(q, 1) 74219820Sjeff#define wake_up_interruptible(q) __wake_up(q, 0) 75219820Sjeff#define wake_up_interruptible_nr(q, nr) __wake_up(q, 1) 76219820Sjeff#define wake_up_interruptible_all(q, nr) __wake_up(q, 1) 77219820Sjeff 78219820Sjeff#define wait_event(q, cond) \ 79219820Sjeffdo { \ 80219820Sjeff void *c = &(q).wchan; \ 81219820Sjeff if (!(cond)) { \ 82219820Sjeff for (;;) { \ 83219820Sjeff sleepq_lock(c); \ 84219820Sjeff if (cond) { \ 85219820Sjeff sleepq_release(c); \ 86219820Sjeff break; \ 87219820Sjeff } \ 88219820Sjeff sleepq_add(c, NULL, "completion", SLEEPQ_SLEEP, 0); \ 89219820Sjeff sleepq_wait(c, 0); \ 90219820Sjeff } \ 91219820Sjeff } \ 92219820Sjeff} while (0) 93219820Sjeff 94219820Sjeff#define wait_event_interruptible(q, cond) \ 95219820Sjeff({ \ 96219820Sjeff void *c = &(q).wchan; \ 97219820Sjeff int _error; \ 98219820Sjeff \ 99219820Sjeff _error = 0; \ 100219820Sjeff if (!(cond)) { \ 101219820Sjeff for (; _error == 0;) { \ 102219820Sjeff sleepq_lock(c); \ 103219820Sjeff if (cond) { \ 104219820Sjeff sleepq_release(c); \ 105219820Sjeff break; \ 106219820Sjeff } \ 107219820Sjeff sleepq_add(c, NULL, "completion", \ 108219820Sjeff SLEEPQ_SLEEP | SLEEPQ_INTERRUPTIBLE, 0); \ 109219820Sjeff if (sleepq_wait_sig(c, 0)) \ 110219820Sjeff _error = -ERESTARTSYS; \ 111219820Sjeff } \ 112219820Sjeff } \ 113219820Sjeff -_error; \ 114219820Sjeff}) 115219820Sjeff 116289564Shselaskystatic inline int 117289564Shselaskywaitqueue_active(wait_queue_head_t *q) 118289564Shselasky{ 119289564Shselasky return 0; /* XXX: not really implemented */ 120289564Shselasky} 121219820Sjeff 122289564Shselasky#define DEFINE_WAIT(name) \ 123289564Shselasky wait_queue_t name = {} 124289564Shselasky 125289564Shselaskystatic inline void 126289564Shselaskyprepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state) 127289564Shselasky{ 128289564Shselasky} 129289564Shselasky 130289564Shselaskystatic inline void 131289564Shselaskyfinish_wait(wait_queue_head_t *q, wait_queue_t *wait) 132289564Shselasky{ 133289564Shselasky} 134289564Shselasky 135219820Sjeff#endif /* _LINUX_WAIT_H_ */ 136