RPA Toolkit
Work on the synchronization functions.
authorMartin Stoilov <martin@rpasearch.com>
Sun, 10 Jul 2011 23:09:52 +0000 (16:09 -0700)
committerMartin Stoilov <martin@rpasearch.com>
Sun, 10 Jul 2011 23:09:52 +0000 (16:09 -0700)
arch/windows/i386/rtypes.h
rlib/build/windows/i386/makefile
rlib/rspinlock.c

index 06dc8d8..af4ec39 100644 (file)
@@ -1,5 +1,6 @@
 #ifndef _RTYPES_H_
 #define _RTYPES_H_
+#include <windows.h>
 
 /* 
  * Architecture dependent types. These types have to be redifined 
@@ -15,7 +16,7 @@ typedef signed long long rint64;
 typedef unsigned long long ruint64;
 typedef unsigned long rsize_t;
 typedef signed long rssize_t;
-typedef unsigned int ratomic_t;
+typedef unsigned long ratomic_t;
 typedef unsigned long rword;
 typedef long rsword;
 
@@ -43,16 +44,16 @@ typedef struct {ruint32 p1; ruint32 p2;} rpair_t;
  * Atomic operations (Architecture Dependent)
  */
 #define R_ATOMIC_CMPXCHG(ptr, oldval, newval, resptr) \
-               do { } while (0)
+               do { InterlockedCompareExchange (ptr, newval, oldval); *resptr = *ptr; } while (0)
 
 #define R_ATOMIC_XCHG(ptr, val) \
-               do { } while (0)
+               do { val = InterlockedExchange (ptr, val); } while (0)
 
 #define R_ATOMIC_ADD(ptr, val) \
-               do { } while (0)
+               do { InterlockedExchangeAdd (ptr, val); } while (0)
 
 #define R_ATOMIC_SUB(ptr, val) \
-               do { } while (0)
+               do { InterlockedExchangeAdd (ptr, -val); } while (0)
 
 
 #define R_DEBUG_BRAKE do { __asm int 3 } while (0)
index 6e71acb..11d46be 100644 (file)
@@ -41,7 +41,7 @@ CPP_FLAGS=/nologo $(INCLUDE_DIRS) /Zp1 /W3 /EHsc /O2 /D "WIN32" /D "NDEBUG" /D "
 !ELSEIF  "$(CFG)" == "debug"
 
 OUTDIR=.\out
-CPP_FLAGS=/nologo $(INCLUDE_DIRS) /Zp1 /Zi /W3 /EHsc  /Od /D "WIN32" /D "_DEBUG" /D "DEBUG" /D "_CONSOLE" /Fo"$(OUTDIR)\\" /FD  /c
+CPP_FLAGS=/nologo $(INCLUDE_DIRS) /Zp1 /Zi /W3 /EHsc  /Od /D "WIN32" /D "_DEBUG" /D "DEBUG" /D "R_DEBUG_MEMALLOC" /D "_CONSOLE" /Fo"$(OUTDIR)\\" /FD  /c
 
 !ENDIF
 
index 23b4754..be45e59 100644 (file)
@@ -27,14 +27,18 @@ void r_spinlock_init(rspinlock_t *lock)
        *lock = 0;
 }
 
+
 void r_spinlock_lock(rspinlock_t *lock)
 {
        while (1)
        {
                if (!r_atomic_exchange(lock, R_SPINLOCK_BUSY))
                        return;
-
-               while (*lock);
+               while (*lock) {
+                       /*
+                        * Spin...
+                        */
+               }
        }
 }