* ========== Copyright Header Begin ==========================================
* OpenSPARC T2 Processor File: BL_Mutex.h
* Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
* The above named program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License version 2 as published by the Free Software Foundation.
* The above named program is distributed in the hope that it will be
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public
* License along with this work; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
* ========== Copyright Header End ============================================
BL_CondVar() { pthread_cond_init(&cond
,NULL
); }
~BL_CondVar() { pthread_cond_destroy(&cond
); }
int signal() { return pthread_cond_signal(&cond
); }
int broadcast() { return pthread_cond_broadcast(&cond
); }
BL_CondVar( const BL_CondVar
& m
) {}
BL_Mutex() { pthread_mutex_init(&mutex
,NULL
); }
~BL_Mutex() { pthread_mutex_destroy(&mutex
); }
BL_Mutex( const BL_Mutex
& m
)
// this code guarantees that the mutex is unlock when BL_Mutex is
fprintf(stderr
, "BL_Mutex( const BL_Mutex& m ): mutex at %p is held\n",
int lock() { return pthread_mutex_lock(&mutex
); }
int unlock() { return pthread_mutex_unlock(&mutex
); }
int trylock() { return pthread_mutex_trylock(&mutex
); }
int wait( BL_CondVar
& cv
) { return pthread_cond_wait(&cv
.cond
,&mutex
); }
// BL_RdWrLock is a wrapper around the solaris pthread_rwlock.
// Be carefull when and where you use this as this lock is at
// least 4.5 times more expensive as a mutex. So don't use this
// to saveguard tlb access for example. Actually avoid using it.
BL_RdWrLock() { pthread_rwlock_init(&rw
,NULL
); }
~BL_RdWrLock() { pthread_rwlock_destroy(&rw
); }
int rdlock() { return pthread_rwlock_rdlock(&rw
); }
int rdunlock() { return pthread_rwlock_unlock(&rw
); }
int tryrdlock() { return pthread_rwlock_tryrdlock(&rw
); }
int wrlock() { return pthread_rwlock_wrlock(&rw
); }
int wrunlock() { return pthread_rwlock_unlock(&rw
); }
int trywrlock() { return pthread_rwlock_trywrlock(&rw
); }
BL_RdWrLock( const BL_RdWrLock
& ) {}