Ignore:
Timestamp:
Mar 7, 2007, 8:34:56 AM (18 years ago)
Author:
ggaren
Message:

Reviewed by Darin Adler.


Fixed ASSERT failure I just introduced.


Made the fastMalloc isForbidden flag per thread. (Oops!) We expect that
other threads will malloc while we're marking -- we just want to prevent
our own marking from malloc'ing.

  • wtf/FastMalloc.cpp: (WTF::initializeIsForbiddenKey): (WTF::isForbidden): (WTF::fastMallocForbid): (WTF::fastMallocAllow): (WTF::fastMalloc): (WTF::fastCalloc): (WTF::fastFree): (WTF::fastRealloc): (WTF::do_malloc):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/wtf/FastMalloc.cpp

    r20019 r20020  
    7979namespace WTF {
    8080
    81 static bool isForbidden = false;
     81static pthread_key_t isForbiddenKey;
     82static pthread_once_t isForbiddenKeyOnce = PTHREAD_ONCE_INIT;
     83static void initializeIsForbiddenKey()
     84{
     85  pthread_key_create(&isForbiddenKey, 0);
     86}
     87
     88static bool isForbidden()
     89{
     90    pthread_once(&isForbiddenKeyOnce, initializeIsForbiddenKey);
     91    return !!pthread_getspecific(isForbiddenKey);
     92}
     93
    8294void fastMallocForbid()
    8395{
    84     isForbidden = true;
     96    pthread_once(&isForbiddenKeyOnce, initializeIsForbiddenKey);
     97    pthread_setspecific(isForbiddenKey, &isForbiddenKey);
    8598}
    8699
    87100void fastMallocAllow()
    88101{
    89     isForbidden = false;
     102    pthread_once(&isForbiddenKeyOnce, initializeIsForbiddenKey);
     103    pthread_setspecific(isForbiddenKey, 0);
    90104}
    91105
     
    104118void *fastMalloc(size_t n)
    105119{
    106     ASSERT(!isForbidden);
     120    ASSERT(!isForbidden());
    107121    return malloc(n);
    108122}
     
    110124void *fastCalloc(size_t n_elements, size_t element_size)
    111125{
    112     ASSERT(!isForbidden);
     126    ASSERT(!isForbidden());
    113127    return calloc(n_elements, element_size);
    114128}
     
    116130void fastFree(void* p)
    117131{
    118     ASSERT(!isForbidden);
     132    ASSERT(!isForbidden());
    119133    free(p);
    120134}
     
    122136void *fastRealloc(void* p, size_t n)
    123137{
    124     ASSERT(!isForbidden);
     138    ASSERT(!isForbidden());
    125139    return realloc(p, n);
    126140}
     
    19041918#ifdef WTF_CHANGES
    19051919    ASSERT(isMultiThreaded || pthread_main_np());
    1906     ASSERT(!isForbidden);
     1920    ASSERT(!isForbidden());
    19071921#endif
    19081922
Note: See TracChangeset for help on using the changeset viewer.