Skip to content

Any reason to call a member function of the object in QSBR? #30

@abhinav04sharma

Description

@abhinav04sharma

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

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions