71c64492 |
/*
* $Id$
*
* Copyright (C) 2006 iptelorg GmbH
*
* This file is part of ser, a free SIP server.
*
* ser is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version
*
* For a license to use the ser software under conditions
* other than those described here, or to purchase support for this
* software, please contact iptel.org by e-mail at the following addresses:
* info@iptel.org
*
* ser is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* atomic operations init
*/
/*
* History:
* --------
* 2006-03-08 created by andrei
*/
|
d307929c |
#include "atomic_ops_init.h"
|
71c64492 |
#include "atomic_ops.h"
|
ed21728f |
#if defined ATOMIC_OPS_USE_LOCK || 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
#ifdef ATOMIC_OPS_USE_LOCK
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
|
d307929c |
#ifdef 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 |
}
#endif
|
f146bed0 |
return 0;
#if defined MEMBAR_USES_LOCK || defined ATOMIC_OPS_USE_LOCK
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
|
d307929c |
#ifdef ATOMIC_OPS_USE_LOCK
if (_atomic_lock!=0){
lock_destroy(_atomic_lock);
lock_dealloc(_atomic_lock);
_atomic_lock=0;
}
#endif
}
|