#ifndef BLIS_PTHREAD_H
#define BLIS_PTHREAD_H
#if defined(BLIS_DISABLE_SYSTEM)
typedef int bli_pthread_t;
typedef int bli_pthread_attr_t;
typedef int bli_pthread_mutex_t;
typedef int bli_pthread_mutexattr_t;
typedef int bli_pthread_cond_t;
typedef int bli_pthread_condattr_t;
typedef int bli_pthread_once_t;
typedef int bli_pthread_barrier_t;
typedef int bli_pthread_barrierattr_t;
#define BLIS_PTHREAD_MUTEX_INITIALIZER 0
#define BLIS_PTHREAD_COND_INITIALIZER 0
#define BLIS_PTHREAD_ONCE_INIT 0
#elif defined(_MSC_VER)
typedef struct
{
HANDLE handle;
void* retval;
} bli_pthread_t;
typedef void bli_pthread_attr_t;
typedef SRWLOCK bli_pthread_mutex_t;
typedef void bli_pthread_mutexattr_t;
typedef CONDITION_VARIABLE bli_pthread_cond_t;
typedef void bli_pthread_condattr_t;
typedef INIT_ONCE bli_pthread_once_t;
typedef struct
{
bli_pthread_mutex_t mutex;
bli_pthread_cond_t cond;
int count;
int tripCount;
} bli_pthread_barrier_t;
typedef void bli_pthread_barrierattr_t;
#define BLIS_PTHREAD_MUTEX_INITIALIZER SRWLOCK_INIT
#define BLIS_PTHREAD_ONCE_INIT INIT_ONCE_STATIC_INIT
#define BLIS_PTHREAD_COND_INITIALIZER CONDITION_VARIABLE_INIT
#else
#include <pthread.h>
typedef pthread_t bli_pthread_t;
typedef pthread_attr_t bli_pthread_attr_t;
typedef pthread_mutex_t bli_pthread_mutex_t;
typedef pthread_mutexattr_t bli_pthread_mutexattr_t;
typedef pthread_cond_t bli_pthread_cond_t;
typedef pthread_condattr_t bli_pthread_condattr_t;
typedef pthread_once_t bli_pthread_once_t;
#if defined(__APPLE__)
typedef void bli_pthread_barrierattr_t;
typedef struct
{
bli_pthread_mutex_t mutex;
bli_pthread_cond_t cond;
int count;
int tripCount;
} bli_pthread_barrier_t;
#else
typedef pthread_barrier_t bli_pthread_barrier_t;
typedef pthread_barrierattr_t bli_pthread_barrierattr_t;
#endif
#define BLIS_PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_INITIALIZER
#define BLIS_PTHREAD_COND_INITIALIZER PTHREAD_COND_INITIALIZER
#define BLIS_PTHREAD_ONCE_INIT PTHREAD_ONCE_INIT
#endif
BLIS_EXPORT_BLIS int bli_pthread_create
(
bli_pthread_t* thread,
const bli_pthread_attr_t* attr,
void* (*start_routine)(void*),
void* arg
);
BLIS_EXPORT_BLIS int bli_pthread_join
(
bli_pthread_t thread,
void** retval
);
BLIS_EXPORT_BLIS int bli_pthread_mutex_init
(
bli_pthread_mutex_t* mutex,
const bli_pthread_mutexattr_t* attr
);
BLIS_EXPORT_BLIS int bli_pthread_mutex_destroy
(
bli_pthread_mutex_t* mutex
);
BLIS_EXPORT_BLIS int bli_pthread_mutex_lock
(
bli_pthread_mutex_t* mutex
);
BLIS_EXPORT_BLIS int bli_pthread_mutex_trylock
(
bli_pthread_mutex_t* mutex
);
BLIS_EXPORT_BLIS int bli_pthread_mutex_unlock
(
bli_pthread_mutex_t* mutex
);
BLIS_EXPORT_BLIS int bli_pthread_cond_init
(
bli_pthread_cond_t* cond,
const bli_pthread_condattr_t* attr
);
BLIS_EXPORT_BLIS int bli_pthread_cond_destroy
(
bli_pthread_cond_t* cond
);
BLIS_EXPORT_BLIS int bli_pthread_cond_wait
(
bli_pthread_cond_t* cond,
bli_pthread_mutex_t* mutex
);
BLIS_EXPORT_BLIS int bli_pthread_cond_broadcast
(
bli_pthread_cond_t* cond
);
BLIS_EXPORT_BLIS void bli_pthread_once
(
bli_pthread_once_t* once,
void (*init)(void)
);
#if 0#endif
BLIS_EXPORT_BLIS int bli_pthread_barrier_init
(
bli_pthread_barrier_t* barrier,
const bli_pthread_barrierattr_t* attr,
unsigned int count
);
BLIS_EXPORT_BLIS int bli_pthread_barrier_destroy
(
bli_pthread_barrier_t* barrier
);
BLIS_EXPORT_BLIS int bli_pthread_barrier_wait
(
bli_pthread_barrier_t* barrier
);
typedef struct
{
int status;
bli_pthread_mutex_t mutex;
} bli_pthread_switch_t;
#define BLIS_PTHREAD_SWITCH_INIT { .status = 0, \
.mutex = BLIS_PTHREAD_MUTEX_INITIALIZER }
int bli_pthread_switch_on
(
bli_pthread_switch_t* sw,
int (*init)(void)
);
int bli_pthread_switch_off
(
bli_pthread_switch_t* sw,
int (*deinit)(void)
);
#endif