Skip to content

How to check for uninitialised ThreadSafeFunction #883

@kidneysolo

Description

@kidneysolo

Hello everyone,
I have code setup in the following way:

static ThreadSafeFunction uglyGlobalCallback = nullptr;

// ...much later in the lifetime of the module
void SetCallback(const CallbackInfo &info) {
  auto callback = info[0].As<Function>();
  uglyGlobalCallback = ThreadSafeFunction(info.Env(), callback, "UglyGlobal", 0, 1);
}

// this is a not exposed C++ function
void TriggerCallback() {
  if (/* uglyGlobalCallback is not set */) {
    // bail out
   return;
  }
  
  // uglyGlobalCallback.Call etc...
}

I was able to just check for the global callback to be != nullptr on MacOs but then I encountered a problem porting the code to Windows. On Windows the check is marked as error as no suitable operator matches the pair.

I understand the global itself is not very clean code but this is legacy stuff I would prefer not to change too much so, is there a safe way to check if the ThreadSafeFunction is actually initialised before calling it ?

Thank you :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions