RE: Semaphore help
- Posted by Derek Parnell <Derek.Parnell at SYD.RABOBANK.COM> Jun 05, 2002
- 382 views
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C20CEF.D325EBB0 charset=iso-8859-1 > -----Original Message----- > From: jbrown105 at speedymail.org [mailto:jbrown105 at speedymail.org] > Sent: Thursday, 6 June 2002 9:56 > To: EUforum > Subject: 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? > semctl_ = define_c_func(so, "semctl", {C_INT, C_INT, C_INT, C_POINTER}, C_INT) Because the largest item in the union is a pointer. When calling this routine, you just need to decide what you are sending in the last parameter. It is expecting one of ... val address of buf address of array address of __buf depending on what the cmd value is. ----------- Derek. ================================================================== De informatie opgenomen in dit bericht kan vertrouwelijk zijn en is uitsluitend bestemd voor de geadresseerde. Indien u dit bericht onterecht ontvangt wordt u verzocht de inhoud niet te gebruiken en de afzender direct te informeren door het bericht te retourneren. ================================================================== The information contained in this message may be confidential and is intended to be exclusively for the addressee. Should you receive this message unintentionally, please do not use the contents herein and notify the sender immediately by return e-mail. ================================================================== ------_=_NextPart_000_01C20CEF.D325EBB0 Content-Type: application/ms-tnef