mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-25 17:25:08 +02:00
LibThreading: Allow configuring thread stack size
Add set_stack_size() to Threading::Thread and use pthread_attr_t to apply it in start().
This commit is contained in:
committed by
Andreas Kling
parent
5eeac1b9dd
commit
a116f08acb
Notes:
github-actions[bot]
2026-03-06 12:08:19 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/a116f08acba Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8211 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/Zaggy1024 Reviewed-by: https://github.com/alimpfard
@@ -70,10 +70,17 @@ void Thread::start()
|
||||
// Set this first so that the other thread starts out seeing m_state == Running.
|
||||
m_state = Threading::ThreadState::Running;
|
||||
|
||||
pthread_attr_t attr;
|
||||
pthread_attr_t* attr_ptr = nullptr;
|
||||
if (m_stack_size > 0) {
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setstacksize(&attr, m_stack_size);
|
||||
attr_ptr = &attr;
|
||||
}
|
||||
|
||||
int rc = pthread_create(
|
||||
&m_tid,
|
||||
// FIXME: Use pthread_attr_t to start a thread detached if that was requested by the user before the call to start().
|
||||
nullptr,
|
||||
attr_ptr,
|
||||
[](void* arg) -> void* {
|
||||
auto self = adopt_ref(*static_cast<Thread*>(arg));
|
||||
|
||||
@@ -112,6 +119,9 @@ void Thread::start()
|
||||
},
|
||||
&NonnullRefPtr(*this).leak_ref());
|
||||
|
||||
if (attr_ptr)
|
||||
pthread_attr_destroy(attr_ptr);
|
||||
|
||||
VERIFY(rc == 0);
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,8 @@ public:
|
||||
ErrorOr<void> set_priority(int priority);
|
||||
ErrorOr<int> get_priority() const;
|
||||
|
||||
void set_stack_size(size_t size) { m_stack_size = size; }
|
||||
|
||||
// Only callable in the Startable state.
|
||||
void start();
|
||||
// Only callable in the Running state.
|
||||
@@ -81,6 +83,7 @@ private:
|
||||
pthread_t m_tid {};
|
||||
ByteString m_thread_name;
|
||||
Atomic<ThreadState> m_state { ThreadState::Startable };
|
||||
size_t m_stack_size { 0 };
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
|
||||
Reference in New Issue
Block a user