X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/9dae56ea45a0f5f8136a5c93d6f3a7f99399ca73..b80e619319b1def83d1e8b4f84042b661be1be7f:/wtf/Threading.cpp diff --git a/wtf/Threading.cpp b/wtf/Threading.cpp index 41c9135..49de59e 100644 --- a/wtf/Threading.cpp +++ b/wtf/Threading.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008 Apple Inc. All rights reserved. + * Copyright (C) 2008, 2009 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -26,16 +26,21 @@ #include "config.h" #include "Threading.h" +#include + namespace WTF { -struct NewThreadContext { - NewThreadContext(ThreadFunction entryPoint, void* data) +struct NewThreadContext : FastAllocBase { + NewThreadContext(ThreadFunction entryPoint, void* data, const char* name) : entryPoint(entryPoint) , data(data) - { } + , name(name) + { + } ThreadFunction entryPoint; void* data; + const char* name; Mutex creationMutex; }; @@ -44,11 +49,14 @@ static void* threadEntryPoint(void* contextData) { NewThreadContext* context = reinterpret_cast(contextData); - // Block until our creating thread has completed any extra setup work + // Block until our creating thread has completed any extra setup work, including + // establishing ThreadIdentifier. { MutexLocker locker(context->creationMutex); } + initializeCurrentThreadInternal(context->name); + // Grab the info that we need out of the context, then deallocate it. ThreadFunction entryPoint = context->entryPoint; void* data = context->data; @@ -59,9 +67,16 @@ static void* threadEntryPoint(void* contextData) ThreadIdentifier createThread(ThreadFunction entryPoint, void* data, const char* name) { - NewThreadContext* context = new NewThreadContext(entryPoint, data); + // Visual Studio has a 31-character limit on thread names. Longer names will + // be truncated silently, but we'd like callers to know about the limit. +#if !LOG_DISABLED + if (strlen(name) > 31) + LOG_ERROR("Thread name \"%s\" is longer than 31 characters and will be truncated by Visual Studio", name); +#endif + + NewThreadContext* context = new NewThreadContext(entryPoint, data, name); - // Prevent the thread body from executing until we've established the thread identifier + // Prevent the thread body from executing until we've established the thread identifier. MutexLocker locker(context->creationMutex); return createThreadInternal(threadEntryPoint, context, name);