+2007-10-30 Adam Roben <aroben@apple.com>
+
+ Use GetCurrentThreadId instead of pthread_self in FastMalloc
+
+ Speeds up SunSpider by 0.3%.
+
+ Reviewed by Steve.
+
+ * wtf/FastMalloc.cpp:
+ (WTF::TCMalloc_ThreadCache::InitTSD):
+ (WTF::TCMalloc_ThreadCache::CreateCacheIfNecessary):
+
2007-10-30 Adam Roben <aroben@apple.com>
Switch to a Win32 critical section implementation of spinlocks
class TCMalloc_ThreadCache {
private:
typedef TCMalloc_ThreadCache_FreeList FreeList;
+#if COMPILER(MSVC)
+ typedef DWORD ThreadIdentifier;
+#else
+ typedef pthread_t ThreadIdentifier;
+#endif
size_t size_; // Combined size of data
- pthread_t tid_; // Which thread owns it
+ ThreadIdentifier tid_; // Which thread owns it
bool setspecific_; // Called pthread_setspecific?
FreeList list_[kNumClasses]; // Array indexed by size-class
TCMalloc_ThreadCache* next_;
TCMalloc_ThreadCache* prev_;
- void Init(pthread_t tid);
+ void Init(ThreadIdentifier tid);
void Cleanup();
// Accessors (mostly just for printing stats)
}
}
-void TCMalloc_ThreadCache::Init(pthread_t tid) {
+void TCMalloc_ThreadCache::Init(ThreadIdentifier tid) {
size_ = 0;
next_ = NULL;
prev_ = NULL;
#endif
tsd_inited = true;
+#if !COMPILER(MSVC)
// We may have used a fake pthread_t for the main thread. Fix it.
pthread_t zero;
memset(&zero, 0, sizeof(zero));
+#endif
#ifndef WTF_CHANGES
SpinLockHolder h(&pageheap_lock);
#else
ASSERT(pageheap_lock.IsLocked());
#endif
for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) {
+#if COMPILER(MSVC)
+ if (h->tid_ == 0) {
+ h->tid_ = GetCurrentThreadId();
+ }
+#else
if (pthread_equal(h->tid_, zero)) {
h->tid_ = pthread_self();
}
+#endif
}
}
{
SpinLockHolder h(&pageheap_lock);
+#if COMPILER(MSVC)
+ DWORD me;
+ if (!tsd_inited) {
+ me = 0;
+ } else {
+ me = GetCurrentThreadId();
+ }
+#else
// Early on in glibc's life, we cannot even call pthread_self()
pthread_t me;
if (!tsd_inited) {
} else {
me = pthread_self();
}
+#endif
// This may be a recursive malloc call from pthread_setspecific()
// In that case, the heap for this thread has already been created
// and added to the linked list. So we search for that first.
for (TCMalloc_ThreadCache* h = thread_heaps; h != NULL; h = h->next_) {
+#if COMPILER(MSVC)
+ if (h->tid_ == me) {
+#else
if (pthread_equal(h->tid_, me)) {
+#endif
heap = h;
break;
}