sourcepawn/jit/BaseRuntime.cpp
changeset 4013 6201c1180e0e
parent 3977 fca2b54741ca
child 4327 60e4042f2589
     1.1 --- a/sourcepawn/jit/BaseRuntime.cpp	Wed Aug 14 17:18:02 2013 -0400
     1.2 +++ b/sourcepawn/jit/BaseRuntime.cpp	Wed Aug 14 23:54:25 2013 -0700
     1.3 @@ -37,10 +37,21 @@
     1.4    
     1.5    memset(m_CodeHash, 0, sizeof(m_CodeHash));
     1.6    memset(m_DataHash, 0, sizeof(m_DataHash));
     1.7 +
     1.8 +  ke::AutoLock lock(g_Jit.Mutex());
     1.9 +  g_Jit.RegisterRuntime(this);
    1.10  }
    1.11  
    1.12  BaseRuntime::~BaseRuntime()
    1.13  {
    1.14 +  // The watchdog thread takes the global JIT lock while it patches all
    1.15 +  // runtimes. It is not enough to ensure that the unlinking of the runtime is
    1.16 +  // protected; we cannot delete functions or code while the watchdog might be
    1.17 +  // executing. Therefore, the entire destructor is guarded.
    1.18 +  ke::AutoLock lock(g_Jit.Mutex());
    1.19 +
    1.20 +  g_Jit.DeregisterRuntime(this);
    1.21 +
    1.22    for (uint32_t i = 0; i < m_plugin.num_publics; i++)
    1.23      delete m_PubFuncs[i];
    1.24    delete [] m_PubFuncs;