view vis_threading.c @ 165:47ab97730865

Fix a couple of issues in networking lib
author Mike Pavone <pavone@retrodev.com>
date Thu, 10 Mar 2011 04:15:37 +0000
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