diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/vis_threading.c	Tue Apr 28 23:06:07 2009 +0000
@@ -0,0 +1,63 @@
+#ifdef WIN32
+#include "windows.h"
+void VIS_EnterCriticalSectionImpl(short * cs)
+{
+	int tmp = (int)cs;
+	__asm
+	{
+		mov	ebx, tmp
+	CriticalLoop:
+		bts	[ebx], 0
+		jnc	End
+	}
+	Sleep(0);
+	__asm
+	{
+		jmp	CriticalLoop
+	}
+	
+End:
+	return;
+}
+
+#else
+
+#include <unistd.h>
+
+volatile /*inline*/ void VIS_EnterCriticalSectionImpl(short * cs)
+{
+	int code;
+VIS_EnterStart:
+	asm(
+	"movw $1, %%ax\n\t"
+	"xchg %%ax, (%1)\n\t"
+	"test %%ax, %%ax\n\t"
+	"jz VIS_EnterEnd\n\t"
+	"movl $1, %0\n\t"
+	"jmp VIS_EnterCont\n"
+"VIS_EnterEnd:\n\t"
+	"movl $0, %0\n"
+"VIS_EnterCont:":
+	"=r"(code):
+	"r"(cs):
+	"%ax");
+	if(!code)
+		return;
+	sleep(0);
+	goto VIS_EnterStart;
+}
+
+volatile /*inline*/ void VIS_LeaveCriticalSectionImpl(short * cs)
+{
+	asm(
+	"movw $0, %%ax\n\t"
+	"mfence\n\t"
+	"xchg %%ax, (%0)"::
+	"r"(cs):
+	"%ax");
+}
+
+#endif
+
+
+