1276541Sdes/* arc4_lock.c - global lock for arc4random 2276541Sdes* 3276541Sdes * Copyright (c) 2014, NLnet Labs. All rights reserved. 4276541Sdes * 5276541Sdes * This software is open source. 6276541Sdes * 7276541Sdes * Redistribution and use in source and binary forms, with or without 8276541Sdes * modification, are permitted provided that the following conditions 9276541Sdes * are met: 10276541Sdes * 11276541Sdes * Redistributions of source code must retain the above copyright notice, 12276541Sdes * this list of conditions and the following disclaimer. 13276541Sdes * 14276541Sdes * Redistributions in binary form must reproduce the above copyright notice, 15276541Sdes * this list of conditions and the following disclaimer in the documentation 16276541Sdes * and/or other materials provided with the distribution. 17276541Sdes * 18276541Sdes * Neither the name of the NLNET LABS nor the names of its contributors may 19276541Sdes * be used to endorse or promote products derived from this software without 20276541Sdes * specific prior written permission. 21276541Sdes * 22276541Sdes * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23276541Sdes * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24276541Sdes * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25276541Sdes * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26276541Sdes * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27276541Sdes * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28276541Sdes * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29276541Sdes * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30276541Sdes * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31276541Sdes * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32276541Sdes * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33276541Sdes */ 34276541Sdes#include "config.h" 35276541Sdes#define LOCKRET(func) func 36276541Sdes#include "util/locks.h" 37276541Sdes 38276541Sdesvoid _ARC4_LOCK(void); 39276541Sdesvoid _ARC4_UNLOCK(void); 40276541Sdes 41276541Sdes#ifdef THREADS_DISABLED 42276541Sdesvoid _ARC4_LOCK(void) 43276541Sdes{ 44276541Sdes} 45276541Sdes 46276541Sdesvoid _ARC4_UNLOCK(void) 47276541Sdes{ 48276541Sdes} 49276541Sdes#else /* !THREADS_DISABLED */ 50276541Sdes 51276541Sdesstatic lock_quick_t arc4lock; 52276541Sdesstatic int arc4lockinit = 0; 53276541Sdes 54276541Sdesvoid _ARC4_LOCK(void) 55276541Sdes{ 56276605Sdes if(!arc4lockinit) { 57276605Sdes arc4lockinit = 1; 58276541Sdes lock_quick_init(&arc4lock); 59276605Sdes } 60276541Sdes lock_quick_lock(&arc4lock); 61276541Sdes} 62276541Sdes 63276541Sdesvoid _ARC4_UNLOCK(void) 64276541Sdes{ 65276541Sdes lock_quick_unlock(&arc4lock); 66276541Sdes} 67276541Sdes#endif /* THREADS_DISABLED */ 68