From 0c15b2743d232bf98cb6e3d11d6c784b27597b3f Mon Sep 17 00:00:00 2001 From: cobalt-github-releaser-bot <95661244+cobalt-github-releaser-bot@users.noreply.github.com> Date: Fri, 3 May 2024 21:28:42 -0700 Subject: [PATCH] Cherry pick PR #3161: Remove unused TLSKeyManager (#3164) Refer to the original PR: https://github.com/youtube/cobalt/pull/3161 b/338649380 Change-Id: I8ef4ccab8998adfb9c84a0d1f39889cee48da877 Co-authored-by: Yavor Goulishev --- .../starboard/thread_create_local_key.cc | 25 ------ .../starboard/thread_destroy_local_key.cc | 24 ------ .../starboard/thread_get_local_value.cc | 24 ------ .../starboard/thread_local_storage_internal.h | 84 ------------------- .../starboard/thread_set_local_value.cc | 21 ----- 5 files changed, 178 deletions(-) delete mode 100644 starboard/shared/starboard/thread_create_local_key.cc delete mode 100644 starboard/shared/starboard/thread_destroy_local_key.cc delete mode 100644 starboard/shared/starboard/thread_get_local_value.cc delete mode 100644 starboard/shared/starboard/thread_local_storage_internal.h delete mode 100644 starboard/shared/starboard/thread_set_local_value.cc diff --git a/starboard/shared/starboard/thread_create_local_key.cc b/starboard/shared/starboard/thread_create_local_key.cc deleted file mode 100644 index a1f7d69008f3..000000000000 --- a/starboard/shared/starboard/thread_create_local_key.cc +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if SB_API_VERSION < 16 - -#include "starboard/thread.h" - -#include "starboard/shared/starboard/thread_local_storage_internal.h" - -SbThreadLocalKey SbThreadCreateLocalKey(SbThreadLocalDestructor destructor) { - return starboard::shared::TLSKeyManager::Get()->CreateKey(destructor); -} - -#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/starboard/thread_destroy_local_key.cc b/starboard/shared/starboard/thread_destroy_local_key.cc deleted file mode 100644 index f4a194625e31..000000000000 --- a/starboard/shared/starboard/thread_destroy_local_key.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if SB_API_VERSION < 16 - -#include "starboard/thread.h" - -#include "starboard/shared/starboard/thread_local_storage_internal.h" - -void SbThreadDestroyLocalKey(SbThreadLocalKey key) { - starboard::shared::TLSKeyManager::Get()->DestroyKey(key); -} -#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/starboard/thread_get_local_value.cc b/starboard/shared/starboard/thread_get_local_value.cc deleted file mode 100644 index 7d51b6fb37d8..000000000000 --- a/starboard/shared/starboard/thread_get_local_value.cc +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#if SB_API_VERSION < 16 - -#include "starboard/thread.h" - -#include "starboard/shared/starboard/thread_local_storage_internal.h" - -void* SbThreadGetLocalValue(SbThreadLocalKey key) { - return starboard::shared::TLSKeyManager::Get()->GetLocalValue(key); -} -#endif // SB_API_VERSION < 16 diff --git a/starboard/shared/starboard/thread_local_storage_internal.h b/starboard/shared/starboard/thread_local_storage_internal.h deleted file mode 100644 index 1964af0c737a..000000000000 --- a/starboard/shared/starboard/thread_local_storage_internal.h +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef STARBOARD_SHARED_STARBOARD_THREAD_LOCAL_STORAGE_INTERNAL_H_ -#define STARBOARD_SHARED_STARBOARD_THREAD_LOCAL_STORAGE_INTERNAL_H_ - -#if SB_API_VERSION < 16 - -#include - -#include "starboard/common/mutex.h" -#include "starboard/common/scoped_ptr.h" -#include "starboard/configuration_constants.h" -#include "starboard/shared/internal_only.h" -#include "starboard/thread.h" - -namespace starboard { -namespace shared { - -class TLSKeyManager { - public: - static TLSKeyManager* Get(); - - TLSKeyManager(); - - // Returns a unique ID that acts as a new key for a thread local storage - // value. - SbThreadLocalKey CreateKey(SbThreadLocalDestructor destructor); - - // Destroys the specified key, making its ID available for re-use in a - // subsequent call to AllocateKey(). - void DestroyKey(SbThreadLocalKey key); - - // Sets the thread local value for the given key. - bool SetLocalValue(SbThreadLocalKey key, void* value); - - // Returns the thread local value for the given key. - void* GetLocalValue(SbThreadLocalKey key); - - private: - // We add 1 to kSbMaxThreads here to account for the main thread. - static const int kMaxThreads = kSbMaxThreads + 1; - struct KeyRecord { - bool valid; - SbThreadLocalDestructor destructor; - std::vector values(kMaxThreads); - }; - - // Sets up the specified key. - int GetUnusedKeyIndex(); - - // Returns true if the given key is a valid, current unique TLS ID. Active - // means it has been allocated via AllocateKey() but has not yet been - // destroyed via DestroyKey(). - bool IsKeyActive(SbThreadLocalKey key); - - // Returns the TLS ID of the current thread, used for indexing into - // KeyRecord::values. - int GetCurrentThreadId(); - - // Access to the class members below are protected by this mutex so that they - // can be updated by any thread at any time. - Mutex mutex_; - - struct InternalData; - scoped_ptr data_; -}; - -} // namespace shared -} // namespace starboard - -#endif // SB_API_VERSION < 16 -#endif // STARBOARD_SHARED_STARBOARD_THREAD_LOCAL_STORAGE_INTERNAL_H_ diff --git a/starboard/shared/starboard/thread_set_local_value.cc b/starboard/shared/starboard/thread_set_local_value.cc deleted file mode 100644 index 4d5dd623d58a..000000000000 --- a/starboard/shared/starboard/thread_set_local_value.cc +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2015 The Cobalt Authors. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "starboard/thread.h" - -#include "starboard/shared/starboard/thread_local_storage_internal.h" - -bool SbThreadSetLocalValue(SbThreadLocalKey key, void* value) { - return starboard::shared::TLSKeyManager::Get()->SetLocalValue(key, value); -}