#ifndef __OSPSEMH__
#define __OSPSEMH__

#ifdef __cplusplus
extern "C" {
#endif
#include "ospTypes.h"

#include <sched.h>
#include <pthread.h>
#include <semaphore.h>



typedef enum        /*SEM_B_STATE */
{
    SEM_EMPTY,            /* 0: semaphore not available */
    SEM_FULL            /* 1: semaphore available */
} SEM_B_STATE;




#define SEM_TYPE_MUTEX        0x1
#define SEM_TYPE_COUNT        0x2
#define SEM_TYPE_BINARY       0x3

typedef struct tag_lx_sem_t
{
    union
    {
        pthread_mutex_t sem_mutex;
        sem_t sem_count;
    } u;
    
    int32_t sem_type;
} lx_sem_t;


extern OSP_STATUS osp_sem_taketry(void *semId);
extern void *osp_semm_create(void);
extern void *osp_semsm_create(void *semId);
extern void *osp_semb_create(SEM_B_STATE initalState);
extern void *osp_semc_create(int32_t initCount);
extern OSP_STATUS osp_sem_take(void *semId, int32_t timeout);
extern OSP_STATUS osp_sem_give(void *semId);
extern OSP_STATUS osp_sem_delete(void *semId);

extern OSP_STATUS osp_semr_take(void *semId, int32_t timeout);
extern OSP_STATUS osp_sem_wtake(void *semId, int32_t timeout);
extern OSP_STATUS osp_semrw_give(void *semId);
extern void *osp_semss_create(void *sem);

#ifdef __cplusplus
}
#endif

#endif  /* __OSPSEMH__ */

