| OLD | NEW | 
|---|
| 1 /* | 1 /* | 
| 2  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. | 2  * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. | 
| 3  * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) | 3  * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) | 
| 4  * Copyright (C) 2011 Research In Motion Limited. All rights reserved. | 4  * Copyright (C) 2011 Research In Motion Limited. All rights reserved. | 
| 5  * | 5  * | 
| 6  * Redistribution and use in source and binary forms, with or without | 6  * Redistribution and use in source and binary forms, with or without | 
| 7  * modification, are permitted provided that the following conditions | 7  * modification, are permitted provided that the following conditions | 
| 8  * are met: | 8  * are met: | 
| 9  * | 9  * | 
| 10  * 1.  Redistributions of source code must retain the above copyright | 10  * 1.  Redistributions of source code must retain the above copyright | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 52 #if OS(LINUX) | 52 #if OS(LINUX) | 
| 53 #include <sys/syscall.h> | 53 #include <sys/syscall.h> | 
| 54 #endif | 54 #endif | 
| 55 | 55 | 
| 56 #if OS(LINUX) || OS(ANDROID) | 56 #if OS(LINUX) || OS(ANDROID) | 
| 57 #include <unistd.h> | 57 #include <unistd.h> | 
| 58 #endif | 58 #endif | 
| 59 | 59 | 
| 60 namespace WTF { | 60 namespace WTF { | 
| 61 | 61 | 
|  | 62 namespace internal { | 
|  | 63 | 
|  | 64 ThreadIdentifier currentThreadSyscall() { | 
|  | 65 #if OS(MACOSX) | 
|  | 66   return pthread_mach_thread_np(pthread_self()); | 
|  | 67 #elif OS(LINUX) | 
|  | 68   return syscall(__NR_gettid); | 
|  | 69 #elif OS(ANDROID) | 
|  | 70   return gettid(); | 
|  | 71 #else | 
|  | 72   return reinterpret_cast<uintptr_t>(pthread_self()); | 
|  | 73 #endif | 
|  | 74 } | 
|  | 75 | 
|  | 76 }  // namespace internal | 
|  | 77 | 
| 62 static Mutex* atomicallyInitializedStaticMutex; | 78 static Mutex* atomicallyInitializedStaticMutex; | 
| 63 | 79 | 
| 64 void initializeThreading() { | 80 void initializeThreading() { | 
| 65   // This should only be called once. | 81   // This should only be called once. | 
| 66   DCHECK(!atomicallyInitializedStaticMutex); | 82   DCHECK(!atomicallyInitializedStaticMutex); | 
| 67 | 83 | 
| 68   // StringImpl::empty() does not construct its static string in a threadsafe | 84   // StringImpl::empty() does not construct its static string in a threadsafe | 
| 69   // fashion, so ensure it has been initialized from here. | 85   // fashion, so ensure it has been initialized from here. | 
| 70   StringImpl::empty(); | 86   StringImpl::empty(); | 
| 71   StringImpl::empty16Bit(); | 87   StringImpl::empty16Bit(); | 
| 72   atomicallyInitializedStaticMutex = new Mutex; | 88   atomicallyInitializedStaticMutex = new Mutex; | 
| 73   wtfThreadData(); | 89   wtfThreadData(); | 
| 74   initializeDates(); | 90   initializeDates(); | 
| 75   // Force initialization of static DoubleToStringConverter converter variable | 91   // Force initialization of static DoubleToStringConverter converter variable | 
| 76   // inside EcmaScriptConverter function while we are in single thread mode. | 92   // inside EcmaScriptConverter function while we are in single thread mode. | 
| 77   double_conversion::DoubleToStringConverter::EcmaScriptConverter(); | 93   double_conversion::DoubleToStringConverter::EcmaScriptConverter(); | 
| 78 } | 94 } | 
| 79 | 95 | 
| 80 void lockAtomicallyInitializedStaticMutex() { | 96 void lockAtomicallyInitializedStaticMutex() { | 
| 81   DCHECK(atomicallyInitializedStaticMutex); | 97   DCHECK(atomicallyInitializedStaticMutex); | 
| 82   atomicallyInitializedStaticMutex->lock(); | 98   atomicallyInitializedStaticMutex->lock(); | 
| 83 } | 99 } | 
| 84 | 100 | 
| 85 void unlockAtomicallyInitializedStaticMutex() { | 101 void unlockAtomicallyInitializedStaticMutex() { | 
| 86   atomicallyInitializedStaticMutex->unlock(); | 102   atomicallyInitializedStaticMutex->unlock(); | 
| 87 } | 103 } | 
| 88 | 104 | 
| 89 ThreadIdentifier currentThread() { | 105 ThreadIdentifier currentThread() { | 
| 90 #if OS(MACOSX) | 106 // TLS lookup is fast on these platforms. | 
| 91   return pthread_mach_thread_np(pthread_self()); | 107 #if defined(__GLIBC__) || OS(ANDROID) || OS(FREEBSD) | 
| 92 #elif OS(LINUX) | 108   return wtfThreadData().threadId(); | 
| 93   return syscall(__NR_gettid); |  | 
| 94 #elif OS(ANDROID) |  | 
| 95   return gettid(); |  | 
| 96 #else | 109 #else | 
| 97   return reinterpret_cast<uintptr_t>(pthread_self()); | 110   // TODO(csharrison): For platforms where TLS lookup is slow, use the hack that | 
|  | 111   // oilpan uses in ThreadState::current() to check if this is the main thread | 
|  | 112   // via stack address. | 
|  | 113   return internal::currentThreadSyscall(); | 
| 98 #endif | 114 #endif | 
| 99 } | 115 } | 
| 100 | 116 | 
| 101 MutexBase::MutexBase(bool recursive) { | 117 MutexBase::MutexBase(bool recursive) { | 
| 102   pthread_mutexattr_t attr; | 118   pthread_mutexattr_t attr; | 
| 103   pthread_mutexattr_init(&attr); | 119   pthread_mutexattr_init(&attr); | 
| 104   pthread_mutexattr_settype( | 120   pthread_mutexattr_settype( | 
| 105       &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); | 121       &attr, recursive ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL); | 
| 106 | 122 | 
| 107   int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr); | 123   int result = pthread_mutex_init(&m_mutex.m_internalMutex, &attr); | 
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 238 } | 254 } | 
| 239 | 255 | 
| 240 void willCreateThread() { | 256 void willCreateThread() { | 
| 241   s_threadCreated = true; | 257   s_threadCreated = true; | 
| 242 } | 258 } | 
| 243 #endif | 259 #endif | 
| 244 | 260 | 
| 245 }  // namespace WTF | 261 }  // namespace WTF | 
| 246 | 262 | 
| 247 #endif  // OS(POSIX) | 263 #endif  // OS(POSIX) | 
| OLD | NEW | 
|---|