71c64492 |
/*
* $Id$
*
* Copyright (C) 2006 iptelorg GmbH
*
|
ccab6f01 |
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
|
71c64492 |
*
|
ccab6f01 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
71c64492 |
*/
/*
* atomic operations init
*/
/*
* History:
* --------
* 2006-03-08 created by andrei
|
ccab6f01 |
* 2007-05-11 added lock_set support (andrei)
|
71c64492 |
*/
|
1d0661db |
/*!
* \file
* \brief SIP-router core ::
* \ingroup core
* Module: \ref core
*/
|
71c64492 |
|
d307929c |
#include "atomic_ops_init.h"
|
71c64492 |
#include "atomic_ops.h"
|
ccab6f01 |
#if defined ATOMIC_OPS_USE_LOCK || defined ATOMIC_OPS_USE_LOCK_SET || \
defined MEMBAR_USES_LOCK
|
d307929c |
#include "locking.h"
|
f146bed0 |
#endif
|
d307929c |
|
f146bed0 |
#ifdef MEMBAR_USES_LOCK
gen_lock_t* __membar_lock=0; /* init in atomic_ops.c */
#endif
|
ccab6f01 |
#ifdef ATOMIC_OPS_USE_LOCK_SET
gen_lock_set_t* _atomic_lock_set=0;
#elif defined ATOMIC_OPS_USE_LOCK
|
f146bed0 |
gen_lock_t* _atomic_lock=0;
|
71c64492 |
#endif
/* returns 0 on success, -1 on error */
|
d307929c |
int init_atomic_ops()
|
71c64492 |
{
|
f146bed0 |
#ifdef MEMBAR_USES_LOCK
if ((__membar_lock=lock_alloc())==0){
goto error;
}
if (lock_init(__membar_lock)==0){
lock_dealloc(__membar_lock);
__membar_lock=0;
goto error;
}
_membar_lock; /* start with the lock "taken" so that we can safely use
unlock/lock sequences on it later */
#endif
|
ccab6f01 |
#ifdef ATOMIC_OPS_USE_LOCK_SET
if ((_atomic_lock_set=lock_set_alloc(_ATOMIC_LS_SIZE))==0){
goto error;
}
if (lock_set_init(_atomic_lock_set)==0){
lock_set_dealloc(_atomic_lock_set);
_atomic_lock_set=0;
goto error;
}
#elif defined ATOMIC_OPS_USE_LOCK
|
e960e1e6 |
if ((_atomic_lock=lock_alloc())==0){
|
f146bed0 |
goto error;
|
71c64492 |
}
|
e960e1e6 |
if (lock_init(_atomic_lock)==0){
|
f146bed0 |
lock_dealloc(_atomic_lock);
_atomic_lock=0;
goto error;
|
71c64492 |
}
|
ccab6f01 |
#endif /* ATOMIC_OPS_USE_LOCK_SET/ATOMIC_OPS_USE_LOCK */
|
f146bed0 |
return 0;
|
ccab6f01 |
#if defined MEMBAR_USES_LOCK || defined ATOMIC_OPS_USE_LOCK || \
defined ATOMIC_OPS_USE_LOCK_SET
|
f146bed0 |
error:
destroy_atomic_ops();
return -1;
#endif
|
71c64492 |
}
|
d307929c |
void destroy_atomic_ops()
{
|
f146bed0 |
#ifdef MEMBAR_USES_LOCK
if (__membar_lock!=0){
lock_destroy(__membar_lock);
lock_dealloc(__membar_lock);
__membar_lock=0;
}
#endif
|
ccab6f01 |
#ifdef ATOMIC_OPS_USE_LOCK_SET
if (_atomic_lock_set!=0){
lock_set_destroy(_atomic_lock_set);
lock_set_dealloc(_atomic_lock_set);
_atomic_lock_set=0;
}
#elif defined ATOMIC_OPS_USE_LOCK
|
d307929c |
if (_atomic_lock!=0){
lock_destroy(_atomic_lock);
lock_dealloc(_atomic_lock);
_atomic_lock=0;
}
|
ccab6f01 |
#endif /* ATOMIC_OPS_USE_LOCK_SET / ATOMIC_OPS_USE_LOCK*/
|
d307929c |
}
|