Thread safe way to request that the browser calls a plugin function on the browser or plugin thread (the thread on which the plugin was initiated).
#include <npapi.h> void NPN_PluginThreadAsyncCall(NPP plugin, void (*func)(void *), void *userData);
The function has the following parameters:
- Pointer to the current plug-in instance.
- Pointer to the function to call on the correct thread.
- Pointer to the data to pass to the function
Causes asynchronous execution of the specified function pointer on the "plugin thread", passing in the specified user data pointer when it is called. (The "plugin thread" means the thread hosting the plug-in, which today is the browser window's UI thread, though this might change in the future.)
It is the application's responsibility to perform any synchronization
between the thread calling
NPN_PluginThreadAsyncCall() and the thread on which the call is eventually executed. In particular, the user must
ensure that the function pointer remains callable and the user data is
not deallocated until the browser executes the call.
There are inherent race conditions between calling this function and
termination of the plugin instance. The browser might not execute
calls successfully registered with this API call during plugin
termination. Plugins should perform appropriate synchronization with
the code in their
NPP_Destroy() routine to ensure correct execution and avoid memory leaks.
NPN_PluginThreadAsyncCall() on the "browser main thread" or
the "plugin thread" is legal; the call to
returns immediately. After control returns to the browser, it is free
to call the function with its argument from this thread.