Re: Semaphore help
On 0, Bernie Ryan <xotron at localnet.com> wrote:
>
>
> jbrown105 at speedymail.org wrote:
> > I have tried to implement the code for semaphores, but it seems
> > not to be working. The main limitation is that fact that one of
> > the paramters of a function (semctl) has a union as its type.
> > How does one create/pass a union as a paramter to a C func?
> > (It would be nice to also have examples of using semaphores, but
> > I have the lpg (linux programmers guide) in addition to the
> > man pages, so if none can be provided, I can manage.)
>
> All a union is is a storage location that can contain different
> size values. To use it all you need to do is know the largest
> value that will fit in the union and this will be the size that
> you will use when allocating the union size.
> Then you can store any value that is listed in the union values.
> in the same storage. The only thing you have to be careful
> to use the correct size for the value when poking it into the storage.
> I hope this makes sense.
>
> Bernie
>
It does. However I am unclear as how to define a C func which
uses a union.
union semun {
int val; /* value for SETVAL */
struct semid_ds *buf; /* buffer for IPC_STAT,
IPC_SET */
unsigned short int *array; /* array for GETALL, SETALL
*/
struct seminfo *__buf; /* buffer for IPC_INFO */
};
int semctl (int semid, int semnum, int cmd, union semun arg);
Thats the C prototype. How do I use define_c_func() to have a union
as a parameter? I got this far:
semctl_ = define_c_func(so, "semctl", {C_INT, C_INT, C_INT, }, C_INT)
How do I finish it?
TIA,
jbrown
--
Please don't use http://fastmail.fm
(I like feeling special.)
|
Not Categorized, Please Help
|
|