Changeset 27707 in webkit


Ignore:
Timestamp:
Nov 11, 2007 9:54:59 PM (16 years ago)
Author:
mrowe@apple.com
Message:

2007-11-11 Justin Haygood <jhaygood@reaktix.com>

Reviewed by Adam Roben.

http://bugs.webkit.org/show_bug.cgi?id=15939
Adds a currentThread API for use by SQLiteDatabase, etc.

  • platform/Threading.h:
  • platform/ThreadingNone.cpp: (WebCore::currentThread):
  • platform/gtk/ThreadingGtk.cpp: (WebCore::identifierByGthreadHandle): (WebCore::):
  • platform/pthreads/ThreadingPthreads.cpp: (WebCore::identifierByPthreadHandle): (WebCore::currentThread):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r27706 r27707  
     12007-11-11  Justin Haygood  <jhaygood@reaktix.com>
     2
     3        Reviewed by Adam Roben.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=15939
     6        Adds a currentThread API for use by SQLiteDatabase, etc.
     7
     8        * platform/Threading.h:
     9        * platform/ThreadingNone.cpp:
     10        (WebCore::currentThread):
     11        * platform/gtk/ThreadingGtk.cpp:
     12        (WebCore::identifierByGthreadHandle):
     13        (WebCore::):
     14        * platform/pthreads/ThreadingPthreads.cpp:
     15        (WebCore::identifierByPthreadHandle):
     16        (WebCore::currentThread):
     17
    1182007-11-11  Dan Bernstein  <mitz@apple.com>
    219
  • trunk/WebCore/platform/Threading.h

    r26864 r27707  
    11/*
    22 * Copyright (C) 2007 Apple Inc. All rights reserved.
     3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4243#endif
    4344
     45#if PLATFORM(QT)
     46class QMutex;
     47class QWaitCondition;
     48#endif
     49
    4450#include <stdint.h>
    4551
     
    5157// Returns 0 if thread creation failed
    5258ThreadIdentifier createThread(ThreadFunction, void*);
     59ThreadIdentifier currentThread();
    5360int waitForThreadCompletion(ThreadIdentifier, void**);
    5461void detachThread(ThreadIdentifier);
     
    6067typedef GMutex* PlatformMutex;
    6168typedef GCond* PlatformCondition;
     69#elif PLATFORM(QT)
     70typedef QMutex* PlatformMutex;
     71typedef QWaitCondition* PlatformCondition;
    6272#else
    6373typedef void* PlatformMutex;
  • trunk/WebCore/platform/ThreadingNone.cpp

    r26722 r27707  
    11/*
    22 * Copyright (C) 2007 Apple Inc. All rights reserved.
     3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3435int waitForThreadCompletion(ThreadIdentifier, void**) { return 0; }
    3536void detachThread(ThreadIdentifier) { }
     37ThreadIdentifier currentThread() { return 0; }
    3638
    3739Mutex::Mutex() {}
  • trunk/WebCore/platform/gtk/ThreadingGtk.cpp

    r26864 r27707  
    11/*
    22 * Copyright (C) 2007 Apple Inc. All rights reserved.
     3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    8081}
    8182
     83static ThreadIdentifier identifierByGthreadHandle(GThread*& thread)
     84{
     85    MutexLocker locker(threadMapMutex());
     86
     87    HashMap<ThreadIdentifier, GThread*>::iterator i = threadMap().begin();
     88    for (; i != threadMap().end(); ++i) {
     89        if (i->second == thread)
     90            return i->first;
     91    }
     92
     93    return 0;
     94}
     95
    8296static GThread* threadForIdentifier(ThreadIdentifier id)
    8397{
     
    125139}
    126140
     141ThreadIdentifier currentThread()
     142{
     143    GThread* currentThread = g_thread_self();
     144    if (ThreadIdentifier id = identifierByGthreadHandle(currentThread))
     145        return id;
     146    return establishIdentifierForThread(currentThread);
     147}
     148
    127149Mutex::Mutex()
    128150    : m_mutex(g_mutex_new())
  • trunk/WebCore/platform/pthreads/ThreadingPthreads.cpp

    r26824 r27707  
    11/*
    22 * Copyright (C) 2007 Apple Inc. All rights reserved.
     3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com)
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    5960}
    6061
     62static ThreadIdentifier identifierByPthreadHandle(const pthread_t& pthreadHandle)
     63{
     64    MutexLocker locker(threadMapMutex());
     65
     66    HashMap<ThreadIdentifier, pthread_t>::iterator i = threadMap().begin();
     67    for (; i != threadMap().end(); ++i) {
     68        if (pthread_equal(i->second, pthreadHandle))
     69            return i->first;
     70    }
     71
     72    return 0;
     73}
     74
    6175static pthread_t pthreadHandleForIdentifier(ThreadIdentifier id)
    6276{
     
    113127}
    114128
     129ThreadIdentifier currentThread()
     130{
     131    pthread_t currentThread = pthread_self();
     132    if (ThreadIdentifier id = identifierByPthreadHandle(currentThread))
     133        return id;
     134    return establishIdentifierForPthreadHandle(currentThread);
     135}
     136
    115137Mutex::Mutex()
    116138{
Note: See TracChangeset for help on using the changeset viewer.