[haiku-gsoc] Re: [HCD]: xsi semaphore - kernel side

On 2008-06-21 at 01:06:07 [+0200], Salvatore Benedetto <emitrax@xxxxxxxxx> 
wrote:
> 2008/6/17 Ingo Weinhold <ingo_weinhold@xxxxxx>:
> >
> > Apropos hash tables, I just re-read the sem*() operations and it looks 
> > like
> > you need two hash tables. One mapping key_t -> int (IPC keys to semaphore
> > IDs) and the second one mapping int -> semaphore set object. Private
> > semaphores obviously wouldn't be entered in the first table.
> >
> 
> Yes, and here it the data structure I intend to use.
> 
> * Hash table sIPCTableSem {sIPCTableMsg, sIPCTableShm}
> key_t ipcKey
> int sem_set_id {msg_queue_id, shm_memory_id}
> 
> * Hash table sXSISemaphoreSet
> int semaphore_set_id;
> ipc_perm permission;
> time sem_otime
> time sem_ctime
> int nsems
> lock mutex
> vector<xsi_sem> semaphores
> 
> The above are all information related to the whole set.
> Note: The position in the vector represent the number of the semaphore,
> I don't think it's necessary to add such an information to the below 
> structure
> since a user cannot delete a single semaphore, but only the whole set.

Yep.

> * xsi_sem structure
> short semval
> pid_t sempid
> short semncnt
> short semzcnt
> list<threads> waitingToIncrease
> list<threads> waitingToBeZero
> 
> The above are all information about a single sem.

Looks good so far.

> Variables name will probably be different.

Good. :-)

> BTW: Are hash tables thread safe or do I have to use an explicit lock ?

They need explicit locking.

CU, Ingo

Other related posts: