try fix windows compile error: pthread_mutext_t and others
This commit is contained in:
parent
481c6d517b
commit
29a49c653e
1 changed files with 63 additions and 3 deletions
64
ggml.c
64
ggml.c
|
@ -51,10 +51,15 @@ static inline LONG atomic_flag_test_and_set(atomic_flag* ptr) {
|
|||
return InterlockedCompareExchange(ptr, 1, 0);
|
||||
}
|
||||
|
||||
static inline LONG atomic_flag_test_clear(atomic_flag* ptr) {
|
||||
return InterlockedExchange(ptr, 0)
|
||||
static inline LONG atomic_flag_clear(atomic_flag* ptr) {
|
||||
return InterlockedExchange(ptr, 0);
|
||||
}
|
||||
|
||||
typedef CRITICAL_SECTION pthread_mutex_t;
|
||||
typedef CONDITION_VARIABLE pthread_cond_t;
|
||||
typedef void pthread_mutexattr_t;
|
||||
typedef void pthread_condattr_t;
|
||||
|
||||
typedef HANDLE pthread_t;
|
||||
|
||||
typedef DWORD thread_ret_t;
|
||||
|
@ -75,6 +80,61 @@ static int pthread_join(pthread_t thread, void* unused) {
|
|||
return (int) WaitForSingleObject(thread, INFINITE);
|
||||
}
|
||||
|
||||
static int pthread_mutex_init(pthread_mutex_t *mutex, pthread_mutexattr_t *attr) {
|
||||
(void) attr;
|
||||
if (mutex == NULL) return 1;
|
||||
InitializeCriticalSection(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthread_mutex_destroy(pthread_mutex_t *mutex) {
|
||||
if (mutex == NULL) return 1;
|
||||
DeleteCriticalSection(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthread_mutex_lock(pthread_mutex_t *mutex) {
|
||||
if (mutex == NULL) return 1;
|
||||
EnterCriticalSection(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthread_mutex_unlock(pthread_mutex_t *mutex) {
|
||||
if (mutex == NULL) return 1;
|
||||
LeaveCriticalSection(mutex);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *attr) {
|
||||
(void) attr;
|
||||
if (cond == NULL) return 1;
|
||||
InitializeConditionVariable(cond);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthread_cond_destroy(pthread_cond_t *cond) {
|
||||
(void) cond;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) {
|
||||
if (cond == NULL || mutex == NULL) return 1;
|
||||
if (!SleepConditionVariableCS(cond, mutex, INFINITE)) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthread_cond_signal(pthread_cond_t *cond) {
|
||||
if (cond == NULL) return 1;
|
||||
WakeConditionVariable(cond);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int pthread_cond_broadcast(pthread_cond_t *cond) {
|
||||
if (cond == NULL) return 1;
|
||||
WakeAllConditionVariable(cond);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int sched_yield (void) {
|
||||
Sleep (0);
|
||||
return 0;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue