Function TVMFFIHandleInitOnce

Function TVMFFIHandleInitOnce#

Function Documentation#

int TVMFFIHandleInitOnce(void **handle_addr, int (*init_func)(void **result))#

Initialize a handle once in a thread-safe manner.

This function checks if *handle_addr is nullptr, and if so, calls the initialization function and stores the result in *handle_addr.

This function is thread-safe and is meant to be used by DSLs that, unlike C++, may not have static initialization support.

Note

If init_func encounters an error, it should call TVMFFIErrorSetRaisedFromCStr to set the error and return nonzero, which will then be propagated to the caller of TVMFFIHandleInitOnce.

Parameters:
  • handle_addr – The address of the handle to be initialized.

  • init_func – The initialization function to be called once to create the result handle.

Returns:

0 on success, nonzero on failure.