cv_wait

Ian Lepore ian at freebsd.org
Thu Jul 2 19:07:32 UTC 2020


On Fri, 2020-07-03 at 00:36 +0530, Kamal R. Prasad wrote:
> but if i am doing cv_wait() for the first time, should someone be
> calling cv_signal for it to proceed?
> my algo is something like this in my driver:-
> function1()
> {
> mtx_lock(&sc->sc_mtx);
> cv_wait(&sc->sc_cv);
> mtx_unlock(&sc->sc_mtx);
> ....
> critical section
> ....
> cv_signal(&sc->sc_cv);
> }
> 
> function2()
> {
> mtx_lock(&sc->sc_mtx);
> cv_wait(&sc->sc_cv);
> mtx_unlock(&sc->sc_mtx);
> ....
> critical section
> ....
> cv_signal(&sc->sc_cv);
> }
> ---------------------
> i want to protect critical section. The critical section calls a
> common
> piece of code which has some locks. if i put in locks to guard the
> cs, it
> triggers a call to witness().
> 
> Update: i saw an implementation wherein they used a callout to
> periodically
> send a cv_signal(). i could do that but the pt of this implementation
> is
> that cs in either of these functions should not be eecuting at the
> same
> time.
> 
> thanks
> -kamal
> 

A condition variable doesn't work the way you're trying to use it.

What is the complaint from witness?  What type of locks are used in the
common code that causes a complaint?  Are any of these functions
involved called from interrupt handlers (that also imposes restrictions
on what kind of locking you can do)?

-- Ian




More information about the freebsd-arm mailing list