Skip to content

Commit

Permalink
Deprecate SbThreadGetName/SbThreadSetName (#3153)
Browse files Browse the repository at this point in the history
b/302335657

Change-Id: I483f9c77addde8bed1e45862430abd22acc28b6f
  • Loading branch information
y4vor committed May 3, 2024
1 parent efb0625 commit 925ba5a
Show file tree
Hide file tree
Showing 23 changed files with 63 additions and 14 deletions.
3 changes: 2 additions & 1 deletion base/threading/platform_thread_starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include "base/threading/platform_thread.h"

#include <pthread.h>
#include <sched.h>
#include <unistd.h>

Expand Down Expand Up @@ -127,7 +128,7 @@ void PlatformThread::Sleep(TimeDelta duration) {
// static
void PlatformThread::SetName(const std::string& name) {
ThreadIdNameManager::GetInstance()->SetName(name);
SbThreadSetName(name.c_str());
pthread_setname_np(pthread_self(), name.c_str());
}

// static
Expand Down
4 changes: 3 additions & 1 deletion cobalt/base/init_cobalt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "cobalt/base/init_cobalt.h"

#include <pthread.h>

#include <string>

#include "base/at_exit.h"
Expand Down Expand Up @@ -55,7 +57,7 @@ void InitCobalt(int argc, char* argv[], const char* link) {

// Copy the Starboard thread name to the PlatformThread name.
char thread_name[128] = {'\0'};
SbThreadGetName(thread_name, 127);
pthread_getname_np(pthread_self(), thread_name, 127);
base::PlatformThread::SetName(thread_name);
}

Expand Down
3 changes: 2 additions & 1 deletion cobalt/test/run_all_unittests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ int InitAndRunAllTests(int argc, char** argv) {

// Copy the Starboard thread name to the PlatformThread name.
char thread_name[128] = {'\0'};
SbThreadGetName(thread_name, 127);
pthread_getname_np(pthread_self(), thread_name, 127);

base::PlatformThread::SetName(thread_name);
return test_suite.Run();
}
Expand Down
4 changes: 4 additions & 0 deletions starboard/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ since the version previous to it.

## Version 16

### Deprecated the `SbThreadSetName` and `SbThreadGetName` APIs.
Replaced the `SbThreadSetName`/`SbThreadGetName` with the POSIX
`pthread_setname_np`/`pthread_getname_np`.

### Deprecated the `SbThreadLocalKey` APIs.
Replaced the `SbThreadLocalKey` with the POSIX `pthread_key_t`.

Expand Down
2 changes: 1 addition & 1 deletion starboard/android/shared/jni_env_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ JniEnvExt* JniEnvExt::Get() {
if (JNI_OK != g_vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6)) {
// Tell the JVM our thread name so it doesn't change it.
char thread_name[16];
SbThreadGetName(thread_name, sizeof(thread_name));
pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name));
JavaVMAttachArgs args{JNI_VERSION_1_6, thread_name, NULL};
g_vm->AttachCurrentThread(&env, &args);
// We don't use the value, but any non-NULL means we have to detach.
Expand Down
2 changes: 1 addition & 1 deletion starboard/android/shared/thread_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void* ThreadFunc(void* context) {
void* real_context = thread_params->context;
SbThreadAffinity affinity = thread_params->affinity;
if (thread_params->name[0] != '\0') {
SbThreadSetName(thread_params->name);
pthread_setname_np(pthread_self(), thread_params->name);
}

starboard::shared::pthread::ThreadSetPriority(thread_params->priority);
Expand Down
4 changes: 4 additions & 0 deletions starboard/android/shared/thread_get_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include <sys/prctl.h>
#include "starboard/thread.h"

void SbThreadGetName(char* buffer, int buffer_size) {
prctl(PR_GET_NAME, buffer, 0L, 0L, 0L);
}

#endif
3 changes: 2 additions & 1 deletion starboard/common/experimental/concurrency_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ class ThreadTracker {
}

char name[kSbMaxThreadNameLength + 1];
SbThreadGetName(name, kSbMaxThreadNameLength);

pthread_getname_np(pthread_self(), name, kSbMaxThreadNameLength);

int64_t thread_now = starboard::CurrentMonotonicThreadTime();
SB_LOG(INFO) << "Thread " << name << " uses "
Expand Down
4 changes: 3 additions & 1 deletion starboard/common/log.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

#include "starboard/common/log.h"

#include <pthread.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
Expand Down Expand Up @@ -166,7 +168,7 @@ void LogMessage::Init(const char* file, int line) {
filename.erase(0, last_slash_pos + 1);
}
char name[128] = {0};
SbThreadGetName(name, SB_ARRAY_SIZE_INT(name));
pthread_getname_np(pthread_self(), name, SB_ARRAY_SIZE_INT(name));
stream_ << '[';
stream_ << name << '/' << SbThreadGetId() << ':';
EzTimeValue time_value;
Expand Down
4 changes: 2 additions & 2 deletions starboard/elf_loader/exported_symbols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,9 @@ ExportedSymbols::ExportedSymbols() {

#if SB_API_VERSION < 16
REGISTER_SYMBOL(SbThreadGetLocalValue);
REGISTER_SYMBOL(SbThreadGetName);
#endif // SB_API_VERSION < 16

REGISTER_SYMBOL(SbThreadGetName);
REGISTER_SYMBOL(SbThreadIsEqual);
REGISTER_SYMBOL(SbThreadJoin);
REGISTER_SYMBOL(SbThreadSamplerCreate);
Expand All @@ -409,8 +409,8 @@ ExportedSymbols::ExportedSymbols() {
REGISTER_SYMBOL(SbThreadSetLocalValue);
#endif // SB_API_VERSION < 16

REGISTER_SYMBOL(SbThreadSetName);
#if SB_API_VERSION < 16
REGISTER_SYMBOL(SbThreadSetName);
REGISTER_SYMBOL(SbThreadSleep);
REGISTER_SYMBOL(SbThreadYield);
REGISTER_SYMBOL(SbTimeGetMonotonicNow);
Expand Down
4 changes: 4 additions & 0 deletions starboard/nplb/thread_get_name_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

// Thread joining is mostly tested in the other tests.

#if SB_API_VERSION < 16

#include "starboard/nplb/thread_helpers.h"
#include "starboard/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -44,3 +46,5 @@ TEST(SbThreadGetNameTest, SunnyDay) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif
4 changes: 4 additions & 0 deletions starboard/nplb/thread_set_name_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

// Thread joining is mostly tested in the other tests.

#if SB_API_VERSION < 16

#include "starboard/nplb/thread_helpers.h"
#include "starboard/thread.h"
#include "testing/gtest/include/gtest/gtest.h"
Expand Down Expand Up @@ -59,3 +61,5 @@ TEST(SbThreadSetNameTest, SunnyDay) {
} // namespace
} // namespace nplb
} // namespace starboard

#endif
4 changes: 4 additions & 0 deletions starboard/shared/linux/thread_get_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/thread.h"

#include <pthread.h>

void SbThreadGetName(char* buffer, int buffer_size) {
pthread_getname_np(pthread_self(), buffer, static_cast<size_t>(buffer_size));
}

#endif
4 changes: 4 additions & 0 deletions starboard/shared/linux/thread_set_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/thread.h"

#include <errno.h>
Expand Down Expand Up @@ -41,3 +43,5 @@ void SbThreadSetName(const char* name) {
SB_DLOG(ERROR) << "Failed to set thread name to " << name;
}
}

#endif
2 changes: 1 addition & 1 deletion starboard/shared/pthread/thread_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ void* ThreadFunc(void* context) {
void* real_context = thread_params->context;
SbThreadAffinity affinity = thread_params->affinity;
if (thread_params->name[0] != '\0') {
SbThreadSetName(thread_params->name);
pthread_setname_np(pthread_self(), thread_params->name);
}

starboard::shared::pthread::ThreadSetPriority(thread_params->priority);
Expand Down
4 changes: 4 additions & 0 deletions starboard/shared/stub/thread_get_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/thread.h"

void SbThreadGetName(char* buffer, int buffer_size) {}

#endif
4 changes: 4 additions & 0 deletions starboard/shared/stub/thread_set_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/thread.h"

void SbThreadSetName(const char* name) {}

#endif
2 changes: 1 addition & 1 deletion starboard/shared/win32/posix_emu/pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static unsigned ThreadTrampoline(void* thread_create_info_context) {

ThreadSubsystemSingleton* singleton = GetThreadSubsystemSingleton();
ThreadSetLocalValue(singleton->thread_private_key_, &info->thread_private_);
SbThreadSetName(info->name_.c_str());
pthread_setname_np(pthread_self(), info->name_.c_str());

void* result = info->entry_point_(info->user_context_);

Expand Down
4 changes: 3 additions & 1 deletion starboard/shared/win32/thread_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "starboard/thread.h"

#include <process.h>
#include <pthread.h>

#include <memory>

#include "starboard/common/log.h"
Expand Down Expand Up @@ -113,7 +115,7 @@ unsigned ThreadTrampoline(void* thread_create_info_context) {

ThreadSubsystemSingleton* singleton = GetThreadSubsystemSingleton();
ThreadSetLocalValue(singleton->thread_private_key_, &info->thread_private_);
SbThreadSetName(info->name_.c_str());
pthread_setname_np(pthread_self(), info->name_.c_str());

void* result = info->entry_point_(info->user_context_);

Expand Down
4 changes: 4 additions & 0 deletions starboard/shared/win32/thread_get_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/thread.h"

#include <windows.h>
Expand All @@ -26,3 +28,5 @@ void SbThreadGetName(char* buffer, int buffer_size) {
SbThreadPrivate* thread_private = GetCurrentSbThreadPrivate();
starboard::strlcpy(buffer, thread_private->name_.c_str(), buffer_size);
}

#endif
4 changes: 4 additions & 0 deletions starboard/shared/win32/thread_set_name.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if SB_API_VERSION < 16

#include "starboard/thread.h"

#include <windows.h>
Expand Down Expand Up @@ -64,3 +66,5 @@ void SbThreadSetName(const char* name) {
thread_private->name_ = name;
SetThreadName(static_cast<DWORD>(-1), name);
}

#endif
2 changes: 1 addition & 1 deletion starboard/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ SB_EXPORT SbThreadId SbThreadGetId();
// |thread2|: The second thread to compare.
SB_EXPORT bool SbThreadIsEqual(SbThread thread1, SbThread thread2);

#if SB_API_VERSION < 16
// Returns the debug name of the currently executing thread.
SB_EXPORT void SbThreadGetName(char* buffer, int buffer_size);

Expand All @@ -229,7 +230,6 @@ SB_EXPORT void SbThreadGetName(char* buffer, int buffer_size);
// |name|: The name to assign to the thread.
SB_EXPORT void SbThreadSetName(const char* name);

#if SB_API_VERSION < 16
// Creates and returns a new, unique key for thread local data. If the function
// does not succeed, the function returns |kSbThreadLocalKeyInvalid|.
//
Expand Down
2 changes: 1 addition & 1 deletion v8/src/base/platform/platform-starboard.cc
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ Thread::Thread(const Options& options)

Thread::~Thread() { delete data_; }

static void SetThreadName(const char* name) { SbThreadSetName(name); }
static void SetThreadName(const char* name) { pthread_setname_np(pthread_self(), name); }

static void* ThreadEntry(void* arg) {
Thread* thread = reinterpret_cast<Thread*>(arg);
Expand Down

0 comments on commit 925ba5a

Please sign in to comment.