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