1*9e5fbd4fSriastradh /* $NetBSD: srcu.h,v 1.4 2021/12/19 11:49:11 riastradh Exp $ */ 26bbc4920Sriastradh 36bbc4920Sriastradh /*- 46bbc4920Sriastradh * Copyright (c) 2018 The NetBSD Foundation, Inc. 56bbc4920Sriastradh * All rights reserved. 66bbc4920Sriastradh * 76bbc4920Sriastradh * This code is derived from software contributed to The NetBSD Foundation 86bbc4920Sriastradh * by Taylor R. Campbell. 96bbc4920Sriastradh * 106bbc4920Sriastradh * Redistribution and use in source and binary forms, with or without 116bbc4920Sriastradh * modification, are permitted provided that the following conditions 126bbc4920Sriastradh * are met: 136bbc4920Sriastradh * 1. Redistributions of source code must retain the above copyright 146bbc4920Sriastradh * notice, this list of conditions and the following disclaimer. 156bbc4920Sriastradh * 2. Redistributions in binary form must reproduce the above copyright 166bbc4920Sriastradh * notice, this list of conditions and the following disclaimer in the 176bbc4920Sriastradh * documentation and/or other materials provided with the distribution. 186bbc4920Sriastradh * 196bbc4920Sriastradh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 206bbc4920Sriastradh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 216bbc4920Sriastradh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 226bbc4920Sriastradh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 236bbc4920Sriastradh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 246bbc4920Sriastradh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 256bbc4920Sriastradh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 266bbc4920Sriastradh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 276bbc4920Sriastradh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 286bbc4920Sriastradh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 296bbc4920Sriastradh * POSSIBILITY OF SUCH DAMAGE. 306bbc4920Sriastradh */ 316bbc4920Sriastradh 326bbc4920Sriastradh #ifndef _LINUX_SRCU_H_ 336bbc4920Sriastradh #define _LINUX_SRCU_H_ 346bbc4920Sriastradh 356bbc4920Sriastradh #include <sys/types.h> 366bbc4920Sriastradh #include <sys/condvar.h> 376bbc4920Sriastradh #include <sys/mutex.h> 386bbc4920Sriastradh 39ce9506a8Sriastradh /* namespace */ 40*9e5fbd4fSriastradh #define _init_srcu_struct linux__init_init_srcu_struct 41*9e5fbd4fSriastradh #define cleanup_srcu_struct linux_cleanup_srcu_struct 42ce9506a8Sriastradh #define srcu_read_lock linux_srcu_read_lock 43ce9506a8Sriastradh #define srcu_read_unlock linux_srcu_read_unlock 44ce9506a8Sriastradh #define synchronize_srcu linux_synchronize_srcu 45*9e5fbd4fSriastradh #define synchronize_srcu_expedited linux_synchronize_srcu_expedited 46ce9506a8Sriastradh 476bbc4920Sriastradh struct lwp; 486bbc4920Sriastradh struct percpu; 496bbc4920Sriastradh 50fb21a037Sriastradh struct srcu_struct { 516bbc4920Sriastradh struct percpu *srcu_percpu; /* struct srcu_cpu */ 526bbc4920Sriastradh kmutex_t srcu_lock; 536bbc4920Sriastradh kcondvar_t srcu_cv; 546bbc4920Sriastradh struct lwp *srcu_sync; 556bbc4920Sriastradh int64_t srcu_total; 566bbc4920Sriastradh volatile unsigned srcu_gen; 576bbc4920Sriastradh }; 586bbc4920Sriastradh 59*9e5fbd4fSriastradh #define init_srcu_struct(S) _init_srcu_struct(S, #S) 60*9e5fbd4fSriastradh 61*9e5fbd4fSriastradh void _init_srcu_struct(struct srcu_struct *, const char *); 62*9e5fbd4fSriastradh void cleanup_srcu_struct(struct srcu_struct *); 636bbc4920Sriastradh 64fb21a037Sriastradh int srcu_read_lock(struct srcu_struct *); 65fb21a037Sriastradh void srcu_read_unlock(struct srcu_struct *, int); 666bbc4920Sriastradh 67fb21a037Sriastradh void synchronize_srcu(struct srcu_struct *); 68*9e5fbd4fSriastradh void synchronize_srcu_expedited(struct srcu_struct *); 696bbc4920Sriastradh 706bbc4920Sriastradh #endif /* _LINUX_SRCU_H_ */ 71