rw_lock.h

00001 /* File:      rw_lock.h
00002 ** Author(s): Rui Marques
00003 ** Contact:   xsb-contact@cs.sunysb.edu
00004 ** 
00005 ** Copyright (C) The Research Foundation of SUNY, 1986, 1993-1998
00006 ** Copyright (C) ECRC, Germany, 1990
00007 ** 
00008 ** XSB is free software; you can redistribute it and/or modify it under the
00009 ** terms of the GNU Library General Public License as published by the Free
00010 ** Software Foundation; either version 2 of the License, or (at your option)
00011 ** any later version.
00012 ** 
00013 ** XSB is distributed in the hope that it will be useful, but WITHOUT ANY
00014 ** WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00015 ** FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
00016 ** more details.
00017 ** 
00018 ** You should have received a copy of the GNU Library General Public License
00019 ** along with XSB; if not, write to the Free Software Foundation,
00020 ** Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00021 **
00022 ** $Id: rw_lock.h,v 1.4 2005/12/07 13:23:02 ruim Exp $
00023 ** 
00024 */
00025 
00026 #ifdef MULTI_THREAD_RWL
00027 
00028 #ifdef WIN_NT
00029 #include "pthread.h"
00030 #else /* UNIX */
00031 #include <pthread.h>
00032 #endif
00033 
00034 typedef struct
00035 {
00036         int havelock ;
00037         int writers ;
00038         pthread_mutex_t lock ;
00039         pthread_cond_t waiting ;
00040 }
00041 rw_lock ;
00042 
00043 extern rw_lock trie_rw_lock ;
00044 
00045 void rw_lock_init(rw_lock *l) ;
00046 void rw_lock_read(rw_lock *l) ;
00047 void rw_unlock_read(rw_lock *l) ;
00048 void rw_lock_write(rw_lock *l) ;
00049 void rw_unlock_write(rw_lock *l) ;
00050 
00051 #define TRIE_R_LOCK()                           \
00052 {       if( !th->trie_locked )                  \
00053         {       th->trie_locked = 1 ;           \
00054                 rw_lock_read( &trie_rw_lock ) ; \
00055 }       }
00056 
00057 #define TRIE_R_UNLOCK()                         \
00058 {       if( th->trie_locked )                   \
00059         {       th->trie_locked = 0 ;           \
00060                 rw_unlock_read( &trie_rw_lock );\
00061 }       }
00062 
00063 #define TRIE_W_LOCK()                           \
00064   rw_lock_write(&trie_rw_lock);
00065 #define TRIE_W_UNLOCK()                         \
00066   rw_unlock_write(&trie_rw_lock);
00067 #else
00068 
00069 #define TRIE_R_LOCK()
00070 #define TRIE_R_UNLOCK()
00071 #define TRIE_W_LOCK()
00072 #define TRIE_W_UNLOCK()
00073 
00074 #endif /* MULTI_THREAD_RWL */
00075 

Generated on Wed Jul 26 13:30:42 2006 for XSB by  doxygen 1.4.5