Commit c32ab617 authored by ap@webkit.org's avatar ap@webkit.org
Browse files

Reviewed by Maciej.

        Thread static data destructors are not guaranteed to be called in any particular order;
        turn ThreadSpecific into a phoenix-style singleton to avoid accessing freed memory when
        deleted objects are interdependent (e.g. CommonIdentifiers and internal identifier tables).

        No change on SunSpider.

        * wtf/ThreadSpecific.h:
        (WTF::ThreadSpecific::Data::Data):
        (WTF::::get):
        (WTF::::set):
        (WTF::::destroy):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@32000 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent d0c768a0
2008-04-17 Alexey Proskuryakov <ap@webkit.org>
Reviewed by Maciej.
Thread static data destructors are not guaranteed to be called in any particular order;
turn ThreadSpecific into a phoenix-style singleton to avoid accessing freed memory when
deleted objects are interdependent (e.g. CommonIdentifiers and internal identifier tables).
No change on SunSpider.
* wtf/ThreadSpecific.h:
(WTF::ThreadSpecific::Data::Data):
(WTF::::get):
(WTF::::set):
(WTF::::destroy):
2008-04-15 Srinivas Rao. M Hamse <msrinirao@gmail.com>
Reviewed by Maciej Stachowiak.
......
......@@ -53,6 +53,13 @@ private:
void static destroy(void* ptr);
#if USE(PTHREADS) || PLATFORM(WIN)
struct Data : Noncopyable {
Data(T* value, ThreadSpecific<T>* owner) : value(value), owner(owner) {}
T* value;
ThreadSpecific<T>* owner;
};
pthread_key_t m_key;
#endif
};
......@@ -73,20 +80,24 @@ inline ThreadSpecific<T>::~ThreadSpecific()
template<typename T>
inline T* ThreadSpecific<T>::get()
{
return static_cast<T*>(pthread_getspecific(m_key));
Data* data = static_cast<Data*>(pthread_getspecific(m_key));
return data ? data->value : 0;
}
template<typename T>
inline void ThreadSpecific<T>::set(T* ptr)
{
ASSERT(!get());
pthread_setspecific(m_key, ptr);
pthread_setspecific(m_key, new Data(ptr, this));
}
template<typename T>
inline void ThreadSpecific<T>::destroy(void* ptr)
{
delete static_cast<T*>(ptr);
Data* data = static_cast<Data*>(ptr);
pthread_setspecific(data->owner->m_key, 0);
delete data->value;
delete data;
}
#else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment