RE: How to create kernel semaphore that will timeout?

Bret Indrelee (bindrelee@sbs-cp.com)
Tue, 12 Oct 1999 13:18:24 -0500


Andi Kleen [mailto:ak@muc.de] wrote:
> Matthew.Wilcox@genedata.com (Matthew Wilcox) writes:
> > On Mon, Oct 11, 1999 at 04:00:50PM -0500, Bret Indrelee wrote:
> > > What is the best way to create a kernel semaphore that
> will time out after
> > > so many clock ticks?
[ snip ]
> >
> > Why not just use a timer which unlocks the semaphore after
> a given period?
>
> You can unlock a semaphore which you're holding, but there is no clean
> to cancel a pending semaphore down request, which would be
> required for
> down_trylock_timeout().
>
> Workaround: use a wait queue and schedule_timeout.

One of the things I'm going to try is:

current->timeout = jiffies + timeout * HZ;
if (0 >= down_interruptable(semaphore)) {
if (time_before(jiffies, current_timeout)) {
ret_val = -EINTR;
} else {
ret_val = -EBUSY;
}
} else {
ret_val = 0;
}

Should this work?

-Bret

-------------------------------------------------------------
SBS Technologies, Connectivity Products
... solutions for real-time connectivity

Bret Indrelee, Engineer
SBS Technologies, Inc., Connectivity Products
1284 Corporate Center Drive, St. Paul MN 55121
Direct: (651) 905-4731
Main: (651) 905-4700 Fax: (651) 905-4701
E-mail: bindrelee@sbs-cp.com http://www.sbs.com
-------------------------------------------------------------

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/