OSDN Git Service

am beeeb788: am 05fa5fd5: Merge "Simplify merges of the annotation code."
[android-x86/dalvik.git] / vm / AtomicCache.h
index 2342162..42ba6be 100644 (file)
 /*
  * Mutex-free cache for key1+key2=value.
  */
-#ifndef _DALVIK_ATOMICCACHE
-#define _DALVIK_ATOMICCACHE
-
-#ifdef __cplusplus
-extern "C" {
-#endif
+#ifndef DALVIK_ATOMICCACHE_H_
+#define DALVIK_ATOMICCACHE_H_
 
 /*
  * If set to "1", gather some stats on our caching success rate.
@@ -35,12 +31,12 @@ extern "C" {
  *
  * Must be exactly 16 bytes.
  */
-typedef struct AtomicCacheEntry {
+struct AtomicCacheEntry {
     u4          key1;
     u4          key2;
     u4          value;
     volatile u4 version;    /* version and lock flag */
-} AtomicCacheEntry;
+};
 
 /*
  * One cache.
@@ -49,7 +45,7 @@ typedef struct AtomicCacheEntry {
  * struct and "entries" separately, avoiding an indirection.  (We already
  * handle "numEntries" separately in ATOMIC_CACHE_LOOKUP.)
  */
-typedef struct AtomicCache {
+struct AtomicCache {
     AtomicCacheEntry*   entries;        /* array of entries */
     int         numEntries;             /* #of entries, must be power of 2 */
 
@@ -61,7 +57,7 @@ typedef struct AtomicCache {
     int         hits;                   /* found entry in cache */
     int         misses;                 /* entry was for other keys */
     int         fills;                  /* entry was empty */
-} AtomicCache;
+};
 
 /*
  * Do a cache lookup.  We need to be able to read and write entries
@@ -140,8 +136,10 @@ typedef struct AtomicCache {
          * boost.                                                           \
          */                                                                 \
         value = (u4) ATOMIC_CACHE_CALC;                                     \
-        dvmUpdateAtomicCache((u4) (_key1), (u4) (_key2), value, pEntry,     \
-                    firstVersion CACHE_XARG(_cache) );                      \
+        if (value == 0 && ATOMIC_CACHE_NULL_ALLOWED) { \
+            dvmUpdateAtomicCache((u4) (_key1), (u4) (_key2), value, pEntry, \
+                        firstVersion CACHE_XARG(_cache) ); \
+        } \
     }                                                                       \
     value;                                                                  \
 })
@@ -174,8 +172,4 @@ void dvmUpdateAtomicCache(u4 key1, u4 key2, u4 value, AtomicCacheEntry* pEntry,
  */
 void dvmDumpAtomicCacheStats(const AtomicCache* pCache);
 
-#ifdef __cplusplus
-}
-#endif
-
-#endif /*_DALVIK_ATOMICCACHE*/
+#endif  // DALVIK_ATOMICCACHE_H_