Changeset 34760 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Jun 24, 2008, 2:51:07 AM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Cameron Zwarich.

Make ParserRefCountedCounter actually perform a leak check.

  • kjs/nodes.cpp: (KJS::ParserRefCountedCounter::~ParserRefCountedCounter): Check for leaks in destructor, not in constructor. (KJS::ParserRefCountedCounter::increment): (KJS::ParserRefCountedCounter::decrement): (KJS::ParserRefCounted::ParserRefCounted): (KJS::ParserRefCounted::~ParserRefCounted): While at it, also made counting thread-safe.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r34754 r34760  
    4343#include <wtf/HashSet.h>
    4444#include <wtf/MathExtras.h>
     45#include <wtf/Threading.h>
    4546
    4647namespace KJS {
     
    6061
    6162struct ParserRefCountedCounter {
    62     static unsigned count;
    63     ParserRefCountedCounter()
     63    ~ParserRefCountedCounter()
    6464    {
    6565        if (count)
    6666            LOG(KJSNodeLeaks, "LEAK: %u KJS::Node\n", count);
    6767    }
     68
     69    static void increment();
     70    static void decrement();
     71
     72private:
     73    static volatile int count;
    6874};
    69 unsigned ParserRefCountedCounter::count = 0;
     75
     76volatile int ParserRefCountedCounter::count = 0;
     77
     78#if USE(MULTIPLE_THREADS)
     79void ParserRefCountedCounter::increment()
     80{
     81    atomicIncrement(&count);
     82}
     83
     84void ParserRefCountedCounter::decrement()
     85{
     86    atomicDecrement(&count);
     87}
     88
     89#else
     90
     91void ParserRefCountedCounter::increment()
     92{
     93    ++count;
     94}
     95
     96void ParserRefCountedCounter::decrement()
     97{
     98    --count;
     99}
     100#endif
     101
    70102static ParserRefCountedCounter parserRefCountedCounter;
     103
    71104#endif
    72105
     
    77110{
    78111#ifndef NDEBUG
    79     ++ParserRefCountedCounter::count;
     112    ParserRefCountedCounter::increment();
    80113#endif
    81114    if (!newTrackedObjects)
     
    88121{
    89122#ifndef NDEBUG
    90     --ParserRefCountedCounter::count;
     123    ParserRefCountedCounter::decrement();
    91124#endif
    92125}
Note: See TracChangeset for help on using the changeset viewer.