Changeset 31864 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Apr 14, 2008, 9:30:13 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Adam Roben.

https://bugs.webkit.org/show_bug.cgi?id=18488
FastMalloc doesn't release thread-specific data on Windows

  • wtf/ThreadingWin.cpp: (WTF::threadMapMutex): (WTF::initializeThreading): Call threadMapMutex once to initialize the static safely. (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): Added a structure to wrap thread entry point and arguments. (WTF::wtfThreadEntryPoint): Make sure to end all WTF threads with pthread_exit(), to give pthreads-win32 a chance to call destructors of thread-specific data. (WTF::createThread): Use _beginthreadex instead of CreateThread, because MSDN says so. Also removed a call to CreateEvent, for which I could see no reason at all.
Location:
trunk/JavaScriptCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r31862 r31864  
     12008-04-14  Alexey Proskuryakov  <[email protected]>
     2
     3        Reviewed by Adam Roben.
     4
     5        https://bugs.webkit.org/show_bug.cgi?id=18488
     6        FastMalloc doesn't release thread-specific data on Windows
     7
     8        * wtf/ThreadingWin.cpp:
     9        (WTF::threadMapMutex): (WTF::initializeThreading): Call threadMapMutex once to initialize the static safely.
     10        (WTF::ThreadFunctionInvocation::ThreadFunctionInvocation): Added a structure to wrap thread entry point and arguments.
     11        (WTF::wtfThreadEntryPoint): Make sure to end all WTF threads with pthread_exit(), to give pthreads-win32 a chance to call
     12        destructors of thread-specific data.
     13        (WTF::createThread): Use _beginthreadex instead of CreateThread, because MSDN says so. Also removed a call to CreateEvent,
     14        for which I could see no reason at all.
     15
    1162008-04-14  Alexey Proskuryakov  <[email protected]>
    217
  • trunk/JavaScriptCore/wtf/ThreadingWin.cpp

    r31730 r31864  
    6565
    6666#include "MainThread.h"
     67#include <process.h>
    6768#include <windows.h>
    6869#include <wtf/HashMap.h>
    6970#include <wtf/MathExtras.h>
    7071
     72#if PLATFORM(WIN)
     73// Currently, Apple's Windows port uses a mixture of native and pthreads functions in FastMalloc.
     74// To ensure that thread-specific data is properly destroyed, we need to end each thread with pthread_exit().
     75#include <pthreads.h>
     76#endif
     77
    7178namespace WTF {
    7279
     
    7481
    7582static ThreadIdentifier mainThreadIdentifier;
     83
     84static Mutex& threadMapMutex()
     85{
     86    static Mutex mutex;
     87    return mutex;
     88}
    7689
    7790void initializeThreading()
     
    7992    if (!atomicallyInitializedStaticMutex) {
    8093        atomicallyInitializedStaticMutex = new Mutex;
     94        threadMapMutex();
    8195        wtf_random_init();
    8296        initializeMainThread();
     
    8599}
    86100
    87 static Mutex& threadMapMutex()
    88 {
    89     static Mutex mutex;
    90     return mutex;
    91 }
    92 
    93101static HashMap<DWORD, HANDLE>& threadMap()
    94102{
     
    116124}
    117125
     126struct ThreadFunctionInvocation {
     127    ThreadFunctionInvocation(ThreadFunction function, void* data) : function(function), data(data) {}
     128
     129    ThreadFunction function;
     130    void* data;
     131};
     132
     133static unsigned __stdcall wtfThreadEntryPoint(void* param)
     134{
     135    ThreadFunctionInvocation invocation = *static_cast<ThreadFunctionInvocation*>(param);
     136    delete static_cast<ThreadFunctionInvocation*>(param);
     137
     138    void* result = invocation.function(invocation.data);
     139
     140#if PLATFORM(WIN)
     141    // pthreads-win32 knows how to work with threads created with Win32 or CRT functions, so it's OK to mix APIs.
     142    pthread_exit(result);
     143#endif
     144
     145    return reinterpret_cast<unsigned>(result);
     146}
     147
    118148ThreadIdentifier createThread(ThreadFunction entryPoint, void* data)
    119149{
    120     DWORD threadIdentifier = 0;
     150    unsigned threadIdentifier = 0;
    121151    ThreadIdentifier threadID = 0;
    122     HANDLE hEvent = ::CreateEvent(0, FALSE, FALSE, 0);
    123     HANDLE threadHandle = ::CreateThread(0, 0, (LPTHREAD_START_ROUTINE)entryPoint, data, 0, &threadIdentifier);
     152    ThreadFunctionInvocation* invocation = new ThreadFunctionInvocation(entryPoint, data);
     153    HANDLE threadHandle = reinterpret_cast<HANDLE>(_beginthreadex(0, 0, wtfThreadEntryPoint, invocation, 0, &threadIdentifier));
    124154    if (!threadHandle) {
    125         LOG_ERROR("Failed to create thread at entry point %p with data %p", entryPoint, data);
     155        LOG_ERROR("Failed to create thread at entry point %p with data %p: %ld", entryPoint, data, errno);
    126156        return 0;
    127157    }
Note: See TracChangeset for help on using the changeset viewer.