mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 18:40:43 +03:00
libspl: move mutex implementation from libzpool
Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Rob Norris <robn@despairlabs.com> Closes #17861
This commit is contained in:
committed by
Brian Behlendorf
parent
cc119fbb48
commit
3e37ea85af
@@ -184,62 +184,6 @@ kstat_set_raw_ops(kstat_t *ksp,
|
||||
(void) ksp, (void) headers, (void) data, (void) addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* =========================================================================
|
||||
* mutexes
|
||||
* =========================================================================
|
||||
*/
|
||||
|
||||
void
|
||||
mutex_init(kmutex_t *mp, char *name, int type, void *cookie)
|
||||
{
|
||||
(void) name, (void) type, (void) cookie;
|
||||
VERIFY0(pthread_mutex_init(&mp->m_lock, NULL));
|
||||
memset(&mp->m_owner, 0, sizeof (pthread_t));
|
||||
}
|
||||
|
||||
void
|
||||
mutex_destroy(kmutex_t *mp)
|
||||
{
|
||||
VERIFY0(pthread_mutex_destroy(&mp->m_lock));
|
||||
}
|
||||
|
||||
void
|
||||
mutex_enter(kmutex_t *mp)
|
||||
{
|
||||
VERIFY0(pthread_mutex_lock(&mp->m_lock));
|
||||
mp->m_owner = pthread_self();
|
||||
}
|
||||
|
||||
int
|
||||
mutex_enter_check_return(kmutex_t *mp)
|
||||
{
|
||||
int error = pthread_mutex_lock(&mp->m_lock);
|
||||
if (error == 0)
|
||||
mp->m_owner = pthread_self();
|
||||
return (error);
|
||||
}
|
||||
|
||||
int
|
||||
mutex_tryenter(kmutex_t *mp)
|
||||
{
|
||||
int error = pthread_mutex_trylock(&mp->m_lock);
|
||||
if (error == 0) {
|
||||
mp->m_owner = pthread_self();
|
||||
return (1);
|
||||
} else {
|
||||
VERIFY3S(error, ==, EBUSY);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
mutex_exit(kmutex_t *mp)
|
||||
{
|
||||
memset(&mp->m_owner, 0, sizeof (pthread_t));
|
||||
VERIFY0(pthread_mutex_unlock(&mp->m_lock));
|
||||
}
|
||||
|
||||
/*
|
||||
* =========================================================================
|
||||
* rwlocks
|
||||
|
||||
Reference in New Issue
Block a user