本文整理汇总了C++中cv_timedwait函数的典型用法代码示例。如果您正苦于以下问题:C++ cv_timedwait函数的具体用法?C++ cv_timedwait怎么用?C++ cv_timedwait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cv_timedwait函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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*/
}
开发者ID:andreiw,项目名称:polaris,代码行数:36,代码来源:page_retire.c
示例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);
}
开发者ID:Zak-Adelman,项目名称:zfs,代码行数:31,代码来源:txg.c
示例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);
}
开发者ID:garasubo,项目名称:frankenlibc,代码行数:7,代码来源:rumpuser.c
示例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;
}
开发者ID:ajinkya93,项目名称:netbsd-src,代码行数:33,代码来源:test_mutex2.c
示例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);
}
开发者ID:MarginC,项目名称:kame,代码行数:35,代码来源:kern_sema.c
示例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();
}
开发者ID:apprisi,项目名称:illumos-gate,代码行数:68,代码来源:vsw_switching.c
示例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;
}
开发者ID:bagdxk,项目名称:openafs,代码行数:36,代码来源:osi_sleep.c
示例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 */
}
开发者ID:eyberg,项目名称:rumpkernel-netbsd-src,代码行数:27,代码来源:udf_strat_sequential.c
示例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");
}
}
开发者ID:andreiw,项目名称:polaris,代码行数:33,代码来源:ehci_isoch.c
示例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;
}
开发者ID:FireDrunk,项目名称:spl,代码行数:35,代码来源:splat-condvar.c
示例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);
}
}
开发者ID:ChaosJohn,项目名称:freebsd,代码行数:33,代码来源:trim_map.c
示例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);
}
开发者ID:ryo,项目名称:netbsd-src,代码行数:29,代码来源:npf_worker.c
示例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();
}
开发者ID:libkeiser,项目名称:illumos-nexenta,代码行数:59,代码来源:special.c
示例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)));
}
开发者ID:ryoon,项目名称:netbsd-xhci,代码行数:9,代码来源:usbdi_util.c
示例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"));
}
开发者ID:RajasekharBhumi,项目名称:L4Re,代码行数:11,代码来源:main.c
示例16: usb_detach_wait
void
usb_detach_wait(device_t dv, kcondvar_t *cv, kmutex_t *lock)
{
USBHIST_FUNC(); USBHIST_CALLED(usbdebug);
DPRINTFN(1, "waiting for dv %p", dv, 0, 0, 0);
if (cv_timedwait(cv, lock, hz * 60)) // dv, PZERO, "usbdet", hz * 60
printf("usb_detach_wait: %s didn't detach\n",
device_xname(dv));
DPRINTFN(1, "done", 0, 0, 0, 0);
}
开发者ID:ryo,项目名称:netbsd-src,代码行数:11,代码来源:usbdi_util.c
示例17: txg_thread_wait
static void
txg_thread_wait(tx_state_t *tx, callb_cpr_t *cpr, kcondvar_t *cv, uint64_t time)
{
CALLB_CPR_SAFE_BEGIN(cpr);
if (time)
(void) cv_timedwait(cv, &tx->tx_sync_lock, time);
else
cv_wait(cv, &tx->tx_sync_lock);
CALLB_CPR_SAFE_END(cpr, &tx->tx_sync_lock);
}
开发者ID:AhmadTux,项目名称:freebsd,代码行数:12,代码来源:txg.c
示例18: splat_condvar_test5
static int
splat_condvar_test5(struct file *file, void *arg)
{
kcondvar_t condvar;
kmutex_t mtx;
clock_t time_left, time_before, time_after, time_delta;
uint64_t whole_delta;
uint32_t remain_delta;
int rc = 0;
mutex_init(&mtx, SPLAT_CONDVAR_TEST_NAME, MUTEX_DEFAULT, NULL);
cv_init(&condvar, NULL, CV_DEFAULT, NULL);
splat_vprint(file, SPLAT_CONDVAR_TEST5_NAME, "Thread going to sleep for "
"%d second and expecting to be woken by timeout\n", 1);
/* Allow a 1 second timeout, plenty long to validate correctness. */
time_before = lbolt;
mutex_enter(&mtx);
time_left = cv_timedwait(&condvar, &mtx, lbolt + HZ);
mutex_exit(&mtx);
time_after = lbolt;
time_delta = time_after - time_before; /* XXX - Handle jiffie wrap */
whole_delta = time_delta;
remain_delta = do_div(whole_delta, HZ);
if (time_left == -1) {
if (time_delta >= HZ) {
splat_vprint(file, SPLAT_CONDVAR_TEST5_NAME,
"Thread correctly timed out and was asleep "
"for %d.%d seconds (%d second min)\n",
(int)whole_delta, (int)remain_delta, 1);
} else {
splat_vprint(file, SPLAT_CONDVAR_TEST5_NAME,
"Thread correctly timed out but was only "
"asleep for %d.%d seconds (%d second "
"min)\n", (int)whole_delta,
(int)remain_delta, 1);
rc = -ETIMEDOUT;
}
} else {
splat_vprint(file, SPLAT_CONDVAR_TEST5_NAME,
"Thread exited after only %d.%d seconds, it "
"did not hit the %d second timeout\n",
(int)whole_delta, (int)remain_delta, 1);
rc = -ETIMEDOUT;
}
cv_destroy(&condvar);
mutex_destroy(&mtx);
return rc;
}
开发者ID:FireDrunk,项目名称:spl,代码行数:53,代码来源:splat-condvar.c
示例19: awin_p2wi_wait
static int
awin_p2wi_wait(struct awin_p2wi_softc *sc, int flags)
{
int error = 0, retry;
/* Wait up to 5 seconds for a transfer to complete */
sc->sc_stat = 0;
for (retry = (flags & I2C_F_POLL) ? 100 : 5; retry > 0; retry--) {
if (flags & I2C_F_POLL) {
sc->sc_stat |= P2WI_READ(sc, AWIN_A31_P2WI_STAT_REG);
} else {
error = cv_timedwait(&sc->sc_cv, &sc->sc_lock, hz);
if (error && error != EWOULDBLOCK) {
break;
}
}
if (sc->sc_stat & AWIN_A31_P2WI_STAT_MASK) {
break;
}
if (flags & I2C_F_POLL) {
delay(10000);
}
}
if (retry == 0)
error = EAGAIN;
if (flags & I2C_F_POLL) {
P2WI_WRITE(sc, AWIN_A31_P2WI_STAT_REG,
sc->sc_stat & AWIN_A31_P2WI_STAT_MASK);
}
if (error) {
/* Abort transaction */
device_printf(sc->sc_dev, "transfer timeout, error = %d\n",
error);
P2WI_WRITE(sc, AWIN_A31_P2WI_CTRL_REG,
AWIN_A31_P2WI_CTRL_ABORT_TRANS);
return error;
}
if (sc->sc_stat & AWIN_A31_P2WI_STAT_LOAD_BSY) {
device_printf(sc->sc_dev, "transfer busy\n");
return EBUSY;
}
if (sc->sc_stat & AWIN_A31_P2WI_STAT_TRANS_ERR) {
device_printf(sc->sc_dev, "transfer error, id 0x%02llx\n",
__SHIFTOUT(sc->sc_stat, AWIN_A31_P2WI_STAT_TRANS_ERR_ID));
return EIO;
}
return 0;
}
开发者ID:krytarowski,项目名称:netbsd-current-src-sys,代码行数:52,代码来源:awin_p2wi.c
示例20: cv_timedwait_hires
// Unlike cv_timedwait(), this timeout is relative to now.
clock_t cv_timedwait_hires(
kcondvar_t * cv, kmutex_t * m, hrtime_t timeout, hrtime_t resolution, int flag)
{
VERIFY0(flag); // We don't support flags.
clock_t expiration = ddi_get_lbolt() + timeout;;
if (resolution > 1) {
expiration = (expiration / resolution) * resolution;
}
// clock_t is ticks (usec) and hrtime_t is nsec.
return cv_timedwait(cv, m, USEC_TO_NSEC(expiration));
}
开发者ID:jpeach,项目名称:zfsd,代码行数:14,代码来源:condvar.c
注:本文中的cv_timedwait函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论