-
Notifications
You must be signed in to change notification settings - Fork 158
Open
Description
Line 74 in 5e0de11
| TURF_CALL_MEMBER (*self->target, self->pmf)(); |
Since QSBR accepts a member function of the object here it's not clear how we can use this for object destruction. We cannot pass it the destructor of the object since that is forbidden in C++. It would be nice if we could pass arbitrary function here which takes the pointer (i.e. map element's value) as a parameter like this:
void enqueue(void (T::*func)(T*), T* target) {
struct Closure {
void (T::*func)(T*);
T* target;
static void thunk(void* param) {
Closure* self = (Closure*) param;
self->(*func)(target);
}
};
Closure closure = {func, target};
turf::LockGuard<turf::Mutex> guard(m_mutex);
TURF_RACE_DETECT_GUARD(m_flushRaceDetector);
m_deferredActions.push_back(Action(Closure::thunk, &closure, sizeof(closure)));
}
Then we could just call delete value in the callback function to free the object. For example:
struct Foo {
static void destroy(Foo *ptr) {
delete ptr;
}
}
auto value= map.erase(key);
junction::DefaultQSBR.enqueue(&Foo::destroy, value);
I was wondering if there is any reason to enforce a member function in enqueue().
Metadata
Metadata
Assignees
Labels
No labels