fix a bug for ATOMIC_RMWCAS
[c11tester.git] / mymemory.cc
index 4182e094e5251c1a8efedbe8a92c232c012f13f3..f7b716247e3965d5b2c2f3e255846b60aeda01c5 100644 (file)
@@ -16,6 +16,7 @@
 size_t allocatedReqs[REQUESTS_BEFORE_ALLOC] = { 0 };
 int nextRequest = 0;
 int howManyFreed = 0;
+int switch_alloc = 0;
 #if !USE_MPROTECT_SNAPSHOT
 static mspace sStaticSpace = NULL;
 #endif
@@ -179,6 +180,9 @@ static void * user_malloc(size_t size)
 void *malloc(size_t size)
 {
        if (user_snapshot_space) {
+               if (switch_alloc) {
+                       return model_malloc(size);
+               }
                /* Only perform user allocations from user context */
                ASSERT(!model || thread_current());
                return user_malloc(size);
@@ -189,8 +193,12 @@ void *malloc(size_t size)
 /** @brief Snapshotting free implementation for user programs */
 void free(void * ptr)
 {
-       if (!DontFree(ptr))
+       if (!DontFree(ptr)) {
+               if (switch_alloc) {
+                       return model_free(ptr);
+               }
                mspace_free(user_snapshot_space, ptr);
+       }
 }
 
 /** @brief Snapshotting realloc implementation for user programs */
@@ -251,7 +259,7 @@ void operator delete[](void *p, size_t size)
        free(p);
 }
 
-#else /* !USE_MPROTECT_SNAPSHOT */
+#else  /* !USE_MPROTECT_SNAPSHOT */
 
 /** @brief Snapshotting allocation function for use by the Thread class only */
 void * Thread_malloc(size_t size)
@@ -265,4 +273,4 @@ void Thread_free(void *ptr)
        free(ptr);
 }
 
-#endif /* !USE_MPROTECT_SNAPSHOT */
+#endif /* !USE_MPROTECT_SNAPSHOT */