GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: Alviro Iskandar Setiawan <[email protected]>
To: Ammar Faizi <[email protected]>
Cc: Alviro Iskandar Setiawan <[email protected]>,
	Irvan Malik Azantha <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
Subject: [RFC PATCH v1 3/3] configure: Introduce `--cpp-thread` option
Date: Sat, 11 Mar 2023 11:28:10 +0000	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

Allow user to force use C++ thread instead of pthread on Linux. It
also allows us to debug the C++ implementation on Linux.

Signed-off-by: Alviro Iskandar Setiawan <[email protected]>
---
 configure           | 8 ++++++++
 core/thread.cc      | 2 +-
 include/gw/thread.h | 2 +-
 3 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 887b0b2..2f93056 100755
--- a/configure
+++ b/configure
@@ -40,6 +40,9 @@ for opt do
 	--sanitize)
 		use_sanitize="yes";
 	;;
+	--cpp-thread)
+		use_cpp_thread="yes";
+	;;
 	*)
 		echo "ERROR: unknown option $opt";
 		echo "Try '$0 --help' for more information";
@@ -60,6 +63,7 @@ Options: [defaults in brackets after descriptions]
   --cxx=CMD                Use CMD as the C++ compiler
   --debug                  Build with debug enabled
   --sanitize               Build with sanitize enabled
+  --cpp-thread             Force to use C++ thread implementation
 EOF
 exit 0;
 fi
@@ -308,6 +312,10 @@ if test "${use_sanitize}" = "yes"; then
 	LDFLAGS="${LDFLAGS} -fsanitize=address -fsanitize=undefined";
 fi;
 
+if test "${use_cpp_thread}" = "yes"; then
+	add_config "CONFIG_CPP_THREAD";
+fi;
+
 add_config "CONFIG_MODULE_PING";
 
 add_make_var "CC" "${cc}";
diff --git a/core/thread.cc b/core/thread.cc
index 54e06e7..50cc8ed 100644
--- a/core/thread.cc
+++ b/core/thread.cc
@@ -15,7 +15,7 @@
 extern "C" {
 #endif
 
-#if defined(__linux__)
+#if !defined(CONFIG_CPP_THREAD)
 
 int thread_create(thread_t *ts_p, void *(*func)(void *), void *arg)
 {
diff --git a/include/gw/thread.h b/include/gw/thread.h
index 68a0ee7..f383bd2 100644
--- a/include/gw/thread.h
+++ b/include/gw/thread.h
@@ -10,7 +10,7 @@
 extern "C" {
 #endif
 
-#if defined(__linux__)
+#if !defined(CONFIG_CPP_THREAD)
 #include <pthread.h>
 typedef pthread_t thread_t;
 typedef pthread_mutex_t mutex_t;
-- 
Alviro Iskandar Setiawan


  parent reply	other threads:[~2023-03-11 11:28 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-11 11:28 [RFC PATCH v1 0/3] Fix undefined behavior in the C++ mutex implementation Alviro Iskandar Setiawan
2023-03-11 11:28 ` [RFC PATCH v1 1/3] MAINTAINERS: Add myself as the thread maintainer Alviro Iskandar Setiawan
2023-03-11 11:28 ` [RFC PATCH v1 2/3] core/thread: Fix undefined behavior in the C++ mutex implementation Alviro Iskandar Setiawan
2023-03-11 11:28 ` Alviro Iskandar Setiawan [this message]
2023-03-12 19:40 ` [RFC PATCH v1 0/3] " Ammar Faizi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230311112810.3670483-4-alviro.iskandar@gnuweeb.org \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox