//=========================================================================
// Summary  : */
// Filename : Semaphore.h
// Author   : */
// Project  : */
// Revision : 1
// Created  : 2000/08/19
// Modified : 2000/08/19
//=========================================================================
// Description :
//=========================================================================
#ifndef _AUVSEMAPHORE_H
#define _AUVSEMAPHORE_H

#include <semaphore.h>

/*
CLASS 
Semaphore

DESCRIPTION
auvSemaphore class

AUTHOR
Tom O'Reilly
*/

class auvSemaphore {

public:

  ////////////////////////////////////////////////////////////////////
  // Constructor
  // [input] name: Name of semaphore
  // [input] initialValue: Initial value of semaphore
  auvSemaphore(const char *semName);
  auvSemaphore(const char *name, int initialValue = 1);
  ~auvSemaphore();

  ////////////////////////////////////////////////////////////////////
  // Name of semaphore
  const char *name();

  ////////////////////////////////////////////////////////////////////
  // Post operation. Returns 0 on success, returns -1 and sets errno
  // on error.
  int post();

  ////////////////////////////////////////////////////////////////////
  // Wait operation. Returns 0 on success, returns -1 and sets errno
  // on error.
  int wait();

  ////////////////////////////////////////////////////////////////////
  // Try to wait. Returns 0 on success, returns -1 and sets errno
  // on error.
  int tryWait();

protected:

     int init( const char *semName );

  // Name of shared memory segment
  const char *_name;

  // Pointer to semaphore structure mapped in shared memory
  sem_t *_semaphore;
};

#endif
