aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ports
diff options
context:
space:
mode:
authorGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-16 14:59:24 +0000
committerGravatar bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-07-16 14:59:24 +0000
commitf2e7dbb09fabc31fe5b16f6dc1a16593f518ca7d (patch)
tree5e0cc6a0bf8e2b89d57c99ef54f34e26395df548 /src/ports
parent883fe7f8b13be4ae3e3f8d8f8a6d6e94d13f9392 (diff)
Split TLS implementation into its own translation unit.
SkTLS has it's own header separate from SkThread, and having SkThread own the platform implementation of SkTLS is problematic with Chromium. The simplest way to clean this up is to put the implementation in its own set of files, where it is also more easily found. R=robertphillips@google.com Review URL: https://codereview.chromium.org/19240007 git-svn-id: http://skia.googlecode.com/svn/trunk@10105 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/ports')
-rw-r--r--src/ports/SkTLS_none.cpp18
-rw-r--r--src/ports/SkTLS_pthread.cpp30
-rw-r--r--src/ports/SkTLS_win.cpp75
-rw-r--r--src/ports/SkThread_none.cpp15
-rw-r--r--src/ports/SkThread_pthread.cpp23
-rw-r--r--src/ports/SkThread_win.cpp71
6 files changed, 123 insertions, 109 deletions
diff --git a/src/ports/SkTLS_none.cpp b/src/ports/SkTLS_none.cpp
new file mode 100644
index 0000000000..95f6e37037
--- /dev/null
+++ b/src/ports/SkTLS_none.cpp
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTLS.h"
+
+static void* gSpecific = NULL;
+
+void* SkTLS::PlatformGetSpecific(bool) {
+ return gSpecific;
+}
+
+void SkTLS::PlatformSetSpecific(void* ptr) {
+ gSpecific = ptr;
+}
diff --git a/src/ports/SkTLS_pthread.cpp b/src/ports/SkTLS_pthread.cpp
new file mode 100644
index 0000000000..4264890217
--- /dev/null
+++ b/src/ports/SkTLS_pthread.cpp
@@ -0,0 +1,30 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTLS.h"
+
+#include <pthread.h>
+
+static pthread_key_t gSkTLSKey;
+static pthread_once_t gSkTLSKey_Once = PTHREAD_ONCE_INIT;
+
+static void sk_tls_make_key() {
+ (void)pthread_key_create(&gSkTLSKey, SkTLS::Destructor);
+}
+
+void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) {
+ // should we use forceCreateTheSlot to potentially skip calling pthread_once
+ // and just return NULL if we've never been called with
+ // forceCreateTheSlot==true ?
+
+ (void)pthread_once(&gSkTLSKey_Once, sk_tls_make_key);
+ return pthread_getspecific(gSkTLSKey);
+}
+
+void SkTLS::PlatformSetSpecific(void* ptr) {
+ (void)pthread_setspecific(gSkTLSKey, ptr);
+}
diff --git a/src/ports/SkTLS_win.cpp b/src/ports/SkTLS_win.cpp
new file mode 100644
index 0000000000..dea8cd4d6b
--- /dev/null
+++ b/src/ports/SkTLS_win.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright 2013 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkTLS.h"
+#include "SkThread.h"
+
+static bool gOnce = false;
+static DWORD gTlsIndex;
+SK_DECLARE_STATIC_MUTEX(gMutex);
+
+void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) {
+ if (!forceCreateTheSlot && !gOnce) {
+ return NULL;
+ }
+
+ if (!gOnce) {
+ SkAutoMutexAcquire tmp(gMutex);
+ if (!gOnce) {
+ gTlsIndex = TlsAlloc();
+ gOnce = true;
+ }
+ }
+ return TlsGetValue(gTlsIndex);
+}
+
+void SkTLS::PlatformSetSpecific(void* ptr) {
+ SkASSERT(gOnce);
+ (void)TlsSetValue(gTlsIndex, ptr);
+}
+
+// Call TLS destructors on thread exit. Code based on Chromium's
+// base/threading/thread_local_storage_win.cc
+#ifdef _WIN64
+
+#pragma comment(linker, "/INCLUDE:_tls_used")
+#pragma comment(linker, "/INCLUDE:skia_tls_callback")
+
+#else
+
+#pragma comment(linker, "/INCLUDE:__tls_used")
+#pragma comment(linker, "/INCLUDE:_skia_tls_callback")
+
+#endif
+
+void NTAPI onTLSCallback(PVOID unused, DWORD reason, PVOID unused2) {
+ if ((DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) && gOnce) {
+ void* ptr = TlsGetValue(gTlsIndex);
+ if (ptr != NULL) {
+ SkTLS::Destructor(ptr);
+ TlsSetValue(gTlsIndex, NULL);
+ }
+ }
+}
+
+extern "C" {
+
+#ifdef _WIN64
+
+#pragma const_seg(".CRT$XLB")
+extern const PIMAGE_TLS_CALLBACK skia_tls_callback;
+const PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
+#pragma const_seg()
+
+#else
+
+#pragma data_seg(".CRT$XLB")
+PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
+#pragma data_seg()
+
+#endif
+}
diff --git a/src/ports/SkThread_none.cpp b/src/ports/SkThread_none.cpp
index 1122c959d3..638d7d017d 100644
--- a/src/ports/SkThread_none.cpp
+++ b/src/ports/SkThread_none.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2006 The Android Open Source Project
*
@@ -6,9 +5,7 @@
* found in the LICENSE file.
*/
-
#include "SkThread.h"
-#include "SkTLS.h"
int32_t sk_atomic_inc(int32_t* addr) {
int32_t value = *addr;
@@ -44,15 +41,3 @@ SkMutex::~SkMutex() {}
void SkMutex::acquire() {}
void SkMutex::release() {}
#endif
-
-//////////////////////////////////////////////////////////////////////////
-
-static void* gSpecific;
-
-void* SkTLS::PlatformGetSpecific(bool) {
- return gSpecific;
-}
-
-void SkTLS::PlatformSetSpecific(void* ptr) {
- gSpecific = ptr;
-}
diff --git a/src/ports/SkThread_pthread.cpp b/src/ports/SkThread_pthread.cpp
index 370f673d86..a78c7b2f14 100644
--- a/src/ports/SkThread_pthread.cpp
+++ b/src/ports/SkThread_pthread.cpp
@@ -6,7 +6,6 @@
* found in the LICENSE file.
*/
#include "SkThread.h"
-#include "SkTLS.h"
#include <pthread.h>
#include <errno.h>
@@ -196,25 +195,3 @@ void SkMutex::release() {
}
#endif // !SK_USE_POSIX_THREADS
-
-///////////////////////////////////////////////////////////////////////////////
-
-static pthread_key_t gSkTLSKey;
-static pthread_once_t gSkTLSKey_Once = PTHREAD_ONCE_INIT;
-
-static void sk_tls_make_key() {
- (void)pthread_key_create(&gSkTLSKey, SkTLS::Destructor);
-}
-
-void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) {
- // should we use forceCreateTheSlot to potentially skip calling pthread_once
- // and just return NULL if we've never been called with
- // forceCreateTheSlot==true ?
-
- (void)pthread_once(&gSkTLSKey_Once, sk_tls_make_key);
- return pthread_getspecific(gSkTLSKey);
-}
-
-void SkTLS::PlatformSetSpecific(void* ptr) {
- (void)pthread_setspecific(gSkTLSKey, ptr);
-}
diff --git a/src/ports/SkThread_win.cpp b/src/ports/SkThread_win.cpp
index c69fc4506d..708db24ab9 100644
--- a/src/ports/SkThread_win.cpp
+++ b/src/ports/SkThread_win.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2008 The Android Open Source Project
*
@@ -6,11 +5,9 @@
* found in the LICENSE file.
*/
-
#include <windows.h>
#include <intrin.h>
#include "SkThread.h"
-#include "SkTLS.h"
//MSDN says in order to declare an interlocked function for use as an
//intrinsic, include intrin.h and put the function in a #pragma intrinsic
@@ -66,71 +63,3 @@ void SkMutex::acquire() {
void SkMutex::release() {
LeaveCriticalSection(reinterpret_cast<CRITICAL_SECTION*>(&fStorage));
}
-
-///////////////////////////////////////////////////////////////////////////
-
-static bool gOnce;
-static DWORD gTlsIndex;
-SK_DECLARE_STATIC_MUTEX(gMutex);
-
-void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) {
- if (!forceCreateTheSlot && !gOnce) {
- return NULL;
- }
-
- if (!gOnce) {
- SkAutoMutexAcquire tmp(gMutex);
- if (!gOnce) {
- gTlsIndex = TlsAlloc();
- gOnce = true;
- }
- }
- return TlsGetValue(gTlsIndex);
-}
-
-void SkTLS::PlatformSetSpecific(void* ptr) {
- SkASSERT(gOnce);
- (void)TlsSetValue(gTlsIndex, ptr);
-}
-
-// Call TLS destructors on thread exit. Code based on Chromium's
-// base/threading/thread_local_storage_win.cc
-#ifdef _WIN64
-
-#pragma comment(linker, "/INCLUDE:_tls_used")
-#pragma comment(linker, "/INCLUDE:skia_tls_callback")
-
-#else
-
-#pragma comment(linker, "/INCLUDE:__tls_used")
-#pragma comment(linker, "/INCLUDE:_skia_tls_callback")
-
-#endif
-
-void NTAPI onTLSCallback(PVOID unused, DWORD reason, PVOID unused2) {
- if ((DLL_THREAD_DETACH == reason || DLL_PROCESS_DETACH == reason) && gOnce) {
- void* ptr = TlsGetValue(gTlsIndex);
- if (ptr != NULL) {
- SkTLS::Destructor(ptr);
- TlsSetValue(gTlsIndex, NULL);
- }
- }
-}
-
-extern "C" {
-
-#ifdef _WIN64
-
-#pragma const_seg(".CRT$XLB")
-extern const PIMAGE_TLS_CALLBACK skia_tls_callback;
-const PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
-#pragma const_seg()
-
-#else
-
-#pragma data_seg(".CRT$XLB")
-PIMAGE_TLS_CALLBACK skia_tls_callback = onTLSCallback;
-#pragma data_seg()
-
-#endif
-}