1 /* arc4_lock.c - global lock for arc4random
3 * Copyright (c) 2014, NLnet Labs. All rights reserved.
5 * This software is open source.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * Redistributions of source code must retain the above copyright notice,
12 * this list of conditions and the following disclaimer.
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.
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.
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.
35 #define LOCKRET(func) func
36 #ifdef ENABLE_LOCK_CHECKS
37 #undef ENABLE_LOCK_CHECKS
39 #include "util/locks.h"
41 void _ARC4_LOCK(void);
42 void _ARC4_UNLOCK(void);
44 #ifdef THREADS_DISABLED
49 void _ARC4_UNLOCK(void)
53 void _ARC4_LOCK_DESTROY(void)
56 #else /* !THREADS_DISABLED */
58 static lock_quick_type arc4lock;
59 static int arc4lockinit = 0;
65 lock_quick_init(&arc4lock);
67 lock_quick_lock(&arc4lock);
70 void _ARC4_UNLOCK(void)
72 lock_quick_unlock(&arc4lock);
75 void _ARC4_LOCK_DESTROY(void)
79 lock_quick_destroy(&arc4lock);
82 #endif /* THREADS_DISABLED */