[gjs] context: Use native c++ thread to keep track of the context thread
- From: Philip Chimento <pchimento src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gjs] context: Use native c++ thread to keep track of the context thread
- Date: Tue, 18 May 2021 05:40:30 +0000 (UTC)
commit e3e2abc06007dd2cf85dc96b63555697cbaa4d87
Author: Marco Trevisan (TreviƱo) <mail 3v1n0 net>
Date: Wed May 12 18:23:15 2021 +0200
context: Use native c++ thread to keep track of the context thread
gjs/context-private.h | 5 +++--
gjs/context.cpp | 4 ++--
2 files changed, 5 insertions(+), 4 deletions(-)
---
diff --git a/gjs/context-private.h b/gjs/context-private.h
index bcd99e57..93d87909 100644
--- a/gjs/context-private.h
+++ b/gjs/context-private.h
@@ -12,6 +12,7 @@
#include <atomic>
#include <string>
+#include <thread>
#include <unordered_map>
#include <vector>
@@ -56,7 +57,7 @@ class GjsContextPrivate : public JS::JobQueue {
JSContext* m_cx;
JS::Heap<JSObject*> m_global;
JS::Heap<JSObject*> m_internal_global;
- GThread* m_owner_thread;
+ std::thread::id m_owner_thread;
char* m_program_name;
char* m_program_path;
@@ -178,7 +179,7 @@ class GjsContextPrivate : public JS::JobQueue {
void set_args(std::vector<std::string>&& args);
GJS_JSAPI_RETURN_CONVENTION JSObject* build_args_array();
[[nodiscard]] bool is_owner_thread() const {
- return m_owner_thread == g_thread_self();
+ return m_owner_thread == std::this_thread::get_id();
}
[[nodiscard]] JS::WeakCache<FundamentalTable>& fundamental_table() {
return *m_fundamental_table;
diff --git a/gjs/context.cpp b/gjs/context.cpp
index 436f2e53..9f0cd78e 100644
--- a/gjs/context.cpp
+++ b/gjs/context.cpp
@@ -18,6 +18,7 @@
#include <atomic>
#include <new>
#include <string> // for u16string
+#include <thread> // for get_id
#include <unordered_map>
#include <utility> // for move
#include <vector>
@@ -483,9 +484,8 @@ gjs_context_constructed(GObject *object)
GjsContextPrivate::GjsContextPrivate(JSContext* cx, GjsContext* public_context)
: m_public_context(public_context),
m_cx(cx),
+ m_owner_thread(std::this_thread::get_id()),
m_environment_preparer(cx) {
- m_owner_thread = g_thread_self();
-
const char *env_profiler = g_getenv("GJS_ENABLE_PROFILER");
if (env_profiler || m_should_listen_sigusr2)
m_should_profile = true;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]