1*49cdfc7eSAndroid Build Coastguard Worker /* 2*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2015-2016 Cyril Hrubis <[email protected]> 3*49cdfc7eSAndroid Build Coastguard Worker * 4*49cdfc7eSAndroid Build Coastguard Worker * This program is free software: you can redistribute it and/or modify 5*49cdfc7eSAndroid Build Coastguard Worker * it under the terms of the GNU General Public License as published by 6*49cdfc7eSAndroid Build Coastguard Worker * the Free Software Foundation, either version 2 of the License, or 7*49cdfc7eSAndroid Build Coastguard Worker * (at your option) any later version. 8*49cdfc7eSAndroid Build Coastguard Worker * 9*49cdfc7eSAndroid Build Coastguard Worker * This program is distributed in the hope that it will be useful, 10*49cdfc7eSAndroid Build Coastguard Worker * but WITHOUT ANY WARRANTY; without even the implied warranty of 11*49cdfc7eSAndroid Build Coastguard Worker * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12*49cdfc7eSAndroid Build Coastguard Worker * GNU General Public License for more details. 13*49cdfc7eSAndroid Build Coastguard Worker * 14*49cdfc7eSAndroid Build Coastguard Worker * You should have received a copy of the GNU General Public License 15*49cdfc7eSAndroid Build Coastguard Worker * along with this program. If not, see <http://www.gnu.org/licenses/>. 16*49cdfc7eSAndroid Build Coastguard Worker */ 17*49cdfc7eSAndroid Build Coastguard Worker 18*49cdfc7eSAndroid Build Coastguard Worker /* 19*49cdfc7eSAndroid Build Coastguard Worker 20*49cdfc7eSAndroid Build Coastguard Worker Checkpoint - easy to use parent-child synchronization. 21*49cdfc7eSAndroid Build Coastguard Worker 22*49cdfc7eSAndroid Build Coastguard Worker Checkpoint is based on futexes (man futex). The library allocates a page of 23*49cdfc7eSAndroid Build Coastguard Worker shared memory for futexes and the id is an offset to it which gives the user 24*49cdfc7eSAndroid Build Coastguard Worker up to page_size/sizeof(uint32_t) checkpoint pairs. Up to INT_MAX processes 25*49cdfc7eSAndroid Build Coastguard Worker can sleep on single id and can be woken up by single wake. 26*49cdfc7eSAndroid Build Coastguard Worker 27*49cdfc7eSAndroid Build Coastguard Worker */ 28*49cdfc7eSAndroid Build Coastguard Worker 29*49cdfc7eSAndroid Build Coastguard Worker #ifndef OLD_CHECKPOINT__ 30*49cdfc7eSAndroid Build Coastguard Worker #define OLD_CHECKPOINT__ 31*49cdfc7eSAndroid Build Coastguard Worker 32*49cdfc7eSAndroid Build Coastguard Worker #include "test.h" 33*49cdfc7eSAndroid Build Coastguard Worker #include "tst_checkpoint_fn.h" 34*49cdfc7eSAndroid Build Coastguard Worker 35*49cdfc7eSAndroid Build Coastguard Worker /* 36*49cdfc7eSAndroid Build Coastguard Worker * Checkpoint initializaton, must be done first. 37*49cdfc7eSAndroid Build Coastguard Worker * 38*49cdfc7eSAndroid Build Coastguard Worker * NOTE: tst_tmpdir() must be called beforehand. 39*49cdfc7eSAndroid Build Coastguard Worker */ 40*49cdfc7eSAndroid Build Coastguard Worker #define TST_CHECKPOINT_INIT(cleanup_fn) \ 41*49cdfc7eSAndroid Build Coastguard Worker tst_checkpoint_init(__FILE__, __LINE__, cleanup_fn) 42*49cdfc7eSAndroid Build Coastguard Worker 43*49cdfc7eSAndroid Build Coastguard Worker #define TST_SAFE_CHECKPOINT_WAIT(cleanup_fn, id) \ 44*49cdfc7eSAndroid Build Coastguard Worker tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, 0); 45*49cdfc7eSAndroid Build Coastguard Worker 46*49cdfc7eSAndroid Build Coastguard Worker #define TST_SAFE_CHECKPOINT_WAIT2(cleanup_fn, id, msec_timeout) \ 47*49cdfc7eSAndroid Build Coastguard Worker tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, msec_timeout); 48*49cdfc7eSAndroid Build Coastguard Worker 49*49cdfc7eSAndroid Build Coastguard Worker #define TST_SAFE_CHECKPOINT_WAKE(cleanup_fn, id) \ 50*49cdfc7eSAndroid Build Coastguard Worker tst_safe_checkpoint_wake(__FILE__, __LINE__, cleanup_fn, id, 1); 51*49cdfc7eSAndroid Build Coastguard Worker 52*49cdfc7eSAndroid Build Coastguard Worker #define TST_SAFE_CHECKPOINT_WAKE2(cleanup_fn, id, nr_wake) \ 53*49cdfc7eSAndroid Build Coastguard Worker tst_safe_checkpoint_wake(__FILE__, __LINE__, cleanup_fn, id, nr_wake); 54*49cdfc7eSAndroid Build Coastguard Worker 55*49cdfc7eSAndroid Build Coastguard Worker #define TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup_fn, id) \ 56*49cdfc7eSAndroid Build Coastguard Worker tst_safe_checkpoint_wake(__FILE__, __LINE__, cleanup_fn, id, 1); \ 57*49cdfc7eSAndroid Build Coastguard Worker tst_safe_checkpoint_wait(__FILE__, __LINE__, cleanup_fn, id, 0); 58*49cdfc7eSAndroid Build Coastguard Worker 59*49cdfc7eSAndroid Build Coastguard Worker #endif /* OLD_CHECKPOINT__ */ 60