2018-10-09 05:01:05 +00:00
|
|
|
/*
|
|
|
|
* MARS Long Distance Replication Software
|
|
|
|
*
|
|
|
|
* This file is part of MARS project: http://schoebel.github.io/mars/
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2014 Thomas Schoebel-Theuer
|
|
|
|
* Copyright (C) 2011-2014 1&1 Internet AG
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef BRICK_WAIT_H
|
|
|
|
#define BRICK_WAIT_H
|
|
|
|
|
2022-08-23 14:00:51 +00:00
|
|
|
/* New smp operations for brick waiting.
|
|
|
|
*/
|
|
|
|
#define brick_wait_smp(wq, condition, timeout) \
|
|
|
|
({ \
|
|
|
|
long __tmout = (timeout); \
|
|
|
|
\
|
|
|
|
might_sleep(); \
|
|
|
|
smp_rmb(); \
|
|
|
|
\
|
|
|
|
while (!(condition)) { \
|
|
|
|
__tmout = wait_event_interruptible_timeout( \
|
|
|
|
wq, \
|
|
|
|
({ \
|
|
|
|
smp_rmb(); \
|
|
|
|
(condition); \
|
|
|
|
}), \
|
|
|
|
__tmout); \
|
|
|
|
if (__tmout <= 1) \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
__tmout; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define brick_wake_smp(wq) \
|
|
|
|
({ \
|
|
|
|
smp_wmb(); \
|
|
|
|
wake_up_interruptible_all(wq); \
|
|
|
|
})
|
|
|
|
|
|
|
|
|
2022-08-23 13:48:08 +00:00
|
|
|
/* Historic adaptor.
|
|
|
|
* To disappear somewhen.
|
2018-10-09 05:01:05 +00:00
|
|
|
*/
|
2022-08-23 13:48:08 +00:00
|
|
|
#define brick_wait_flagged(wq, flag, condition, timeout) \
|
2018-10-09 05:01:05 +00:00
|
|
|
({ \
|
2020-02-20 08:42:54 +00:00
|
|
|
long __tmout = (timeout); \
|
2020-01-29 08:42:43 +00:00
|
|
|
int __old_flag; \
|
2018-10-09 05:01:05 +00:00
|
|
|
\
|
|
|
|
might_sleep(); \
|
2020-01-29 08:42:43 +00:00
|
|
|
smp_rmb(); \
|
|
|
|
__old_flag = (flag); \
|
|
|
|
\
|
2019-02-11 18:45:47 +00:00
|
|
|
while (!(condition)) { \
|
2020-01-29 08:42:43 +00:00
|
|
|
int __new_flag; \
|
|
|
|
\
|
2019-02-11 18:45:47 +00:00
|
|
|
__tmout = wait_event_interruptible_timeout( \
|
|
|
|
wq, \
|
2020-01-29 08:42:43 +00:00
|
|
|
({ smp_rmb(); \
|
|
|
|
__new_flag = (flag); \
|
|
|
|
__old_flag != __new_flag; }), \
|
2019-02-11 18:45:47 +00:00
|
|
|
__tmout); \
|
|
|
|
if (__tmout <= 1) \
|
2018-10-09 05:01:05 +00:00
|
|
|
break; \
|
2020-01-29 08:42:43 +00:00
|
|
|
__old_flag = __new_flag; \
|
2018-10-09 05:01:05 +00:00
|
|
|
} \
|
2019-02-11 18:45:47 +00:00
|
|
|
__tmout; \
|
|
|
|
})
|
|
|
|
|
2022-08-23 13:48:08 +00:00
|
|
|
#define brick_wake_flagged(wq, flag) \
|
2019-02-11 18:45:47 +00:00
|
|
|
({ \
|
2020-01-29 08:42:43 +00:00
|
|
|
smp_rmb(); \
|
|
|
|
(flag)++; \
|
2019-02-11 18:45:47 +00:00
|
|
|
smp_wmb(); \
|
|
|
|
wake_up_interruptible_all(wq); \
|
2018-10-09 05:01:05 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|