]> git.saurik.com Git - apple/network_cmds.git/blame - unbound/compat/arc4_lock.c
network_cmds-543.200.16.tar.gz
[apple/network_cmds.git] / unbound / compat / arc4_lock.c
CommitLineData
89c4ed63
A
1/* arc4_lock.c - global lock for arc4random
2*
3 * Copyright (c) 2014, NLnet Labs. All rights reserved.
4 *
5 * This software is open source.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright notice,
15 * this list of conditions and the following disclaimer in the documentation
16 * and/or other materials provided with the distribution.
17 *
18 * Neither the name of the NLNET LABS nor the names of its contributors may
19 * be used to endorse or promote products derived from this software without
20 * specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
28 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
29 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
30 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34#include "config.h"
35#define LOCKRET(func) func
36#include "util/locks.h"
37
38void _ARC4_LOCK(void);
39void _ARC4_UNLOCK(void);
40
41#ifdef THREADS_DISABLED
42void _ARC4_LOCK(void)
43{
44}
45
46void _ARC4_UNLOCK(void)
47{
48}
49#else /* !THREADS_DISABLED */
50
51static lock_quick_t arc4lock;
52static int arc4lockinit = 0;
53
54void _ARC4_LOCK(void)
55{
56 if(!arc4lockinit) {
57 arc4lockinit = 1;
58 lock_quick_init(&arc4lock);
59 }
60 lock_quick_lock(&arc4lock);
61}
62
63void _ARC4_UNLOCK(void)
64{
65 lock_quick_unlock(&arc4lock);
66}
67#endif /* THREADS_DISABLED */