bungeman@google.com | f2e7dbb | 2013-07-16 14:59:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | #include "SkTLS.h" |
mtklein | 2cb49bd | 2016-05-24 07:01:48 -0700 | [diff] [blame] | 9 | #include "SkOnce.h" |
bungeman@google.com | f2e7dbb | 2013-07-16 14:59:24 +0000 | [diff] [blame] | 10 | |
| 11 | #include <pthread.h> |
| 12 | |
| 13 | static pthread_key_t gSkTLSKey; |
bungeman@google.com | f2e7dbb | 2013-07-16 14:59:24 +0000 | [diff] [blame] | 14 | |
| 15 | void* SkTLS::PlatformGetSpecific(bool forceCreateTheSlot) { |
mtklein | 2cb49bd | 2016-05-24 07:01:48 -0700 | [diff] [blame] | 16 | // should we use forceCreateTheSlot to potentially just return nullptr if |
| 17 | // we've never been called with forceCreateTheSlot==true ? |
| 18 | static SkOnce once; |
| 19 | once(pthread_key_create, &gSkTLSKey, SkTLS::Destructor); |
bungeman@google.com | f2e7dbb | 2013-07-16 14:59:24 +0000 | [diff] [blame] | 20 | return pthread_getspecific(gSkTLSKey); |
| 21 | } |
| 22 | |
| 23 | void SkTLS::PlatformSetSpecific(void* ptr) { |
| 24 | (void)pthread_setspecific(gSkTLSKey, ptr); |
| 25 | } |