[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
RFC: localcount_hadref() or localcount_trydarin()
I tried using localcount(9) for opencyrpto(9) to avoid detach encryption
drivers. While I implement that, I want to something to use KASSERT which
ensure someone have reference or not.
In addition, localcount_drain() waits forever if someone has had reference.
So, I want to function which returns in not so long time regardless of
someone has reference or not. In other words, I want some function like
mutex_tryenter() for mutex_enter().
My naive implementation of that is here.
localcount_hadref(struct localcount *lc, kmutex_t *interlock)
int64_t total = 0;
KASSERT(lc->lc_totalp == NULL);
/* Mark it draining. */
lc->lc_totalp = &total;
xc_wait(xc_broadcast(0, &localcount_xc, lc, interlock));
/* Paranoia: Cause any further use of lc->lc_totalp to crash. */
lc->lc_totalp = (void *)(uintptr_t)1;
KASSERT(total >= NULL);
if (total == 0)
In the other design, rename the function name to "localcount_trydrain()"
and invert return value true/false.
Could you comment this function? Any comments are welcome.
Internet Initiative Japan Inc.
Device Engineering Section,
IoT Platform Development Department,
Kengo NAKAHARA <k-nakahara%iij.ad.jp@localhost>
Main Index |
Thread Index |