Browse Source

add rtt memory management support

geniusgogo 11 years ago
parent
commit
993374d860
1 changed files with 20 additions and 3 deletions
  1. 20 3
      components/external/SQLite-3.8.1/src/mem1.c

+ 20 - 3
components/external/SQLite-3.8.1/src/mem1.c

@@ -75,10 +75,27 @@ static malloc_zone_t* _sqliteZone_;
 #define SQLITE_MALLOCSIZE(x) \
         (_sqliteZone_ ? _sqliteZone_->size(_sqliteZone_,x) : malloc_size(x))
 
+#elif defined(SQLITE_OS_RTT)
+/*
+** Use standard C library malloc and free on non-Apple systems.
+** Also used by rt-thread systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
+*/
+#define SQLITE_MALLOC(x)    rt_malloc(x)
+#define SQLITE_FREE(x)      rt_free(x)
+#define SQLITE_REALLOC(x,y) rt_realloc((x),(y))
+
+#if (!defined(SQLITE_WITHOUT_MSIZE)) \
+      && (defined(HAVE_MALLOC_H) && defined(HAVE_MALLOC_USABLE_SIZE))
+#   error "not have malloc_usable_size()"
+#endif
+#ifdef HAVE_MALLOC_USABLE_SIZE
+# undef SQLITE_MALLOCSIZE
+#endif
+
 #else /* if not __APPLE__ */
 
 /*
-** Use standard C library malloc and free on non-Apple systems.  
+** Use standard C library malloc and free on non-Apple systems.
 ** Also used by Apple systems if SQLITE_WITHOUT_ZONEMALLOC is defined.
 */
 #define SQLITE_MALLOC(x)    malloc(x)
@@ -229,13 +246,13 @@ static int sqlite3MemInit(void *NotUsed){
     /* defer MT decisions to system malloc */
     _sqliteZone_ = malloc_default_zone();
   }else{
-    /* only 1 core, use our own zone to contention over global locks, 
+    /* only 1 core, use our own zone to contention over global locks,
     ** e.g. we have our own dedicated locks */
     bool success;
     malloc_zone_t* newzone = malloc_create_zone(4096, 0);
     malloc_set_zone_name(newzone, "Sqlite_Heap");
     do{
-      success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, 
+      success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone,
                                  (void * volatile *)&_sqliteZone_);
     }while(!_sqliteZone_);
     if( !success ){