| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkPixelRef.h" | 8 #include "SkPixelRef.h" |
| 9 #include "SkThread.h" | 9 #include "SkThread.h" |
| 10 | 10 |
| 11 #ifdef SK_USE_POSIX_THREADS | 11 #ifdef SK_BUILD_FOR_WIN32 |
| 12 // We don't have SK_BASE_MUTEX_INIT on Windows. |
| 12 | 13 |
| 14 // must be a power-of-2. undef to just use 1 mutex |
| 15 #define PIXELREF_MUTEX_RING_COUNT 32 |
| 16 static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT]; |
| 17 |
| 18 #else |
| 13 static SkBaseMutex gPixelRefMutexRing[] = { | 19 static SkBaseMutex gPixelRefMutexRing[] = { |
| 14 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 20 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 15 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 21 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 16 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 22 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 17 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 23 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 18 | 24 |
| 19 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 25 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 20 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 26 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 21 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 27 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 22 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 28 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 23 | 29 |
| 24 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 30 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 25 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 31 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 26 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 32 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 27 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 33 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 28 | 34 |
| 29 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 35 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 30 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 36 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 31 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 37 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 32 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, | 38 SK_BASE_MUTEX_INIT, SK_BASE_MUTEX_INIT, |
| 33 }; | 39 }; |
| 34 | |
| 35 // must be a power-of-2. undef to just use 1 mutex | 40 // must be a power-of-2. undef to just use 1 mutex |
| 36 #define PIXELREF_MUTEX_RING_COUNT SK_ARRAY_COUNT(gPixelRefMutexRing) | 41 #define PIXELREF_MUTEX_RING_COUNT SK_ARRAY_COUNT(gPixelRefMutexRing) |
| 37 | 42 |
| 38 #else // not pthreads | |
| 39 | |
| 40 // must be a power-of-2. undef to just use 1 mutex | |
| 41 #define PIXELREF_MUTEX_RING_COUNT 32 | |
| 42 static SkBaseMutex gPixelRefMutexRing[PIXELREF_MUTEX_RING_COUNT]; | |
| 43 | |
| 44 #endif | 43 #endif |
| 45 | 44 |
| 46 static SkBaseMutex* get_default_mutex() { | 45 static SkBaseMutex* get_default_mutex() { |
| 47 static int32_t gPixelRefMutexRingIndex; | 46 static int32_t gPixelRefMutexRingIndex; |
| 48 | 47 |
| 49 SkASSERT(SkIsPow2(PIXELREF_MUTEX_RING_COUNT)); | 48 SkASSERT(SkIsPow2(PIXELREF_MUTEX_RING_COUNT)); |
| 50 | 49 |
| 51 // atomic_inc might be overkill here. It may be fine if once in a while | 50 // atomic_inc might be overkill here. It may be fine if once in a while |
| 52 // we hit a race-condition and two subsequent calls get the same index... | 51 // we hit a race-condition and two subsequent calls get the same index... |
| 53 int index = sk_atomic_inc(&gPixelRefMutexRingIndex); | 52 int index = sk_atomic_inc(&gPixelRefMutexRingIndex); |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 | 276 |
| 278 #ifdef SK_BUILD_FOR_ANDROID | 277 #ifdef SK_BUILD_FOR_ANDROID |
| 279 void SkPixelRef::globalRef(void* data) { | 278 void SkPixelRef::globalRef(void* data) { |
| 280 this->ref(); | 279 this->ref(); |
| 281 } | 280 } |
| 282 | 281 |
| 283 void SkPixelRef::globalUnref() { | 282 void SkPixelRef::globalUnref() { |
| 284 this->unref(); | 283 this->unref(); |
| 285 } | 284 } |
| 286 #endif | 285 #endif |
| OLD | NEW |