comparison vis_threading.c @ 0:76568becd6d6

Rhope Alpha 2a source import
author Mike Pavone <pavone@retrodev.com>
date Tue, 28 Apr 2009 23:06:07 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:76568becd6d6
1 #ifdef WIN32
2 #include "windows.h"
3 void VIS_EnterCriticalSectionImpl(short * cs)
4 {
5 int tmp = (int)cs;
6 __asm
7 {
8 mov ebx, tmp
9 CriticalLoop:
10 bts [ebx], 0
11 jnc End
12 }
13 Sleep(0);
14 __asm
15 {
16 jmp CriticalLoop
17 }
18
19 End:
20 return;
21 }
22
23 #else
24
25 #include <unistd.h>
26
27 volatile /*inline*/ void VIS_EnterCriticalSectionImpl(short * cs)
28 {
29 int code;
30 VIS_EnterStart:
31 asm(
32 "movw $1, %%ax\n\t"
33 "xchg %%ax, (%1)\n\t"
34 "test %%ax, %%ax\n\t"
35 "jz VIS_EnterEnd\n\t"
36 "movl $1, %0\n\t"
37 "jmp VIS_EnterCont\n"
38 "VIS_EnterEnd:\n\t"
39 "movl $0, %0\n"
40 "VIS_EnterCont:":
41 "=r"(code):
42 "r"(cs):
43 "%ax");
44 if(!code)
45 return;
46 sleep(0);
47 goto VIS_EnterStart;
48 }
49
50 volatile /*inline*/ void VIS_LeaveCriticalSectionImpl(short * cs)
51 {
52 asm(
53 "movw $0, %%ax\n\t"
54 "mfence\n\t"
55 "xchg %%ax, (%0)"::
56 "r"(cs):
57 "%ax");
58 }
59
60 #endif
61
62
63