本文整理汇总了C++中cv_timedwait函数的典型用法代码示例。如果您正苦于以下问题:C++ cv_timedwait函数的具体用法?C++ cv_timedwait怎么用?C++ cv_timedwait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cv_timedwait函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: page_retire_thread
/*
* The page_retire_thread loops forever, looking to see if there are
* pages still waiting to be retired.
*/
static void
page_retire_thread(void)
{
callb_cpr_t c;
CALLB_CPR_INIT(&c, &pr_thread_mutex, callb_generic_cpr, "page_retire");
mutex_enter(&pr_thread_mutex);
for (;;) {
if (pr_enable && PR_KSTAT_PENDING) {
/*
* Sigh. It's SO broken how we have to try to shake
* loose the holder of the page. Since we have no
* idea who or what has it locked, we go bang on
* every door in the city to try to locate it.
*/
kmem_reap();
seg_preap();
page_retire_hunt(page_retire_thread_cb);
CALLB_CPR_SAFE_BEGIN(&c);
(void) cv_timedwait(&pr_cv, &pr_thread_mutex,
lbolt + pr_thread_shortwait);
CALLB_CPR_SAFE_END(&c, &pr_thread_mutex);
} else {
CALLB_CPR_SAFE_BEGIN(&c);
(void) cv_timedwait(&pr_cv, &pr_thread_mutex,
lbolt + pr_thread_longwait);
CALLB_CPR_SAFE_END(&c, &pr_thread_mutex);
}
}
/*NOTREACHED*/
}
示例2: txg_delay
/*
* Delay this thread by 'ticks' if we are still in the open transaction
* group and there is already a waiting txg quiesing or quiesced. Abort
* the delay if this txg stalls or enters the quiesing state.
*/
void
txg_delay(dsl_pool_t *dp, uint64_t txg, int ticks)
{
tx_state_t *tx = &dp->dp_tx;
clock_t timeout = ddi_get_lbolt() + ticks;
/* don't delay if this txg could transition to quiesing immediately */
if (tx->tx_open_txg > txg ||
tx->tx_syncing_txg == txg-1 || tx->tx_synced_txg == txg-1)
return;
mutex_enter(&tx->tx_sync_lock);
if (tx->tx_open_txg > txg || tx->tx_synced_txg == txg-1) {
mutex_exit(&tx->tx_sync_lock);
return;
}
while (ddi_get_lbolt() < timeout &&
tx->tx_syncing_txg < txg-1 && !txg_stalled(dp))
(void) cv_timedwait(&tx->tx_quiesce_more_cv, &tx->tx_sync_lock,
timeout);
DMU_TX_STAT_BUMP(dmu_tx_delay);
mutex_exit(&tx->tx_sync_lock);
}
示例3: rumpuser_cv_timedwait
int
rumpuser_cv_timedwait(struct rumpuser_cv *cv, struct rumpuser_mtx *mtx,
int64_t sec, int64_t nsec)
{
return cv_timedwait(cv, mtx, sec, nsec);
}
示例4: testcall
int
testcall(struct lwp *l, void *uap, register_t *retval)
{
int i;
mutex_init(&test_mutex, MUTEX_DEFAULT, IPL_NONE);
cv_init(&test_cv, "testcv");
printf("test: creating threads\n");
test_count = NTHREADS;
test_exit = 0;
for (i = 0; i < test_count; i++)
kthread_create(0, KTHREAD_MPSAFE, NULL, thread1, &primes[i],
&test_threads[i], "thread%d", i);
printf("test: sleeping\n");
mutex_enter(&test_mutex);
while (test_count != 0) {
(void)cv_timedwait(&test_cv, &test_mutex, hz * SECONDS);
test_exit = 1;
}
mutex_exit(&test_mutex);
printf("test: finished\n");
cv_destroy(&test_cv);
mutex_destroy(&test_mutex);
return 0;
}
示例5: _sema_timedwait
int
_sema_timedwait(struct sema *sema, int timo, const char *file, int line)
{
int ret, timed_out;
mtx_lock(&sema->sema_mtx);
/*
* A spurious wakeup will cause the timeout interval to start over.
* This isn't a big deal as long as spurious wakeups don't occur
* continuously, since the timeout period is merely a lower bound on how
* long to wait.
*/
for (timed_out = 0; sema->sema_value == 0 && timed_out == 0;) {
sema->sema_waiters++;
timed_out = cv_timedwait(&sema->sema_cv, &sema->sema_mtx, timo);
sema->sema_waiters--;
}
if (sema->sema_value > 0) {
/* Success. */
sema->sema_value--;
ret = 1;
CTR6(KTR_LOCK, "%s(%p) \"%s\" v = %d at %s:%d", __func__, sema,
cv_wmesg(&sema->sema_cv), sema->sema_value, file, line);
} else {
ret = 0;
CTR5(KTR_LOCK, "%s(%p) \"%s\" fail at %s:%d", __func__, sema,
cv_wmesg(&sema->sema_cv), file, line);
}
mtx_unlock(&sema->sema_mtx);
return (ret);
}
示例6: vsw_setup_switching_thread
/*
* Thread to setup switching mode. This thread is created during vsw_attach()
* initially. It invokes vsw_setup_switching() and keeps retrying while the
* returned value is EAGAIN. The thread exits when the switching mode setup is
* done successfully or when the error returned is not EAGAIN. This thread may
* also get created from vsw_update_md_prop() if the switching mode needs to be
* updated.
*/
void
vsw_setup_switching_thread(void *arg)
{
callb_cpr_t cprinfo;
vsw_t *vswp = (vsw_t *)arg;
clock_t wait_time;
clock_t xwait;
clock_t wait_rv;
int rv;
/* wait time used on successive retries */
xwait = drv_usectohz(vsw_setup_switching_delay * MICROSEC);
CALLB_CPR_INIT(&cprinfo, &vswp->sw_thr_lock, callb_generic_cpr,
"vsw_setup_sw_thread");
mutex_enter(&vswp->sw_thr_lock);
while ((vswp->sw_thr_flags & VSW_SWTHR_STOP) == 0) {
CALLB_CPR_SAFE_BEGIN(&cprinfo);
/* Wait for sometime before (re)trying setup_switching() */
wait_time = ddi_get_lbolt() + xwait;
while ((vswp->sw_thr_flags & VSW_SWTHR_STOP) == 0) {
wait_rv = cv_timedwait(&vswp->sw_thr_cv,
&vswp->sw_thr_lock, wait_time);
if (wait_rv == -1) { /* timed out */
break;
}
}
CALLB_CPR_SAFE_END(&cprinfo, &vswp->sw_thr_lock)
if ((vswp->sw_thr_flags & VSW_SWTHR_STOP) != 0) {
/*
* If there is a stop request, process that first and
* exit the loop. Continue to hold the mutex which gets
* released in CALLB_CPR_EXIT().
*/
break;
}
mutex_exit(&vswp->sw_thr_lock);
rv = vsw_setup_switching(vswp);
if (rv == 0) {
vsw_setup_switching_post_process(vswp);
}
mutex_enter(&vswp->sw_thr_lock);
if (rv != EAGAIN) {
break;
}
}
vswp->sw_thr_flags &= ~VSW_SWTHR_STOP;
vswp->sw_thread = NULL;
CALLB_CPR_EXIT(&cprinfo);
thread_exit();
}
示例7: afs_osi_TimedSleep
/* afs_osi_TimedSleep
*
* Arguments:
* event - event to sleep on
* ams --- max sleep time in milliseconds
* aintok - 1 if should sleep interruptibly
*
* Returns 0 if timeout and EINTR if signalled.
*/
int
afs_osi_TimedSleep(void *event, afs_int32 ams, int aintok)
{
int code = 0;
struct afs_event *evp;
clock_t ticks;
ticks = (ams * afs_hz) / 1000;
#if defined(AFS_SUN510_ENV)
ticks = ticks + ddi_get_lbolt();
#else
ticks = ticks + lbolt;
#endif
evp = afs_getevent(event);
AFS_ASSERT_GLOCK();
if (aintok) {
if (cv_timedwait_sig(&evp->cond, &afs_global_lock, ticks) == 0)
code = EINTR;
} else {
cv_timedwait(&evp->cond, &afs_global_lock, ticks);
}
relevent(evp);
return code;
}
示例8: udf_discstrat_thread
static void
udf_discstrat_thread(void *arg)
{
struct udf_mount *ump = (struct udf_mount *) arg;
struct strat_private *priv = PRIV(ump);
int empty;
empty = 1;
mutex_enter(&priv->discstrat_mutex);
while (priv->run_thread || !empty) {
/* process the current selected queue */
udf_doshedule(ump);
empty = (bufq_peek(priv->queues[UDF_SHED_READING]) == NULL);
empty &= (bufq_peek(priv->queues[UDF_SHED_WRITING]) == NULL);
empty &= (bufq_peek(priv->queues[UDF_SHED_SEQWRITING]) == NULL);
/* wait for more if needed */
if (empty)
cv_timedwait(&priv->discstrat_cv,
&priv->discstrat_mutex, hz/8);
}
mutex_exit(&priv->discstrat_mutex);
wakeup(&priv->run_thread);
kthread_exit(0);
/* not reached */
}
示例9: ehci_wait_for_isoc_completion
/*
* ehci_wait_for_transfers_completion:
*
* Wait for processing all completed transfers and to send results
* to upstream.
*/
static void
ehci_wait_for_isoc_completion(
ehci_state_t *ehcip,
ehci_pipe_private_t *pp)
{
clock_t xfer_cmpl_time_wait;
ASSERT(mutex_owned(&ehcip->ehci_int_mutex));
if (pp->pp_itw_head == NULL) {
return;
}
/* Get the number of clock ticks to wait */
xfer_cmpl_time_wait = drv_usectohz(EHCI_XFER_CMPL_TIMEWAIT * 1000000);
(void) cv_timedwait(&pp->pp_xfer_cmpl_cv,
&ehcip->ehci_int_mutex,
ddi_get_lbolt() + xfer_cmpl_time_wait);
if (pp->pp_itw_head) {
USB_DPRINTF_L2(PRINT_MASK_LISTS, ehcip->ehci_log_hdl,
"ehci_wait_for_isoc_completion: "
"No transfers completion confirmation received");
}
}
示例10: splat_condvar_test34_thread
int
splat_condvar_test34_thread(void *arg)
{
condvar_thr_t *ct = (condvar_thr_t *)arg;
condvar_priv_t *cv = ct->ct_cvp;
clock_t rc;
ASSERT(cv->cv_magic == SPLAT_CONDVAR_TEST_MAGIC);
mutex_enter(&cv->cv_mtx);
splat_vprint(cv->cv_file, ct->ct_name,
"%s thread sleeping with %d waiters\n",
ct->ct_thread->comm, atomic_read(&cv->cv_condvar.cv_waiters));
/* Sleep no longer than 3 seconds, for this test we should
* actually never sleep that long without being woken up. */
rc = cv_timedwait(&cv->cv_condvar, &cv->cv_mtx, lbolt + HZ * 3);
if (rc == -1) {
ct->ct_rc = -ETIMEDOUT;
splat_vprint(cv->cv_file, ct->ct_name, "%s thread timed out, "
"should have been woken\n", ct->ct_thread->comm);
} else {
splat_vprint(cv->cv_file, ct->ct_name,
"%s thread woken %d waiters remain\n",
ct->ct_thread->comm,
atomic_read(&cv->cv_condvar.cv_waiters));
}
mutex_exit(&cv->cv_mtx);
/* wait for main thread reap us */
while (!kthread_should_stop())
schedule();
return 0;
}
示例11: trim_thread
static void
trim_thread(void *arg)
{
spa_t *spa = arg;
zio_t *zio;
#ifdef _KERNEL
(void) snprintf(curthread->td_name, sizeof(curthread->td_name),
"trim %s", spa_name(spa));
#endif
for (;;) {
mutex_enter(&spa->spa_trim_lock);
if (spa->spa_trim_thread == NULL) {
spa->spa_trim_thread = curthread;
cv_signal(&spa->spa_trim_cv);
mutex_exit(&spa->spa_trim_lock);
thread_exit();
}
(void) cv_timedwait(&spa->spa_trim_cv, &spa->spa_trim_lock,
hz * trim_max_interval);
mutex_exit(&spa->spa_trim_lock);
zio = zio_root(spa, NULL, NULL, ZIO_FLAG_CANFAIL);
spa_config_enter(spa, SCL_STATE, FTAG, RW_READER);
trim_map_commit(spa, zio, spa->spa_root_vdev);
(void) zio_wait(zio);
trim_map_commit_done(spa, spa->spa_root_vdev);
spa_config_exit(spa, SCL_STATE, FTAG);
}
}
示例12: npf_worker
static void
npf_worker(void *arg)
{
for (;;) {
const bool finish = (worker_lwp == NULL);
u_int i = NPF_MAX_WORKS;
npf_workfunc_t work;
/* Run the jobs. */
while (i--) {
if ((work = work_funcs[i]) != NULL) {
work();
}
}
/* Exit if requested and all jobs are done. */
if (finish) {
break;
}
/* Sleep and periodically wake up, unless we get notified. */
mutex_enter(&worker_lock);
worker_loop++;
cv_broadcast(&worker_event_cv);
cv_timedwait(&worker_cv, &worker_lock, WORKER_INTERVAL);
mutex_exit(&worker_lock);
}
kthread_exit(0);
}
示例13: spa_perfmon_thread
/* Performance monitor thread */
static void
spa_perfmon_thread(spa_t *spa)
{
spa_perfmon_data_t *data = &spa->spa_perfmon;
boolean_t done = B_FALSE;
ASSERT(data);
DTRACE_PROBE1(spa_pm_start, spa_t *, spa);
/* take a reference against spa */
mutex_enter(&spa_namespace_lock);
spa_open_ref(spa, FTAG);
mutex_exit(&spa_namespace_lock);
/* CONSTCOND */
while (1) {
clock_t deadline = ddi_get_lbolt() +
spa_special_stat_update_ticks;
/* wait for the next tick, check exit condition */
mutex_enter(&data->perfmon_lock);
(void) cv_timedwait(&data->perfmon_cv, &data->perfmon_lock,
deadline);
if (spa->spa_state == POOL_STATE_UNINITIALIZED ||
data->perfmon_thr_exit)
done = B_TRUE;
mutex_exit(&data->perfmon_lock);
if (done)
goto out;
/*
* do the monitoring work here: gather average
* latency and utilization statistics
*/
DTRACE_PROBE1(spa_pm_work, spa_t *, spa);
spa_load_stats_update(spa);
/* we can adjust load and dedup at the same time */
if (spa_enable_data_placement_selection)
spa_special_load_adjust(spa);
if (spa->spa_dedup_best_effort)
spa_special_dedup_adjust(spa);
/* go to sleep until next tick */
DTRACE_PROBE1(spa_pm_sleep, spa_t *, spa);
}
out:
/* release the reference against spa */
mutex_enter(&spa_namespace_lock);
spa_close(spa, FTAG);
mutex_exit(&spa_namespace_lock);
DTRACE_PROBE1(spa_pm_stop, spa_t *, spa);
thread_exit();
}
示例14: usb_detach_wait
void
usb_detach_wait(device_t dv, kcondvar_t *cv, kmutex_t *lock)
{
DPRINTF(("usb_detach_wait: waiting for %s\n", device_xname(dv)));
if (cv_timedwait(cv, lock, hz * 60)) // dv, PZERO, "usbdet", hz * 60
printf("usb_detach_wait: %s didn't detach\n",
device_xname(dv));
DPRINTF(("usb_detach_wait: %s done\n", device_xname(dv)));
}
示例15: cond
static void cond(void *data) {
int res;
printf("%d: entered\n", (int) data);
bsd_dde_prepare_thread("cond");
mtx_lock(&mtx1);
res = cv_timedwait(&cv1, &mtx1, hz/10);
mtx_unlock(&mtx1);
printf("%d: %s\n", (int) data, (res?"timeout":"success"));
}