Don't use atomic ops in hb_cache_t
authorBehdad Esfahbod <behdad@behdad.org>
Sun, 27 May 2012 14:11:13 +0000 (10:11 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Sun, 27 May 2012 14:11:13 +0000 (10:11 -0400)
We don't care about linearizability, so unprotected int read/write
are enough, no need for expensive memory barriers.  It's a cache,
that's all.

src/hb-cache-private.hh

index 7394fbb..a0928a0 100644 (file)
@@ -36,7 +36,7 @@ template <unsigned int key_bits, unsigned int value_bits, unsigned int cache_bit
 struct hb_cache_t
 {
   ASSERT_STATIC (key_bits >= cache_bits);
-  ASSERT_STATIC (key_bits + value_bits - cache_bits < 8 * sizeof (hb_atomic_int_t));
+  ASSERT_STATIC (key_bits + value_bits - cache_bits < 8 * sizeof (unsigned int));
 
   inline void clear (void)
   {
@@ -46,7 +46,7 @@ struct hb_cache_t
   inline bool get (unsigned int key, unsigned int *value)
   {
     unsigned int k = key & ((1<<cache_bits)-1);
-    unsigned int v = hb_atomic_int_get (values[k]);
+    unsigned int v = values[k];
     if ((v >> value_bits) != (key >> cache_bits))
       return false;
   }
@@ -57,12 +57,12 @@ struct hb_cache_t
       return false; /* Overflows */
     unsigned int k = key & ((1<<cache_bits)-1);
     unsigned int v = ((key>>cache_bits)<<value_bits) | value;
-    hb_atomic_int_set (values[k], v);
+    values[k] = v;
     return true;
   }
 
   private:
-  hb_atomic_int_t values[1<<cache_bits];
+  unsigned int values[1<<cache_bits];
 };
 
 typedef hb_cache_t<21, 16, 8> hb_cmap_cache_t;