mirror of
https://github.com/corda/corda.git
synced 2025-01-22 12:28:11 +00:00
Merge pull request #260 from dicej/resource-crash
fix crash on exit due to order of operations bug in ~RawMonitorResource
This commit is contained in:
commit
7273a999bc
@ -48,19 +48,19 @@ using namespace avian::util;
|
|||||||
#define ENTER(t, state) StateResource MAKE_NAME(stateResource_) (t, state)
|
#define ENTER(t, state) StateResource MAKE_NAME(stateResource_) (t, state)
|
||||||
|
|
||||||
#define THREAD_RESOURCE0(t, releaseBody) \
|
#define THREAD_RESOURCE0(t, releaseBody) \
|
||||||
class MAKE_NAME(Resource_): public Thread::Resource { \
|
class MAKE_NAME(Resource_): public Thread::AutoResource { \
|
||||||
public: \
|
public: \
|
||||||
MAKE_NAME(Resource_)(Thread* t): Resource(t) { } \
|
MAKE_NAME(Resource_)(Thread* t): AutoResource(t) { } \
|
||||||
~MAKE_NAME(Resource_)() { releaseBody; } \
|
~MAKE_NAME(Resource_)() { releaseBody; } \
|
||||||
virtual void release() \
|
virtual void release() \
|
||||||
{ this->MAKE_NAME(Resource_)::~MAKE_NAME(Resource_)(); } \
|
{ this->MAKE_NAME(Resource_)::~MAKE_NAME(Resource_)(); } \
|
||||||
} MAKE_NAME(resource_)(t);
|
} MAKE_NAME(resource_)(t);
|
||||||
|
|
||||||
#define OBJECT_RESOURCE(t, name, releaseBody) \
|
#define OBJECT_RESOURCE(t, name, releaseBody) \
|
||||||
class MAKE_NAME(Resource_): public Thread::Resource { \
|
class MAKE_NAME(Resource_): public Thread::AutoResource { \
|
||||||
public: \
|
public: \
|
||||||
MAKE_NAME(Resource_)(Thread* t, object name): \
|
MAKE_NAME(Resource_)(Thread* t, object name): \
|
||||||
Resource(t), name(name), protector(t, &(this->name)) { } \
|
AutoResource(t), name(name), protector(t, &(this->name)) { } \
|
||||||
~MAKE_NAME(Resource_)() { releaseBody; } \
|
~MAKE_NAME(Resource_)() { releaseBody; } \
|
||||||
virtual void release() \
|
virtual void release() \
|
||||||
{ this->MAKE_NAME(Resource_)::~MAKE_NAME(Resource_)(); } \
|
{ this->MAKE_NAME(Resource_)::~MAKE_NAME(Resource_)(); } \
|
||||||
@ -71,10 +71,10 @@ using namespace avian::util;
|
|||||||
} MAKE_NAME(resource_)(t, name);
|
} MAKE_NAME(resource_)(t, name);
|
||||||
|
|
||||||
#define THREAD_RESOURCE(t, type, name, releaseBody) \
|
#define THREAD_RESOURCE(t, type, name, releaseBody) \
|
||||||
class MAKE_NAME(Resource_): public Thread::Resource { \
|
class MAKE_NAME(Resource_): public Thread::AutoResource { \
|
||||||
public: \
|
public: \
|
||||||
MAKE_NAME(Resource_)(Thread* t, type name): \
|
MAKE_NAME(Resource_)(Thread* t, type name): \
|
||||||
Resource(t), name(name) { } \
|
AutoResource(t), name(name) { } \
|
||||||
~MAKE_NAME(Resource_)() { releaseBody; } \
|
~MAKE_NAME(Resource_)() { releaseBody; } \
|
||||||
virtual void release() \
|
virtual void release() \
|
||||||
{ this->MAKE_NAME(Resource_)::~MAKE_NAME(Resource_)(); } \
|
{ this->MAKE_NAME(Resource_)::~MAKE_NAME(Resource_)(); } \
|
||||||
@ -84,10 +84,10 @@ using namespace avian::util;
|
|||||||
} MAKE_NAME(resource_)(t, name);
|
} MAKE_NAME(resource_)(t, name);
|
||||||
|
|
||||||
#define THREAD_RESOURCE2(t, type1, name1, type2, name2, releaseBody) \
|
#define THREAD_RESOURCE2(t, type1, name1, type2, name2, releaseBody) \
|
||||||
class MAKE_NAME(Resource_): public Thread::Resource { \
|
class MAKE_NAME(Resource_): public Thread::AutoResource { \
|
||||||
public: \
|
public: \
|
||||||
MAKE_NAME(Resource_)(Thread* t, type1 name1, type2 name2): \
|
MAKE_NAME(Resource_)(Thread* t, type1 name1, type2 name2): \
|
||||||
Resource(t), name1(name1), name2(name2) { } \
|
AutoResource(t), name1(name1), name2(name2) { } \
|
||||||
~MAKE_NAME(Resource_)() { releaseBody; } \
|
~MAKE_NAME(Resource_)() { releaseBody; } \
|
||||||
virtual void release() \
|
virtual void release() \
|
||||||
{ this->MAKE_NAME(Resource_)::~MAKE_NAME(Resource_)(); } \
|
{ this->MAKE_NAME(Resource_)::~MAKE_NAME(Resource_)(); } \
|
||||||
@ -1375,24 +1375,32 @@ class Thread {
|
|||||||
|
|
||||||
class Resource {
|
class Resource {
|
||||||
public:
|
public:
|
||||||
Resource(Thread* t): t(t), next(t->resource) {
|
Resource(Thread* t, Resource* next): t(t), next(next) {
|
||||||
t->resource = this;
|
t->resource = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
~Resource() {
|
|
||||||
t->resource = next;
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void release() = 0;
|
virtual void release() = 0;
|
||||||
|
|
||||||
Thread* t;
|
Thread* t;
|
||||||
Resource* next;
|
Resource* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ClassInitStack: public Resource {
|
class AutoResource: public Resource {
|
||||||
|
public:
|
||||||
|
AutoResource(Thread* t): Resource(t, t->resource) { }
|
||||||
|
|
||||||
|
~AutoResource() {
|
||||||
|
t->resource = next;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void release() = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class ClassInitStack: public AutoResource {
|
||||||
public:
|
public:
|
||||||
ClassInitStack(Thread* t, object class_):
|
ClassInitStack(Thread* t, object class_):
|
||||||
Resource(t),
|
AutoResource(t),
|
||||||
next(t->classInitStack),
|
next(t->classInitStack),
|
||||||
class_(class_),
|
class_(class_),
|
||||||
protector(t, &(this->class_))
|
protector(t, &(this->class_))
|
||||||
@ -1587,10 +1595,10 @@ class Classpath {
|
|||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
template <class T>
|
template <class T>
|
||||||
class ThreadRuntimeArray: public Thread::Resource {
|
class ThreadRuntimeArray: public Thread::AutoResource {
|
||||||
public:
|
public:
|
||||||
ThreadRuntimeArray(Thread* t, unsigned size):
|
ThreadRuntimeArray(Thread* t, unsigned size):
|
||||||
Resource(t),
|
AutoResource(t),
|
||||||
body(static_cast<T*>(t->m->heap->allocate(size * sizeof(T)))),
|
body(static_cast<T*>(t->m->heap->allocate(size * sizeof(T)))),
|
||||||
size(size)
|
size(size)
|
||||||
{ }
|
{ }
|
||||||
@ -1644,10 +1652,10 @@ enterActiveState(Thread* t)
|
|||||||
enter(t, Thread::ActiveState);
|
enter(t, Thread::ActiveState);
|
||||||
}
|
}
|
||||||
|
|
||||||
class StateResource: public Thread::Resource {
|
class StateResource: public Thread::AutoResource {
|
||||||
public:
|
public:
|
||||||
StateResource(Thread* t, Thread::State state):
|
StateResource(Thread* t, Thread::State state):
|
||||||
Resource(t), oldState(t->state)
|
AutoResource(t), oldState(t->state)
|
||||||
{
|
{
|
||||||
enter(t, state);
|
enter(t, state);
|
||||||
}
|
}
|
||||||
@ -1733,10 +1741,10 @@ release(Thread* t, System::Monitor* m)
|
|||||||
m->release(t->systemThread);
|
m->release(t->systemThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
class MonitorResource: public Thread::Resource {
|
class MonitorResource: public Thread::AutoResource {
|
||||||
public:
|
public:
|
||||||
MonitorResource(Thread* t, System::Monitor* m):
|
MonitorResource(Thread* t, System::Monitor* m):
|
||||||
Resource(t), m(m)
|
AutoResource(t), m(m)
|
||||||
{
|
{
|
||||||
acquire(t, m);
|
acquire(t, m);
|
||||||
}
|
}
|
||||||
@ -1756,12 +1764,13 @@ class MonitorResource: public Thread::Resource {
|
|||||||
class RawMonitorResource: public Thread::Resource {
|
class RawMonitorResource: public Thread::Resource {
|
||||||
public:
|
public:
|
||||||
RawMonitorResource(Thread* t, System::Monitor* m):
|
RawMonitorResource(Thread* t, System::Monitor* m):
|
||||||
Resource(t), m(m)
|
Resource(t, t->resource), m(m)
|
||||||
{
|
{
|
||||||
m->acquire(t->systemThread);
|
m->acquire(t->systemThread);
|
||||||
}
|
}
|
||||||
|
|
||||||
~RawMonitorResource() {
|
~RawMonitorResource() {
|
||||||
|
t->resource = next;
|
||||||
vm::release(t, m);
|
vm::release(t, m);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1009,9 +1009,9 @@ class BootContext {
|
|||||||
|
|
||||||
class Context {
|
class Context {
|
||||||
public:
|
public:
|
||||||
class MyResource: public Thread::Resource {
|
class MyResource: public Thread::AutoResource {
|
||||||
public:
|
public:
|
||||||
MyResource(Context* c): Resource(c->thread), c(c) { }
|
MyResource(Context* c): AutoResource(c->thread), c(c) { }
|
||||||
|
|
||||||
virtual void release() {
|
virtual void release() {
|
||||||
c->dispose();
|
c->dispose();
|
||||||
@ -3857,9 +3857,9 @@ targetFieldOffset(Context* context, object field)
|
|||||||
|
|
||||||
class Stack {
|
class Stack {
|
||||||
public:
|
public:
|
||||||
class MyResource: public Thread::Resource {
|
class MyResource: public Thread::AutoResource {
|
||||||
public:
|
public:
|
||||||
MyResource(Stack* s): Resource(s->thread), s(s) { }
|
MyResource(Stack* s): AutoResource(s->thread), s(s) { }
|
||||||
|
|
||||||
virtual void release() {
|
virtual void release() {
|
||||||
s->zone.dispose();
|
s->zone.dispose();
|
||||||
|
Loading…
Reference in New Issue
Block a user