tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

RFC: localcount_hadref() or localcount_trydarin()



Hi,

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.
====================
bool
localcount_hadref(struct localcount *lc, kmutex_t *interlock)
{
        int64_t total = 0;

        KASSERT(mutex_owned(interlock));
        KASSERT(lc->lc_totalp == NULL);

         /* Mark it draining.  */
        lc->lc_totalp = &total;

        mutex_exit(interlock);
        xc_wait(xc_broadcast(0, &localcount_xc, lc, interlock));
        mutex_enter(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)
                return false;
        else
                return true;
}
====================

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.


Thanks,

-- 
//////////////////////////////////////////////////////////////////////
Internet Initiative Japan Inc.

Device Engineering Section,
IoT Platform Development Department,
Network Division,
Technology Unit

Kengo NAKAHARA <k-nakahara%iij.ad.jp@localhost>


Home | Main Index | Thread Index | Old Index