• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

lock_alloc.h

00001 /* $Id$ */
00002 /*
00003  *
00004  * Copyright (C) 2001-2003 FhG Fokus
00005  *
00006  * This file is part of ser, a free SIP server.
00007  *
00008  * ser 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  * For a license to use the ser software under conditions
00014  * other than those described here, or to purchase support for this
00015  * software, please contact iptel.org by e-mail at the following addresses:
00016  *    info@iptel.org
00017  *
00018  * ser is distributed in the hope that it will be useful,
00019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  * GNU General Public License for more details.
00022  *
00023  * You should have received a copy of the GNU General Public License 
00024  * along with this program; if not, write to the Free Software 
00025  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00026  */
00027 
00028 /*
00029  *   ser locking library
00030  *   WARNING: don't include this directly include instead locking.h!
00031  * History:
00032  * --------
00033  *  2003-03-06  created by andrei (contains parts of the original locking.h)
00034  *  2003-03-17  fixed cast warning in shm_free (forced to void*) (andrei)
00035  *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
00036  *              on darwin (andrei)
00037  *
00038 Implements: (see also locking.h)
00039 
00040         simple locks:
00041         -------------
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         ----------
00047         gen_lock_set_t* lock_set_alloc(no)               - allocs a lock set in shm.
00048         void lock_set_dealloc(gen_lock_set_t* s);        - deallocs the lock set shm.
00049 
00050 */
00051 
00052 #ifndef _lock_alloc_h
00053 #define _lock_alloc_h
00054 
00055 /*shm_{malloc, free}*/
00056 #include "mem/mem.h"
00057 #ifdef SHM_MEM
00058 #include "mem/shm_mem.h"
00059 #else
00060 #error "locking requires shared memory support"
00061 #endif
00062 
00063 #if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM)
00064 /* simple locks*/
00065 #define lock_alloc() shm_malloc(sizeof(gen_lock_t))
00066 #define lock_dealloc(lock) shm_free((void*)lock)
00067 /* lock sets */
00068 
00069 inline static gen_lock_set_t* lock_set_alloc(int n)
00070 {
00071         gen_lock_set_t* ls;
00072         ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t)+n*sizeof(gen_lock_t));
00073         if (ls==0){
00074                 LOG(L_CRIT, "ERROR: lock_set_alloc (FL): could not allocate lock_set\n");
00075         }else{
00076                 ls->locks=(gen_lock_t*)((char*)ls+sizeof(gen_lock_set_t));
00077                 ls->size=n;
00078         }
00079         return ls;
00080 }
00081 
00082 #define lock_set_dealloc(lock_set) shm_free((void*)lock_set)
00083 
00084 #elif defined USE_SYSV_SEM
00085 
00086 /*simple locks*/
00087 #define lock_alloc() shm_malloc(sizeof(gen_lock_t))
00088 #define lock_dealloc(lock) shm_free((void*)lock)
00089 /* lock sets */
00090 
00091 inline static gen_lock_set_t* lock_set_alloc(int n)
00092 {
00093         gen_lock_set_t* ls;
00094         ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t));
00095         if (ls){
00096                 ls->size=n;
00097                 ls->semid=-1;
00098         };
00099         return ls;
00100 }
00101 
00102 
00103 #define lock_set_dealloc(lock_set) shm_free((void*)lock_set)
00104 
00105 
00106 #else
00107 #error "no locking method selected"
00108 #endif
00109 
00110 
00111 #endif

Generated on Tue May 22 2012 13:10:10 for SIP Router by  doxygen 1.7.1