docs
Docs
C++ API
C API
Search API
Ctrl K
2.0
2.0
latest
1.4
Ultralight C++ API
2.0.0
Toggle main menu visibility
Loading...
Searching...
No Matches
Thread.h
Go to the documentation of this file.
1
///
2
/// Copyright (C) 2026 Ultralight, Inc. All rights reserved.
3
/// A license is required for commercial use. https://ultralig.ht
4
///
5
#pragma once
6
#include <
Ultralight/Defines.h
>
7
8
namespace
ultralight
{
9
10
///
11
/// Unique id of the thread, used for referencing the created thread later.
12
/// * on Windows this should be the thread identifier (not the HANDLE that _beginthreadex()
13
/// returns): the id _beginthreadex() writes through its `thrdaddr` out-parameter, or
14
/// GetCurrentThreadId() called on the new thread
15
/// * on POSIX this can be whatever unique id you want
16
///
17
typedef
uint32_t
ThreadId
;
18
19
///
20
/// Platform-specific handle
21
/// * on Windows this is HANDLE
22
/// * on POSIX this is pthread_t
23
///
24
typedef
uint64_t
ThreadHandle
;
25
26
///
27
/// Entry point for the thread, this function should be called by the thread once it is active
28
/// and should be passed entry_point_data as the argument.
29
///
30
typedef
void (*
ThreadEntryPoint
)(
void
*);
31
32
///
33
/// The type of thread, you can choose to optionally handle these for better performance.
34
///
35
enum class
ThreadType
: uint8_t {
36
Unknown = 0,
37
JavaScript
,
38
Compiler
,
39
GarbageCollection
,
40
Network
,
41
Graphics
,
42
Audio
,
43
};
44
45
///
46
/// Result of creating a new thread.
47
///
48
/// This struct is used to return the id and handle of the created thread.
49
///
50
struct
UExport
CreateThreadResult
{
51
ThreadId
id
;
///< The unique id of the thread. @see ThreadId
52
ThreadHandle
handle
;
///< The platform-specific handle of the thread. @see ThreadHandle
53
};
54
55
///
56
/// User-defined factory for creating new threads.
57
///
58
/// You can implement this interface so that the library will use your own implementation for
59
/// creating threads (useful for tracking thread creation, setting thread names, etc).
60
///
61
/// The factory covers the threads that run page content: script workers, the JavaScript compiler
62
/// and garbage collector, networking, and resource loading. The library starts a few threads
63
/// outside the factory (media playback and some background rendering work), and the libraries it
64
/// links start their own, so a factory won't account for every thread in the process.
65
///
66
/// ## Default Implementation
67
///
68
/// When no factory is defined, the library will create threads using the default platform-specific
69
/// thread creation functions (eg, `_beginthreadex()` on Windows, `pthread_create()` on POSIX).
70
///
71
/// ## Setting the Thread Factory
72
///
73
/// To provide your own custom ThreadFactory implementation, you should inherit from this class,
74
/// handle the virtual member functions, and then pass an instance to
75
/// Platform::set_thread_factory().
76
///
77
class
UExport
ThreadFactory
{
78
public
:
79
virtual
~ThreadFactory
() =
default
;
80
81
///
82
/// Create a new thread.
83
///
84
/// @param name The name of the thread (can be nullptr).
85
/// @param type The type of thread.
86
/// @param entry_point The entry point for the thread.
87
/// @param entry_point_data The data to pass to the entry point.
88
/// @param result The resulting id and handle of the thread creation.
89
///
90
/// @return Returns whether or not the thread was created successfully.
91
///
92
virtual
bool
CreateThread
(
const
char
* name,
ThreadType
type,
ThreadEntryPoint
entry_point,
93
void
* entry_point_data,
CreateThreadResult
& result) = 0;
94
};
95
96
}
// namespace ultralight
UExport
#define UExport
Definition
Exports.h:22
Defines.h
ultralight::ThreadFactory
User-defined factory for creating new threads.
Definition
Thread.h:77
ultralight::ThreadFactory::CreateThread
virtual bool CreateThread(const char *name, ThreadType type, ThreadEntryPoint entry_point, void *entry_point_data, CreateThreadResult &result)=0
Create a new thread.
ultralight::ThreadFactory::~ThreadFactory
virtual ~ThreadFactory()=default
ultralight
Root namespace for every public Ultralight type, function, and enumeration.
ultralight::ThreadEntryPoint
void(*) ThreadEntryPoint(void *)
Entry point for the thread, this function should be called by the thread once it is active and should...
Definition
Thread.h:30
ultralight::ThreadId
uint32_t ThreadId
Unique id of the thread, used for referencing the created thread later.
Definition
Thread.h:17
ultralight::ThreadHandle
uint64_t ThreadHandle
Platform-specific handle.
Definition
Thread.h:24
ultralight::ThreadType
ThreadType
The type of thread, you can choose to optionally handle these for better performance.
Definition
Thread.h:35
ultralight::ThreadType::Compiler
@ Compiler
Definition
Thread.h:38
ultralight::ThreadType::JavaScript
@ JavaScript
Definition
Thread.h:37
ultralight::ThreadType::Audio
@ Audio
Definition
Thread.h:42
ultralight::ThreadType::Graphics
@ Graphics
Definition
Thread.h:41
ultralight::ThreadType::Network
@ Network
Definition
Thread.h:40
ultralight::ThreadType::GarbageCollection
@ GarbageCollection
Definition
Thread.h:39
ultralight::CreateThreadResult
Result of creating a new thread.
Definition
Thread.h:50
ultralight::CreateThreadResult::id
ThreadId id
The unique id of the thread.
Definition
Thread.h:51
ultralight::CreateThreadResult::handle
ThreadHandle handle
The platform-specific handle of the thread.
Definition
Thread.h:52
Ultralight
platform
Thread.h
Docs
C++ API
C API
Version
2.0
2.0
latest
1.4