Skip to content

Commit

Permalink
renaming zthr funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
sara hartse committed Apr 3, 2019
1 parent db80cf0 commit 737c202
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 35 deletions.
4 changes: 2 additions & 2 deletions include/sys/zthr.h
Expand Up @@ -33,9 +33,9 @@ extern void zthr_destroy(zthr_t *t);
extern void zthr_wakeup(zthr_t *t);
extern void zthr_cancel(zthr_t *t);
extern void zthr_resume(zthr_t *t);
extern void zthr_finish(zthr_t *t);
extern void zthr_wait_cycle_done(zthr_t *t);

extern boolean_t zthr_iscancelled(zthr_t *t);
extern boolean_t zthr_isfinishing(zthr_t *t);
extern boolean_t zthr_has_waiters(zthr_t *t);

#endif /* _SYS_ZTHR_H */
2 changes: 1 addition & 1 deletion module/zfs/dsl_deadlist.c
Expand Up @@ -822,7 +822,7 @@ dsl_livelist_iterate(void *arg, const blkptr_t *bp, boolean_t free,
zthr_t *t = lia->t;
ASSERT(tx == NULL);

if ((t != NULL) && (zthr_isfinishing(t) || zthr_iscancelled(t)))
if ((t != NULL) && (zthr_has_waiters(t) || zthr_iscancelled(t)))
return (EINTR);
if (free) {
livelist_entry_t *node = kmem_alloc(sizeof (livelist_entry_t),
Expand Down
26 changes: 13 additions & 13 deletions module/zfs/dsl_dir.c
Expand Up @@ -2280,22 +2280,22 @@ dsl_dir_remove_livelist(dsl_dir_t *dd, dmu_tx_t *tx, boolean_t total)
if (ll_condense_thread != NULL &&
(to_condense.ds != NULL) && (to_condense.ds->ds_dir == dd)) {
/*
* We use zthr_finish instead of zthr_cancel because we
* don't want to destroy the zthr, just have it skip
* it's current task.
* We use zthr_wait_cycle_done instead of zthr_cancel
* because we don't want to destroy the zthr, just have
* it skip it's current task.
*/
spa->spa_to_condense.cancelled = B_TRUE;
zthr_finish(ll_condense_thread);
zthr_wait_cycle_done(ll_condense_thread);
/*
* If we've returned from zthr_finish without clearing
* the to_condense data structure it's either because
* the no-wait synctask has started (which is indicated
* by 'syncing' field of to_condense) and we can expect
* it to clear to_condense on its own. Otherwise, we
* returned before the zthr ran. The checkfunc will
* now fail as cancelled == B_TRUE so we can safely NULL
* out ds, allowing a different dir's livelist to be
* condensed.
* If we've returned from zthr_wait_cycle_done without
* clearing the to_condense data structure it's either
* because the no-wait synctask has started (which is
* indicated by 'syncing' field of to_condense) and we
* can expect it to clear to_condense on its own.
* Otherwise, we returned before the zthr ran. The
* checkfunc will now fail as cancelled == B_TRUE so we
* can safely NULL out ds, allowing a different dir's
* livelist to be condensed.
*
* We can be sure that the to_condense struct will not
* be repopulated at this stage because both this
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/spa.c
Expand Up @@ -2569,7 +2569,7 @@ void
spa_livelist_condense_cb(void *arg, zthr_t *t)
{
while (zfs_livelist_condense_zthr_pause &&
!(zthr_isfinishing(t) || zthr_iscancelled(t)))
!(zthr_has_waiters(t) || zthr_iscancelled(t)))
delay(1);

int err;
Expand All @@ -2587,7 +2587,7 @@ spa_livelist_condense_cb(void *arg, zthr_t *t)

if (err == 0) {
while (zfs_livelist_condense_sync_pause &&
!(zthr_isfinishing(t) || zthr_iscancelled(t)))
!(zthr_has_waiters(t) || zthr_iscancelled(t)))
delay(1);

dmu_tx_t *tx = dmu_tx_create_dd(spa_get_dsl(spa)->dp_mos_dir);
Expand Down
34 changes: 17 additions & 17 deletions module/zfs/zthr.c
Expand Up @@ -208,8 +208,8 @@ struct zthr {
boolean_t zthr_cancel;

/* flag set to true if we are waiting for the zthr to finish */
boolean_t zthr_finish;
kcondvar_t zthr_finish_cv;
boolean_t zthr_haswaiters;
kcondvar_t zthr_wait_cv;
/*
* maximum amount of time that the zthr is spent sleeping;
* if this is 0, the thread doesn't wake up until it gets
Expand Down Expand Up @@ -246,9 +246,9 @@ zthr_procedure(void *arg)
MSEC2NSEC(1), 0);
}
}
if (t->zthr_finish) {
t->zthr_finish = B_FALSE;
cv_broadcast(&t->zthr_finish_cv);
if (t->zthr_haswaiters) {
t->zthr_haswaiters = B_FALSE;
cv_broadcast(&t->zthr_wait_cv);
}
}

Expand Down Expand Up @@ -283,7 +283,7 @@ zthr_create_timer(zthr_checkfunc_t *checkfunc, zthr_func_t *func,
mutex_init(&t->zthr_state_lock, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&t->zthr_request_lock, NULL, MUTEX_DEFAULT, NULL);
cv_init(&t->zthr_cv, NULL, CV_DEFAULT, NULL);
cv_init(&t->zthr_finish_cv, NULL, CV_DEFAULT, NULL);
cv_init(&t->zthr_wait_cv, NULL, CV_DEFAULT, NULL);

mutex_enter(&t->zthr_state_lock);
t->zthr_checkfunc = checkfunc;
Expand All @@ -307,7 +307,7 @@ zthr_destroy(zthr_t *t)
mutex_destroy(&t->zthr_request_lock);
mutex_destroy(&t->zthr_state_lock);
cv_destroy(&t->zthr_cv);
cv_destroy(&t->zthr_finish_cv);
cv_destroy(&t->zthr_wait_cv);
kmem_free(t, sizeof (*t));
}

Expand Down Expand Up @@ -401,7 +401,7 @@ zthr_resume(zthr_t *t)
ASSERT3P(&t->zthr_checkfunc, !=, NULL);
ASSERT3P(&t->zthr_func, !=, NULL);
ASSERT(!t->zthr_cancel);
ASSERT(!t->zthr_finish);
ASSERT(!t->zthr_haswaiters);

/*
* There are 4 states that we find the zthr in at this point
Expand Down Expand Up @@ -459,12 +459,12 @@ zthr_iscancelled(zthr_t *t)

/*
* Wait for the zthr to finish its current function. Similar to
* zthr_iscancelled, you can use zthr_isfinishing to have the zthr_func end
* zthr_iscancelled, you can use zthr_has_waiters to have the zthr_func end
* early. Unlike zthr_cancel, the thread is not destroyed. If the zthr was
* sleeping or cancelled, return immediately.
*/
void
zthr_finish(zthr_t *t)
zthr_wait_cycle_done(zthr_t *t)
{
mutex_enter(&t->zthr_state_lock);

Expand All @@ -489,15 +489,15 @@ zthr_finish(zthr_t *t)
* zthr_func.
*/
if (t->zthr_thread != NULL) {
t->zthr_finish = B_TRUE;
t->zthr_haswaiters = B_TRUE;

/* broadcast in case the zthr is sleeping */
cv_broadcast(&t->zthr_cv);

while ((t->zthr_finish) && (t->zthr_thread != NULL))
cv_wait(&t->zthr_finish_cv, &t->zthr_state_lock);
while ((t->zthr_haswaiters) && (t->zthr_thread != NULL))
cv_wait(&t->zthr_wait_cv, &t->zthr_state_lock);

ASSERT(!t->zthr_finish);
ASSERT(!t->zthr_haswaiters);
}

mutex_exit(&t->zthr_state_lock);
Expand All @@ -512,7 +512,7 @@ zthr_finish(zthr_t *t)
* returns FALSE otherwise.
*/
boolean_t
zthr_isfinishing(zthr_t *t)
zthr_has_waiters(zthr_t *t)
{
ASSERT3P(t->zthr_thread, ==, curthread);

Expand All @@ -523,7 +523,7 @@ zthr_isfinishing(zthr_t *t)
* zthr_state_lock so that the zthr itself can use this
* to check for the request.
*/
boolean_t finish = t->zthr_finish;
boolean_t has_waiters = t->zthr_haswaiters;
mutex_exit(&t->zthr_state_lock);
return (finish);
return (has_waiters);
}

0 comments on commit 737c202

Please sign in to comment.