wait.h revision 289564
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. 28219820Sjeff */ 29219820Sjeff#ifndef _LINUX_WAIT_H_ 30219820Sjeff#define _LINUX_WAIT_H_ 31219820Sjeff 32219820Sjeff#include <linux/spinlock.h> 33219820Sjeff#include <linux/sched.h> 34219820Sjeff#include <linux/list.h> 35219820Sjeff 36219820Sjeff#include <sys/param.h> 37219820Sjeff#include <sys/systm.h> 38219820Sjeff#include <sys/sleepqueue.h> 39219820Sjeff#include <sys/kernel.h> 40219820Sjeff#include <sys/proc.h> 41219820Sjeff 42289564Shselaskytypedef struct { 43289564Shselasky} wait_queue_t; 44289564Shselasky 45289564Shselaskytypedef struct { 46219820Sjeff unsigned int wchan; 47289564Shselasky} wait_queue_head_t; 48219820Sjeff 49289564Shselasky#define init_waitqueue_head(x) \ 50289564Shselasky do { } while (0) 51219820Sjeff 52219820Sjeffstatic inline void 53289564Shselasky__wake_up(wait_queue_head_t *q, int all) 54219820Sjeff{ 55219820Sjeff int wakeup_swapper; 56219820Sjeff void *c; 57219820Sjeff 58219820Sjeff c = &q->wchan; 59219820Sjeff sleepq_lock(c); 60219820Sjeff if (all) 61219820Sjeff wakeup_swapper = sleepq_broadcast(c, SLEEPQ_SLEEP, 0, 0); 62219820Sjeff else 63219820Sjeff wakeup_swapper = sleepq_signal(c, SLEEPQ_SLEEP, 0, 0); 64219820Sjeff sleepq_release(c); 65219820Sjeff if (wakeup_swapper) 66219820Sjeff kick_proc0(); 67219820Sjeff} 68219820Sjeff 69219820Sjeff#define wake_up(q) __wake_up(q, 0) 70219820Sjeff#define wake_up_nr(q, nr) __wake_up(q, 1) 71219820Sjeff#define wake_up_all(q) __wake_up(q, 1) 72219820Sjeff#define wake_up_interruptible(q) __wake_up(q, 0) 73219820Sjeff#define wake_up_interruptible_nr(q, nr) __wake_up(q, 1) 74219820Sjeff#define wake_up_interruptible_all(q, nr) __wake_up(q, 1) 75219820Sjeff 76219820Sjeff#define wait_event(q, cond) \ 77219820Sjeffdo { \ 78219820Sjeff void *c = &(q).wchan; \ 79219820Sjeff if (!(cond)) { \ 80219820Sjeff for (;;) { \ 81219820Sjeff sleepq_lock(c); \ 82219820Sjeff if (cond) { \ 83219820Sjeff sleepq_release(c); \ 84219820Sjeff break; \ 85219820Sjeff } \ 86219820Sjeff sleepq_add(c, NULL, "completion", SLEEPQ_SLEEP, 0); \ 87219820Sjeff sleepq_wait(c, 0); \ 88219820Sjeff } \ 89219820Sjeff } \ 90219820Sjeff} while (0) 91219820Sjeff 92219820Sjeff#define wait_event_interruptible(q, cond) \ 93219820Sjeff({ \ 94219820Sjeff void *c = &(q).wchan; \ 95219820Sjeff int _error; \ 96219820Sjeff \ 97219820Sjeff _error = 0; \ 98219820Sjeff if (!(cond)) { \ 99219820Sjeff for (; _error == 0;) { \ 100219820Sjeff sleepq_lock(c); \ 101219820Sjeff if (cond) { \ 102219820Sjeff sleepq_release(c); \ 103219820Sjeff break; \ 104219820Sjeff } \ 105219820Sjeff sleepq_add(c, NULL, "completion", \ 106219820Sjeff SLEEPQ_SLEEP | SLEEPQ_INTERRUPTIBLE, 0); \ 107219820Sjeff if (sleepq_wait_sig(c, 0)) \ 108219820Sjeff _error = -ERESTARTSYS; \ 109219820Sjeff } \ 110219820Sjeff } \ 111219820Sjeff -_error; \ 112219820Sjeff}) 113219820Sjeff 114289564Shselaskystatic inline int 115289564Shselaskywaitqueue_active(wait_queue_head_t *q) 116289564Shselasky{ 117289564Shselasky return 0; /* XXX: not really implemented */ 118289564Shselasky} 119219820Sjeff 120289564Shselasky#define DEFINE_WAIT(name) \ 121289564Shselasky wait_queue_t name = {} 122289564Shselasky 123289564Shselaskystatic inline void 124289564Shselaskyprepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state) 125289564Shselasky{ 126289564Shselasky} 127289564Shselasky 128289564Shselaskystatic inline void 129289564Shselaskyfinish_wait(wait_queue_head_t *q, wait_queue_t *wait) 130289564Shselasky{ 131289564Shselasky} 132289564Shselasky 133219820Sjeff#endif /* _LINUX_WAIT_H_ */ 134