mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-23 19:04:45 +03:00
libspl: move condvar 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
a9f3733376
commit
e7a856d954
@@ -194,125 +194,6 @@ zone_get_hostid(void *zonep)
|
||||
return (hostid);
|
||||
}
|
||||
|
||||
/*
|
||||
* =========================================================================
|
||||
* condition variables
|
||||
* =========================================================================
|
||||
*/
|
||||
|
||||
void
|
||||
cv_init(kcondvar_t *cv, char *name, int type, void *arg)
|
||||
{
|
||||
(void) name, (void) type, (void) arg;
|
||||
VERIFY0(pthread_cond_init(cv, NULL));
|
||||
}
|
||||
|
||||
void
|
||||
cv_destroy(kcondvar_t *cv)
|
||||
{
|
||||
VERIFY0(pthread_cond_destroy(cv));
|
||||
}
|
||||
|
||||
void
|
||||
cv_wait(kcondvar_t *cv, kmutex_t *mp)
|
||||
{
|
||||
memset(&mp->m_owner, 0, sizeof (pthread_t));
|
||||
VERIFY0(pthread_cond_wait(cv, &mp->m_lock));
|
||||
mp->m_owner = pthread_self();
|
||||
}
|
||||
|
||||
int
|
||||
cv_wait_sig(kcondvar_t *cv, kmutex_t *mp)
|
||||
{
|
||||
cv_wait(cv, mp);
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
cv_timedwait(kcondvar_t *cv, kmutex_t *mp, clock_t abstime)
|
||||
{
|
||||
int error;
|
||||
struct timeval tv;
|
||||
struct timespec ts;
|
||||
clock_t delta;
|
||||
|
||||
delta = abstime - ddi_get_lbolt();
|
||||
if (delta <= 0)
|
||||
return (-1);
|
||||
|
||||
VERIFY0(gettimeofday(&tv, NULL));
|
||||
|
||||
ts.tv_sec = tv.tv_sec + delta / hz;
|
||||
ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC + (delta % hz) * (NANOSEC / hz);
|
||||
if (ts.tv_nsec >= NANOSEC) {
|
||||
ts.tv_sec++;
|
||||
ts.tv_nsec -= NANOSEC;
|
||||
}
|
||||
|
||||
memset(&mp->m_owner, 0, sizeof (pthread_t));
|
||||
error = pthread_cond_timedwait(cv, &mp->m_lock, &ts);
|
||||
mp->m_owner = pthread_self();
|
||||
|
||||
if (error == ETIMEDOUT)
|
||||
return (-1);
|
||||
|
||||
VERIFY0(error);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
int
|
||||
cv_timedwait_hires(kcondvar_t *cv, kmutex_t *mp, hrtime_t tim, hrtime_t res,
|
||||
int flag)
|
||||
{
|
||||
(void) res;
|
||||
int error;
|
||||
struct timeval tv;
|
||||
struct timespec ts;
|
||||
hrtime_t delta;
|
||||
|
||||
ASSERT(flag == 0 || flag == CALLOUT_FLAG_ABSOLUTE);
|
||||
|
||||
delta = tim;
|
||||
if (flag & CALLOUT_FLAG_ABSOLUTE)
|
||||
delta -= gethrtime();
|
||||
|
||||
if (delta <= 0)
|
||||
return (-1);
|
||||
|
||||
VERIFY0(gettimeofday(&tv, NULL));
|
||||
|
||||
ts.tv_sec = tv.tv_sec + delta / NANOSEC;
|
||||
ts.tv_nsec = tv.tv_usec * NSEC_PER_USEC + (delta % NANOSEC);
|
||||
if (ts.tv_nsec >= NANOSEC) {
|
||||
ts.tv_sec++;
|
||||
ts.tv_nsec -= NANOSEC;
|
||||
}
|
||||
|
||||
memset(&mp->m_owner, 0, sizeof (pthread_t));
|
||||
error = pthread_cond_timedwait(cv, &mp->m_lock, &ts);
|
||||
mp->m_owner = pthread_self();
|
||||
|
||||
if (error == ETIMEDOUT)
|
||||
return (-1);
|
||||
|
||||
VERIFY0(error);
|
||||
|
||||
return (1);
|
||||
}
|
||||
|
||||
void
|
||||
cv_signal(kcondvar_t *cv)
|
||||
{
|
||||
VERIFY0(pthread_cond_signal(cv));
|
||||
}
|
||||
|
||||
void
|
||||
cv_broadcast(kcondvar_t *cv)
|
||||
{
|
||||
VERIFY0(pthread_cond_broadcast(cv));
|
||||
}
|
||||
|
||||
/*
|
||||
* =========================================================================
|
||||
* procfs list
|
||||
|
||||
Reference in New Issue
Block a user