view vis_threading.c @ 75:0083b2f7b3c7

Partially working implementation of List. Modified build scripts to allow use of other compilers. Fixed some bugs involving method implementations on different types returning different numbers of outputs. Added Fold to the 'builtins' in the comipler.
author Mike Pavone <pavone@retrodev.com>
date Tue, 06 Jul 2010 07:52:59 -0400
parents 76568becd6d6
children
line wrap: on
line source

#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