00001 /* 00002 * $Id: lock_alloc.h 4790 2008-09-01 11:48:36Z henningw $ 00003 * 00004 * Copyright (C) 2001-2003 FhG Fokus 00005 * 00006 * This file is part of Kamailio, a free SIP server. 00007 * 00008 * Kamailio is free software; you can redistribute it and/or modify 00009 * it under the terms of the GNU General Public License as published by 00010 * the Free Software Foundation; either version 2 of the License, or 00011 * (at your option) any later version 00012 * 00013 * Kamailio is distributed in the hope that it will be useful, 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 * GNU General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU General Public License 00019 * along with this program; if not, write to the Free Software 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00021 * 00022 * History: 00023 * -------- 00024 * 2003-03-06 created by andrei (contains parts of the original locking.h) 00025 * 2003-03-17 fixed cast warning in shm_free (forced to void*) (andrei) 00026 * 2004-07-28 s/lock_set_t/gen_lock_set_t/ because of a type conflict 00027 * on darwin (andrei) 00028 */ 00029 00030 /*! 00031 * \file 00032 * \brief Kamailio locking library 00033 * \note WARNING: don't include this directly, use instead locking.h. 00034 */ 00035 00036 00037 /*! 00038 * \page KamailioLocks Kamailio locking library 00039 * Implements simple locks and lock sets. 00040 * 00041 * simple locks: 00042 * - gen_lock_t* lock_alloc(); - allocates a lock in shared mem. 00043 * - void lock_dealloc(gen_lock_t* lock); - deallocates the lock's shared m. 00044 * 00045 * lock sets: [implemented only for FL & SYSV so far] 00046 * - gen_lock_set_t* lock_set_alloc(no) - allocs a lock set in shm. 00047 * - void lock_set_dealloc(gen_lock_set_t* s); - deallocs the lock set shm. 00048 * 00049 * \see locking.h 00050 */ 00051 00052 #ifndef _lock_alloc_h 00053 #define _lock_alloc_h 00054 00055 /*shm_{malloc, free}*/ 00056 #include "mem/mem.h" 00057 #include "mem/shm_mem.h" 00058 00059 #if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM) 00060 /* simple locks*/ 00061 #define lock_alloc() shm_malloc(sizeof(gen_lock_t)) 00062 #define lock_dealloc(lock) shm_free((void*)lock) 00063 /* lock sets */ 00064 00065 inline static gen_lock_set_t* lock_set_alloc(int n) 00066 { 00067 gen_lock_set_t* ls; 00068 ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t)+n*sizeof(gen_lock_t)); 00069 if (ls==0){ 00070 LM_CRIT("no more shm memory\n"); 00071 }else{ 00072 ls->locks=(gen_lock_t*)((char*)ls+sizeof(gen_lock_set_t)); 00073 ls->size=n; 00074 } 00075 return ls; 00076 } 00077 00078 #define lock_set_dealloc(lock_set) shm_free((void*)lock_set) 00079 00080 #elif defined USE_SYSV_SEM 00081 00082 /*simple locks*/ 00083 #define lock_alloc() shm_malloc(sizeof(gen_lock_t)) 00084 #define lock_dealloc(lock) shm_free((void*)lock) 00085 /* lock sets */ 00086 00087 inline static gen_lock_set_t* lock_set_alloc(int n) 00088 { 00089 gen_lock_set_t* ls; 00090 ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t)); 00091 if (ls){ 00092 ls->size=n; 00093 ls->semid=-1; 00094 }; 00095 return ls; 00096 } 00097 00098 00099 #define lock_set_dealloc(lock_set) shm_free((void*)lock_set) 00100 00101 00102 #else 00103 #error "no locking method selected" 00104 #endif 00105 00106 00107 #endif
1.5.6