Visit Mozilla.org

NPN PluginThreadAsyncCall

From MDC

« Gecko Plugin API Reference « Browser Side Plug-in API

Introduced in Gecko 1.9

Contents

[edit] Summary

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).

[edit] Syntax

#include <npapi.h>
 
void
NPN_PluginThreadAsyncCall(NPP plugin,
                          void (*func)(void *),
                          void *userData);

[edit] Parameters

The function has the following parameters:

npp
Pointer to the current plug-in instance.
func
Pointer to the function to call on the correct thread.
userData
Pointer to the data to pass to the function func once called.

[edit] Returns

  • Nothing

[edit] Description

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.

Calling NPN_PluginThreadAsyncCall() on the "browser main thread" or the "plugin thread" is legal; the call to NPN_PluginThreadAsyncCall() returns immediately. After control returns to the browser, it is free to call the function with its argument from this thread.

[edit] See Also

NPP