/*$cb
 *    This file is a part of OpenMHP VDR plugin.
 *
 *    Copyright (C) 2005 Mikko Novaro <miknov@gmail.com>
 *
 *    See README file for licensing and contact information.
 $ce*/

#ifndef _VDR_OPENMHP_SEMAPHORE_H_
#define _VDR_OPENMHP_SEMAPHORE_H_

#include <sys/types.h>
#include <sys/sem.h>

class cSemaphore {
 private:
  key_t key;
  int id;
  static struct sembuf sembufP;
  static struct sembuf sembufP_nowait;
  static struct sembuf sembufV;
 public:
  cSemaphore(key_t semKey);
  ~cSemaphore(void); // make sure that semaphore is deleted outside any critical section (???)

  /* Enter critical section. Return value indicates, whether section
   * was actually entered. Return value is significant if wait ==
   * false, ie. when operation return immediately regardless the
   * situation. */
  bool Enter(bool wait = true);

  /* Leave critical section */
  void Leave(void);
  int GetValue(void); // for debuging
};

#endif
