Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

semShow vs semInfo; Semaphore status

364 views
Skip to first unread message

John W. Komp

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to

Hi,

I'm need to know the status of a binary semaphore (i.e. full or empty)
but there doesn't seem to be a function to call that returns such a
value. semShow displays it to stdout and semInfo returns everything
except the status.

Is the semaphore structure documented anywhere such that I can just
check the status myself or has anyone written code which can return the
status?

Thanks,

John Komp
Medtronic
Minneapolis


--
****************************************************
This morning I shot six holes in my freezer
I think I've got cabin fever
Somebody sound the alarm
- J. Buffett
****************************************************


Minh...@jpl.nasa.gov

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to
Take a look at target/h/private/semLibP.h for the definition of
structure "semaphore". SEM_ID is a pointer to this structure, which
you have accessed once you created a semaphore. Look at
the structure element "state", which is a union of "count"
and "owner". As you use binary semaphore, the following
test tells you either it's empty of full:

if state.owner != NULL then it's EMPTY, otherwise it's FULL.

= Minh =

Charlie Grames

unread,
Apr 6, 2000, 3:00:00 AM4/6/00
to John W. Komp
John,

If you don't want to muck around in VxWorks semaphore implementation, you can
also perform semTake() with NO_WAIT for the timeout. If semTake() returns
ERROR, the semaphore was empty. If it returns OK, the semaphore was full and is
now empty. Calling semGive() will return it to full.

Admittedly, this approach is most useful in situations where you would want to
take the semaphore, anyway. If you want true status without the overhead of the
semaphore operations, you'll want to muck around in VxWorks semaphore
implementation. Just be forewarned that that implementation could change.
--
Charlie Grames
The Boeing Company
Charles.R.Grames @ boeing.com

John W. Komp

unread,
Apr 7, 2000, 3:00:00 AM4/7/00
to Minh...@jpl.nasa.gov

Thanks Minh, That did the trick. Further investigation shows that the
binary semaphore must use the same code as the mutual exclusion semaphore.
By that I mean the way state.owner operates. When full the state is NULL or
for the exclusion semaphore, available. When empty the state is the task ID
of the task which took the semaphore.

Looks like smart reuse of some code.

Again, thanks for the help,

-John Komp

Minh...@jpl.nasa.gov wrote:

> Take a look at target/h/private/semLibP.h for the definition of
> structure "semaphore". SEM_ID is a pointer to this structure, which
> you have accessed once you created a semaphore. Look at
> the structure element "state", which is a union of "count"
> and "owner". As you use binary semaphore, the following
> test tells you either it's empty of full:
>
> if state.owner != NULL then it's EMPTY, otherwise it's FULL.
>
> = Minh =
>
> On Thu, 06 Apr 2000 10:51:33 -0500, "John W. Komp"

0 new messages