00001
00019 module mango.sys.Atomic;
00020
00021
00022 version = ASM;
00023
00024 struct Atomic
00025 {
00026
00034 static bool compareAndSet32(void* vptr, void* expect, void* update) {
00035 return compareAndSet32(vptr,cast(int)expect,cast(int)update);
00036 }
00037
00038 version (ASM) {
00039
00040 static bool compareAndSet32(void* vptr, int expect, int update) {
00041 asm {
00042 mov EBX,update;
00043 mov EAX,expect;
00044 mov ECX,vptr;
00045 lock;
00046 cmpxchg [ECX],EBX;
00047 setz AL;
00048 }
00049 }
00050 }
00051 else
00052 {
00053 static bool compareAndSet32(void* vptr, int expect, int update) {
00054 int* vi = cast(int*)vptr;
00055 bool res = false;
00056 synchronized {
00057 res = expect == *vi;
00058 if (res) {
00059 *vi = update;
00060 }
00061 }
00062 return res;
00063 }
00064 }
00065 }