Changeset 14599 for trunk/FACT++


Ignore:
Timestamp:
11/10/12 13:03:32 (12 years ago)
Author:
tbretz
Message:
Made lockers const and moved the chck for a valid main thread behin the locker; if the main thread was terminatd already set fThreadId to 0 so that no new thread will run.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/FACT++/src/InterpreterV8.cc

    r14598 r14599  
    3434    fThreadIds.clear();
    3535
    36     if (fThreadId>=0)
    37         V8::TerminateExecution(fThreadId);
     36    if (fThreadId<0)
     37        return;
     38
     39    V8::TerminateExecution(fThreadId);
     40    fThreadId = -1;
    3841}
    3942
     
    5154        // of four using a larger value, but this also means that the
    5255        // JavaScript is locked for a longer time.
     56        const Unlocker unlock;
    5357        usleep(1000);
    5458        return Undefined();
     
    7781
    7882    return handle_scope.Close(script->Run());
    79 
    80     //JsSleep(args[0]->Int32Value());
    81     //return Undefined();
    8283}
    8384
    8485void InterpreterV8::ThreadTimeout(Persistent<Function> func, uint32_t ms)
    8586{
     87    const Locker lock;
     88
    8689    if (fThreadId<0)
    8790        return;
    8891
    89     Locker lock;
    90 
    91     const HandleScope handle_scope;
    92 
    93     fGlobalContext->Enter();
    94 
    9592    const int id = V8::GetCurrentThreadId();
    9693    fThreadIds.insert(id);
     94
     95    const HandleScope handle_scope;
     96
     97    fGlobalContext->Enter();
    9798
    9899    TryCatch exception;
     
    891892void InterpreterV8::JsHandleEvent(const EventImp &evt, uint64_t cnt, const string &service)
    892893{
     894    const Locker locker;
     895
    893896    if (fThreadId<0)
    894897        return;
    895 
    896     Locker locker;
    897898
    898899    const auto it = fReverseMap.find(service);
     
    966967void InterpreterV8::JsHandleState(const std::string &server, const State &state)
    967968{
     969    const Locker locker;
     970
    968971    if (fThreadId<0)
    969972        return;
    970 
    971     Locker locker;
    972973
    973974    auto it = fStateCallbacks.find(server);
     
    14821483bool InterpreterV8::JsRun(const string &filename, const map<string, string> &map)
    14831484{
    1484     Locker locker;
     1485    const Locker locker;
    14851486    fThreadId = V8::GetCurrentThreadId();
    14861487
     
    15711572    // the signal to terminate. After they are all successfully
    15721573    // terminated, just to be sure... we lock again
    1573     Unlocker unlock;
    1574 
    1575     for (auto it=fTimeout.begin(); it!=fTimeout.end(); it++)
    1576         it->join();
    1577     fTimeout.clear();
    1578 
    1579     Locker lock2;
     1574    {
     1575        const Unlocker unlock;
     1576
     1577        for (auto it=fTimeout.begin(); it!=fTimeout.end(); it++)
     1578            it->join();
     1579        fTimeout.clear();
     1580    }
    15801581
    15811582    // Now we can dispose all persistent handles from state callbacks
Note: See TracChangeset for help on using the changeset viewer.