/****************************************************************************
** File name    :  HTMutex.cpp
** Description  :  define mutex type
** Create date  :  2018.09.01
** Auther by    :  Liuyx
** Version info :  V1.0.01
** Copyright (C) 2002-2018 xi'an huatek, Inc Co., Ltd
** Update record:  
** DATE         AUTHER   DESC 
** -------------------------------------------------------------------------               
** 2018.09.01   Liuyx    first build
****************************************************************************/
#ifndef __HT_MUTEX_H
#define __HT_MUTEX_H

#ifndef _WIN32  //for unix 
    #define mutex              pthread_mutex_t
    #define mutex_create(X)    pthread_mutex_init(&X, NULL)
    #define mutex_close(X)     pthread_mutex_destroy(&X)
    #define mutex_lock(X)      pthread_mutex_lock(&X)
    #define mutex_unlock(X)    pthread_mutex_unlock(&X)
#else           //for winX
    #define mutex              HANDLE
    #define mutex_create(X)    X = CreateMutex(NULL, FALSE, NULL)
    #define mutex_close(X)     CloseHandle(X)
    #define mutex_lock(X)      WaitForSingleObject(X, INFINITE)
    #define mutex_unlock(X)    ReleaseMutex(X)
#endif

// delay tims, millisecond(ms)
#ifndef _WIN32  //for unix
    #define _SLEEP(X)          usleep(X * 1000)
#else           //for winX
    #define _SLEEP(X)          Sleep(X)  //ms
#endif

#ifdef _WIN32  //for unix
#if defined(snprintf)
#define snprintf          _snprintf
#endif
#endif

#endif  // end __HT_MUTEX_H

