lock.h

00001 /*
00002  * $Id$
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  * History:
00029  * --------
00030  *  2003-03-17  converted to locking.h (andrei)
00031  *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
00032  *              on darwin (andrei)
00033  *  2007-03-07  timer locks cleanup: timers are now handled outside tm => no
00034  *              need for timer locks in tm (andrei)
00035  */
00036 
00037 #include "defs.h"
00038 
00039 
00040 #ifndef __lock_h
00041 #define __lock_h
00042 
00043 #include "../../dprint.h"
00044 #include "../../locking.h"
00045 
00046 
00047 
00048 #ifdef GEN_LOCK_T_PREFERED
00049 #define ser_lock_t gen_lock_t
00050 #else
00051 /* typedef to structure we use for mutexing;
00052    currently, index to a semaphore set identifier now */
00053 typedef struct {
00054         gen_lock_set_t* semaphore_set;
00055         int semaphore_index;
00056 } ser_lock_t;
00057 #endif
00058 
00059 
00060 
00061 #include "h_table.h"
00062 
00063 
00064 
00065 int lock_initialize(void);
00066 void lock_cleanup(void);
00067 
00068 #ifdef DBG_LOCK
00069 #define lock(_s) _lock( (_s), __FILE__, __FUNCTION__, __LINE__ )
00070 #define unlock(_s) _unlock( (_s), __FILE__, __FUNCTION__, __LINE__ )
00071 #else
00072 #define lock(_s) _lock( (_s) )
00073 #define unlock(_s) _unlock( (_s) )
00074 #endif
00075 
00076 
00077 int init_cell_lock( struct cell *cell );
00078 int init_entry_lock( struct s_table* ht, struct entry *entry );
00079 
00080 
00081 int release_cell_lock( struct cell *cell );
00082 int release_entry_lock( struct entry *entry );
00083 
00084 
00085 
00086 /* lock semaphore s */
00087 #ifdef DBG_LOCK
00088 static inline void _lock( ser_lock_t* s , char *file, char *function,
00089                                                         unsigned int line )
00090 #else
00091 static inline void _lock( ser_lock_t* s )
00092 #endif
00093 {
00094 #ifdef DBG_LOCK
00095         DBG("DEBUG: lock : entered from %s , %s(%d)\n", function, file, line );
00096 #endif
00097 #ifdef GEN_LOCK_T_PREFERED 
00098         lock_get(s);
00099 #else
00100         lock_set_get(s->semaphore_set, s->semaphore_index);
00101 #endif
00102 }
00103 
00104 
00105 
00106 #ifdef DBG_LOCK
00107 static inline void _unlock( ser_lock_t* s, char *file, char *function,
00108                 unsigned int line )
00109 #else
00110 static inline void _unlock( ser_lock_t* s )
00111 #endif
00112 {
00113 #ifdef DBG_LOCK
00114         DBG("DEBUG: unlock : entered from %s, %s:%d\n", file, function, line );
00115 #endif
00116 #ifdef GEN_LOCK_T_PREFERED
00117         lock_release(s);
00118 #else
00119         lock_set_release( s->semaphore_set, s->semaphore_index );
00120 #endif
00121 }
00122 
00123 
00124 
00125 #endif
00126