Index: trunk/src/core/SkPixelRef.cpp |
=================================================================== |
--- trunk/src/core/SkPixelRef.cpp (revision 8632) |
+++ trunk/src/core/SkPixelRef.cpp (working copy) |
@@ -11,25 +11,51 @@ |
SK_DEFINE_INST_COUNT(SkPixelRef) |
-// must be a power-of-2. undef to just use 1 mutex |
-#define PIXELREF_MUTEX_RING_COUNT 32 |
-#ifdef PIXELREF_MUTEX_RING_COUNT |
- static int32_t gPixelRefMutexRingIndex; |
- static SK_DECLARE_MUTEX_ARRAY(gPixelRefMutexRing, PIXELREF_MUTEX_RING_COUNT); |
-#else |
- SK_DECLARE_STATIC_MUTEX(gPixelRefMutex); |
+#ifdef SK_USE_POSIX_THREADS |
+ |
+ static SkBaseMutex gPixelRefMutexRing[] = { |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ { PTHREAD_MUTEX_INITIALIZER }, { PTHREAD_MUTEX_INITIALIZER }, |
+ }; |
+ |
+ // must be a power-of-2. undef to just use 1 mutex |
+ #define PIXELREF_MUTEX_RING_COUNT SK_ARRAY_COUNT(gPixelRefMutexRing) |
+ |
+#else // not pthreads |
+ |
+ // must be a power-of-2. undef to just use 1 mutex |
+ #define PIXELREF_MUTEX_RING_COUNT 32 |
+ static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT]; |
+ |
#endif |
static SkBaseMutex* get_default_mutex() { |
-#ifdef PIXELREF_MUTEX_RING_COUNT |
+ static int32_t gPixelRefMutexRingIndex; |
+ |
+ SkASSERT(SkIsPow2(PIXELREF_MUTEX_RING_COUNT)); |
+ |
// atomic_inc might be overkill here. It may be fine if once in a while |
// we hit a race-condition and two subsequent calls get the same index... |
int index = sk_atomic_inc(&gPixelRefMutexRingIndex); |
return &gPixelRefMutexRing[index & (PIXELREF_MUTEX_RING_COUNT - 1)]; |
-#else |
- return &gPixelRefMutex; |
-#endif |
} |
/////////////////////////////////////////////////////////////////////////////// |