-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#pragma once | ||
#include <Windows.h> | ||
|
||
typedef volatile LONG atomic_int; | ||
typedef atomic_int atomic_bool; | ||
|
||
static void atomic_store(atomic_int* ptr, LONG val) { | ||
InterlockedExchange(ptr, val); | ||
} | ||
static LONG atomic_load(atomic_int* ptr) { | ||
return InterlockedCompareExchange(ptr, 0, 0); | ||
} | ||
static LONG atomic_fetch_add(atomic_int* ptr, LONG inc) { | ||
return InterlockedExchangeAdd(ptr, inc); | ||
} | ||
static LONG atomic_fetch_sub(atomic_int* ptr, LONG dec) { | ||
return atomic_fetch_add(ptr, -(dec)); | ||
} | ||
|
||
typedef HANDLE pthread_t; | ||
|
||
typedef DWORD thread_ret_t; | ||
static int pthread_create(pthread_t* out, void* unused, thread_ret_t(*func)(void*), void* arg) { | ||
out = CreateThread(NULL, 0, func, arg, 0, NULL); | ||
return out != NULL; | ||
} | ||
|
||
static int pthread_join(pthread_t thread, void* unused) { | ||
return (int) WaitForSingleObject(thread, INFINITE); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters