Home | History | Annotate | Download | only in ffsb-6.0-rc2
      1 /*
      2  *   Copyright (c) International Business Machines Corp., 2001-2004
      3  *
      4  *   This program is free software;  you can redistribute it and/or modify
      5  *   it under the terms of the GNU General Public License as published by
      6  *   the Free Software Foundation; either version 2 of the License, or
      7  *   (at your option) any later version.
      8  *
      9  *   This program is distributed in the hope that it will be useful,
     10  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
     11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     12  *   the GNU General Public License for more details.
     13  *
     14  *   You should have received a copy of the GNU General Public License
     15  *   along with this program;  if not, write to the Free Software
     16  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     17  */
     18 #ifndef _RWLOCK_H
     19 #define _RWLOCK_H
     20 
     21 #include <pthread.h>
     22 
     23 /* #define RWDEBUG 1 */
     24 
     25 /* n_readers >= 0 means 0 or more readers */
     26 /* n_readers < 0 means a writer */
     27 struct rwlock {
     28 	pthread_mutex_t plock;
     29 	int n_readers;
     30 	pthread_cond_t pcond;
     31 #ifdef RWDEBUG
     32   int writer_tid;
     33   int n_read_waiting;
     34   int n_write_waiting;
     35 #endif
     36 };
     37 
     38 void init_rwlock(struct rwlock *rw);
     39 
     40 void rw_lock_read(struct rwlock *rw);
     41 void rw_lock_write(struct rwlock *rw);
     42 
     43 void rw_unlock_read(struct rwlock *rw);
     44 void rw_unlock_write(struct rwlock *rw);
     45 
     46 int rw_trylock_read(struct rwlock *rw);
     47 int rw_trylock_write(struct rwlock *rw);
     48 
     49 
     50 
     51 #endif
     52