docs
Loading...
Searching...
No Matches
CAPI_ThreadFactory.h

Overview

User-defined factory for creating new threads.

#include <Ultralight/CAPI/CAPI_ThreadFactory.h>

You can implement this interface so that the library will use your own implementation for creating threads (useful for tracking thread creation, setting thread names, etc).

The factory covers the threads that run page content: script workers, the JavaScript compiler and garbage collector, networking, and resource loading. The library starts a few threads outside the factory (media playback and some background rendering work), and the libraries it links start their own, so a factory won't account for every thread in the process.

Default Implementation

When no factory is defined, the library will create threads using the default platform-specific thread creation functions (eg, _beginthreadex() on Windows, pthread_create() on POSIX).

See also
ulPlatformSetThreadFactory()

Classes

struct  ULCreateThreadResult
 Result of creating a new thread. More...
struct  ULThreadFactory
 User-defined factory for creating new threads. More...

Typedefs

typedef unsigned int ULThreadId
 Unique id of the thread, used for referencing the created thread later.
typedef unsigned long long ULThreadHandle
 Platform-specific handle.
typedef void(*) ULThreadEntryPoint(void *)
 Entry point for the thread, this function should be called by the thread once it is active and should be passed entry_point_data as the argument.
typedef bool(*) ULThreadFactoryCreateThreadCallback(void *user_data, const char *name, ULThreadType type, ULThreadEntryPoint entry_point, void *entry_point_data, ULCreateThreadResult *result)
 The callback invoked when the library wants to create a new thread.

Typedef Documentation

◆ ULThreadEntryPoint

typedef void(*) ULThreadEntryPoint(void *)

Entry point for the thread, this function should be called by the thread once it is active and should be passed entry_point_data as the argument.

◆ ULThreadFactoryCreateThreadCallback

typedef bool(*) ULThreadFactoryCreateThreadCallback(void *user_data, const char *name, ULThreadType type, ULThreadEntryPoint entry_point, void *entry_point_data, ULCreateThreadResult *result)

The callback invoked when the library wants to create a new thread.

Parameters
user_dataA user-defined pointer, see ULThreadFactory.
nameThe name of the thread (can be NULL).
typeThe type of thread.
entry_pointThe entry point for the thread.
entry_point_dataThe data to pass to the entry point.
resultThe resulting id and handle of the thread creation.
Returns
Returns whether or not the thread was created successfully.

◆ ULThreadHandle

typedef unsigned long long ULThreadHandle

Platform-specific handle.

  • on Windows this is HANDLE
  • on POSIX this is pthread_t

◆ ULThreadId

typedef unsigned int ULThreadId

Unique id of the thread, used for referencing the created thread later.

  • on Windows this should be the thread identifier (not the HANDLE that _beginthreadex() returns): the id _beginthreadex() writes through its thrdaddr out-parameter, or GetCurrentThreadId() called on the new thread
  • on POSIX this can be whatever unique id you want

Go to the source code of this file.