/*     
 * $RCSfile: xk_semaphore.h,v $
 *
 * x-kernel v3.3
 *
 * Copyright (c) 1993,1991,1990,1996  Arizona Board of Regents
 *
 * $Log: xk_semaphore.h,v $
 * Revision 1.1  1997/03/11  20:47:08  dorgival
 * Initial revision
 *
 * Revision 1.1  1997/03/11 20:47:08  dorgival
 * Initial revision
 *
 *
 */

#ifndef __semaphore_h__
#define __semaphore_h__

#include "/usr/include/pthread.h"

typedef struct {
    void*               sem_signature;
    int			count;
    void*               mutex_signature;
    pthread_mutex_t     mutex;
    void*               cond_signature;
    pthread_cond_t      cond;
} Semaphore;

extern void	semInit (Semaphore* s, unsigned initialVal);
extern void	semWait (Semaphore* s);

/*
 * semSignal does not constitute a scheduling point.  Calling thread
 * is guaranteed to resume execution immediately.
 */
extern void	semSignal (Semaphore* s);
/*
 * Let n=semaphoreCount(s).  Then n>=0 => can perform n semaphoreWait() before
 * blocking, or if n<0 => there are -n threads blocked on semaphore.
 */
extern int	semCount (Semaphore* s);
/*
 * semaphoreSignalAll is identical to:
 *	for (i = 0; i < -semaphoreCount(s); ++i) semaphoreSignal(s);
 */
extern void	semSignalAll (Semaphore* s);

#endif /* __semaphore_h__ */
