Skip to content

Commit 7783a9a

Browse files
committed
attempt to fix old mingw gcc issue
1 parent 427f9f2 commit 7783a9a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

driver/others/blas_server_win32.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@
5050

5151
/* This is a thread implementation for Win32 lazy implementation */
5252

53+
#if defined (__GNUC__) && (__GNUC__ < 6)
54+
#define WIN_CAS(dest, exch, comp) __sync_val_compare_and_swap(dest, comp, exch)
55+
#else
56+
#if defined(_WIN64)
57+
#define WIN_CAS(dest, exch, comp) InterlockedCompareExchange64(dest, exch, comp)
58+
#else
59+
#define WIN_CAS(dest, exch, comp) InterlockedCompareExchange(dest, exch, comp)
60+
#endif
61+
5362
/* Thread server common information */
5463
typedef struct{
5564
HANDLE taskSemaphore;
@@ -232,14 +241,14 @@ static DWORD WINAPI blas_thread_server(void *arg){
232241

233242
// grab a queued task and update the list
234243
volatile blas_queue_t* queue_next;
235-
LONG64 prev_value;
244+
INT_PTR prev_value;
236245
do {
237246
queue = (volatile blas_queue_t*)pool.queue;
238247
if (!queue)
239248
break;
240249

241250
queue_next = (volatile blas_queue_t*)queue->next;
242-
prev_value = InterlockedCompareExchange64((PLONG64)&pool.queue, (LONG64)queue_next, (LONG64)queue);
251+
prev_value = WIN_CAS((INT_PTR*)&pool.queue, (INT_PTR)queue_next, (INT_PTR)queue);
243252
} while (prev_value != queue);
244253

245254
if (queue) {

0 commit comments

Comments
 (0)