/************************************************************************/
/* Copyright 2002 MBARI													*/
/************************************************************************/
/* Summary	: Definitions for Semaphore library for OASIS3				*/
/* Filename : sem.h														*/
/* Author	: Robert Herlien (rah)										*/
/* Project	: OASIS Mooring Replacement (OASIS3)						*/
/* Revision: 0.1														*/
/* Created	: 10/14/2002												*/
/*																			*/
/* MBARI provides this documentation and code "as is", with no warranty,	*/
/* express or implied, of its quality or consistency. It is provided without*/
/* support and without obligation on the part of the Monterey Bay Aquarium	*/
/* Research Institute to assist in its use, correction, modification, or	*/
/* enhancement. This information should not be published or distributed to	*/
/* third parties without specific written permission from MBARI.			*/
/*																			*/
/************************************************************************/
/* Modification History:												*/
/* 10oct2002 rah - created from OASIS sem.h								*/
/************************************************************************/

#ifndef INCsemLibh
#define INCsemLibh		1

#include <list.h>

#define SEM_NAMELEN		16

typedef enum							/************************************/
{										/* Type of Semaphore				*/
  MUTEX,								/* Mutual exclusion (return at exit)*/
  COUNTING								/* Counting							*/
} SemType;								/************************************/
	
typedef struct							/************************************/
{										/* Semaphore STRUCTURE				*/
  Node			sem_link;				/* For global list of semaphores	*/
  LstHead		sem_list;				/* Linked list of waiting tasks		*/
  SemType		sem_type;				/* Type of semaphore				*/
  Void			*sem_owner;				/* Task that owns MUTEX semaphore	*/
  Int16			sem_cnt;				/* Semaphore count					*/
  char			sem_name[SEM_NAMELEN];	/* Name (for display only			*/
} Semaphore;							/************************************/

typedef Semaphore		*SemID;			/* Semaphore ID						*/
#define NULLSEM			((SemID)0)
#define NODEtoSEM(np)	((SemID)np)
#define SEMtoNODE(sem)	((Node *)sem)


/****************************************/
/* Function Declarations				*/
/****************************************/

Void	sem_init(SemID sem, SemType semtype, Int16 count);
Void	sem_name(SemID sem, char *name);
Void	sem_take(Reg SemID sem);
Void	sem_give(Reg SemID sem);
Void	semLibInit(Void);
Void	semTaskExit(Void *taskPtr);
#ifdef DEBUG_SYSTEM_CMD
LstHead *semGetSemList(Void);
#endif
Void	printSemOwner(char *s);

#endif	/* INCtaskLibh */
