/*
 ******************************************************************************
 *  Copyright 1995 DeltaLink bv. All Rights Reserved.
 ******************************************************************************
 *
 * File: serial.h
 *
 * This file contains the serial communication definitions under OS/2
 *
 */

#include <sys/timeb.h>

#ifndef _critical_def
#define _critical_def

#ifdef NT

  #define NOGDI
  typedef void          * THREAD_HANDLE;
  #ifndef SEMA_HANDLE
  typedef void          * SEMA_HANDLE;
  #endif
  typedef unsigned long PRIORITY; 
  #define PD_CRIT_INIT  0x7fffffff
#endif

#ifdef WIN

typedef HANDLE SERIAL_HANDLE;
#endif

#ifdef OS2

typedef HANDLE SERIAL_HANDLE;
#endif

#ifdef UNIX

typedef HANDLE SERIAL_HANDLE;
#endif

#define PD_CRIT_NONE    0
#define PD_CRIT_NORMAL  1
#define PD_CRIT_MEDIUM  2
#define PD_CRIT_HIGH    3

#define CRI_SEMA_COUNT   1            /* increment, for release fo seamphore */
#define CRI_SEMA_TIMEOUT 10000        /* internal time out, waiting for a lock */
#define CRI_SEMA_NAME    "Critical_Semaphore_"

/* error codes */
#define  CRI_GOOD          0
#define  CRI_E_SEMA_CRE   50      /* Error creating semaphore critical section */
#define  CRI_E_SEMA_CLO   51      /* Error closing semaphore */
#define  CRI_E_PRIO_SET   52      /* Error setting priority */
#define  CRI_E_SEMA_TIM   53      /* Error timeout waiting for semaphore crititcal section */
#define  CRI_E_SEMA_UNK   54      /* OS error obtaining semaphore critical section */

                    
typedef struct  _pdcrit {              /* critical strucuture */

  PRIORITY       prio;                 /* original priority of a thread */
  THREAD_HANDLE  thread;               /* thread handle */
  SEMA_HANDLE    semaphore;            /* semaphore handle */
  int            sema;                 /* initial semaphore count */
  char           name[ 80];            /* taskname, used for semaphore name */

} PDCRIT;


/* macros */
#define Critical_Set_Name( c, n)          ( strcpy(((PDCRIT *)c)->name, (char *)n))


/* prototypes of critical functions */
int  pd_init_critical    ( PDCRIT *, int);
int  pd_exit_critical    ( PDCRIT *);

int  pd_enter_critical   ( PDCRIT *, PRIORITY);
int  pd_leave_critical   ( PDCRIT *);
#endif
