xref: /netbsd-src/lib/libpthread/call_once.c (revision c3c6e74f965ddbaf0ebae62d84e293f2a2822f85)
1*c3c6e74fSkamil /*	$NetBSD: call_once.c,v 1.2 2019/04/24 21:41:15 kamil Exp $	*/
2a9ca1710Skamil 
3a9ca1710Skamil /*-
4a9ca1710Skamil  * Copyright (c) 2016 The NetBSD Foundation, Inc.
5a9ca1710Skamil  * All rights reserved.
6a9ca1710Skamil  *
7a9ca1710Skamil  * This code is derived from software contributed to The NetBSD Foundation
8a9ca1710Skamil  * by Kamil Rytarowski.
9a9ca1710Skamil  *
10a9ca1710Skamil  * Redistribution and use in source and binary forms, with or without
11a9ca1710Skamil  * modification, are permitted provided that the following conditions
12a9ca1710Skamil  * are met:
13a9ca1710Skamil  * 1. Redistributions of source code must retain the above copyright
14a9ca1710Skamil  *    notice, this list of conditions and the following disclaimer.
15a9ca1710Skamil  * 2. Redistributions in binary form must reproduce the above copyright
16a9ca1710Skamil  *    notice, this list of conditions and the following disclaimer in the
17a9ca1710Skamil  *    documentation and/or other materials provided with the distribution.
18a9ca1710Skamil  *
19a9ca1710Skamil  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20a9ca1710Skamil  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21a9ca1710Skamil  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22a9ca1710Skamil  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23a9ca1710Skamil  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24a9ca1710Skamil  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25a9ca1710Skamil  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26a9ca1710Skamil  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27a9ca1710Skamil  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28a9ca1710Skamil  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29a9ca1710Skamil  * POSSIBILITY OF SUCH DAMAGE.
30a9ca1710Skamil  */
31a9ca1710Skamil 
32a9ca1710Skamil #include <sys/cdefs.h>
33*c3c6e74fSkamil __RCSID("$NetBSD: call_once.c,v 1.2 2019/04/24 21:41:15 kamil Exp $");
34a9ca1710Skamil 
35a9ca1710Skamil #include <assert.h>
36a9ca1710Skamil #include <pthread.h>
37a9ca1710Skamil #include <threads.h>
38a9ca1710Skamil 
39a9ca1710Skamil void
call_once(once_flag * flag,void (* func)(void))40a9ca1710Skamil call_once(once_flag *flag, void (*func)(void))
41a9ca1710Skamil {
42a9ca1710Skamil 
43a9ca1710Skamil 	_DIAGASSERT(flag != NULL);
44a9ca1710Skamil 	_DIAGASSERT(func != NULL);
45a9ca1710Skamil 
46*c3c6e74fSkamil 	/*
47*c3c6e74fSkamil 	 * The call_once(3) function that conforms to C11 returns no value.
48*c3c6e74fSkamil 	 */
49*c3c6e74fSkamil 	(void)pthread_once(flag, func);
50a9ca1710Skamil }
51