diff options
-rw-r--r-- | CHANGELOG.txt | 5 | ||||
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | dux/CMakeLists.txt | 1 | ||||
-rw-r--r-- | dux/include/dux/base.h | 2 | ||||
-rw-r--r-- | dux/include/dux/c/thrd.h | 2 | ||||
-rw-r--r-- | dux/include/dux/cxx/base.hh | 22 | ||||
-rw-r--r-- | dux/include/dux/cxx/thrd.hh | 4 | ||||
-rw-r--r-- | dux/src/exit.cc | 6 | ||||
-rw-r--r-- | dux/src/ismainthrd.cc | 33 |
9 files changed, 61 insertions, 16 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 28cd085..02ca852 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,3 +1,8 @@ +| 28 + +- Add module dux.ismainthrd; +- Make more compile-time objects be internally-linked; + | 27 - Correct comment in "/dux/src/exit.cc"; diff --git a/CMakeLists.txt b/CMakeLists.txt index 5ee4e15..eb7e85f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ project( # Constants: set( DUX_VERSION - 31.0 + 32.0 ) # Subdirectories diff --git a/dux/CMakeLists.txt b/dux/CMakeLists.txt index f5531b7..6f54c19 100644 --- a/dux/CMakeLists.txt +++ b/dux/CMakeLists.txt @@ -75,6 +75,7 @@ add_library( "src/getmainparam.cc" "src/getnummainparams.cc" "src/gettime.cc" + "src/ismainthrd.cc" "src/mainparams.cc" "src/onexit.cc" "src/raise.cc" diff --git a/dux/include/dux/base.h b/dux/include/dux/base.h index 5c1ac31..47c2f02 100644 --- a/dux/include/dux/base.h +++ b/dux/include/dux/base.h @@ -66,7 +66,7 @@ # endif # endif -# define dux_priv_ver 0x1F +# define dux_priv_ver 0x20 # if !defined(dux_dbg) # if defined(_DEBUG) || !defined(NDEBUG) diff --git a/dux/include/dux/c/thrd.h b/dux/include/dux/c/thrd.h index 86f5c17..415c829 100644 --- a/dux/include/dux/c/thrd.h +++ b/dux/include/dux/c/thrd.h @@ -16,3 +16,5 @@ You should have received a copy of the GNU Affero General Public License along with dux. If not, see <https://www.gnu.org/licenses/>. */ + +dux_attr_useret bool dux_ismainthrd(void); diff --git a/dux/include/dux/cxx/base.hh b/dux/include/dux/cxx/base.hh index 6f2554f..fec8148 100644 --- a/dux/include/dux/cxx/base.hh +++ b/dux/include/dux/cxx/base.hh @@ -18,8 +18,8 @@ */ namespace dux { - constexpr auto dbg {dux_dbg}; - constexpr auto ver {dux_priv_ver}; + constexpr static auto dbg {dux_dbg}; + constexpr static auto ver {dux_priv_ver}; } namespace dux { @@ -65,7 +65,7 @@ namespace dux::priv { template<typename T> struct issame<T,T> {constexpr static auto val {true};}; } namespace dux { - template<typename T,typename T0> constexpr auto issame {::dux::priv::issame<T,T0>::val}; + template<typename T,typename T0> constexpr static auto issame {::dux::priv::issame<T,T0>::val}; } # if defined(dux_lang_cxx23) static_assert(::dux::issame<decltype(0x0uz),::dux::uwrd>); @@ -76,19 +76,19 @@ namespace dux::priv { template<typename T> struct isptrtyp<T *> {constexpr static auto val {true};}; } namespace dux { - template<typename T> constexpr auto isptrtyp {::dux::priv::isptrtyp<T>::val}; + template<typename T> constexpr static auto isptrtyp {::dux::priv::isptrtyp<T>::val}; } namespace dux { - template<typename T> constexpr auto ischrtyp {::dux::issame<T,char> || ::dux::issame<T,char16_t> || ::dux::issame<T,char32_t> || ::dux::issame<T,char8_t> || ::dux::issame<T,wchar_t>}; - template<typename T,typename T0> constexpr auto iscnvto {requires {static_cast<T0>(T {});}}; - template<typename T> constexpr auto isflttyp {::dux::issame<T,double> || ::dux::issame<T,float> || ::dux::issame<T,long double>}; - template<typename T> constexpr auto issinttyp {::dux::issame<T,int> || ::dux::issame<T,long> || ::dux::issame<T,long long> || ::dux::issame<T,short> || ::dux::issame<T,signed char>}; - template<typename T> constexpr auto isuinttyp {::dux::issame<T,unsigned char> || ::dux::issame<T,unsigned int> || ::dux::issame<T,unsigned long> || ::dux::issame<T,unsigned long long> || ::dux::issame<T,unsigned short>}; + template<typename T> constexpr static auto ischrtyp {::dux::issame<T,char> || ::dux::issame<T,char16_t> || ::dux::issame<T,char32_t> || ::dux::issame<T,char8_t> || ::dux::issame<T,wchar_t>}; + template<typename T,typename T0> constexpr static auto iscnvto {requires {static_cast<T0>(T {});}}; + template<typename T> constexpr static auto isflttyp {::dux::issame<T,double> || ::dux::issame<T,float> || ::dux::issame<T,long double>}; + template<typename T> constexpr static auto issinttyp {::dux::issame<T,int> || ::dux::issame<T,long> || ::dux::issame<T,long long> || ::dux::issame<T,short> || ::dux::issame<T,signed char>}; + template<typename T> constexpr static auto isuinttyp {::dux::issame<T,unsigned char> || ::dux::issame<T,unsigned int> || ::dux::issame<T,unsigned long> || ::dux::issame<T,unsigned long long> || ::dux::issame<T,unsigned short>}; - template<typename T> constexpr auto isinttyp {::dux::issinttyp<T> || ::dux::isuinttyp<T>}; + template<typename T> constexpr static auto isinttyp {::dux::issinttyp<T> || ::dux::isuinttyp<T>}; - template<typename T> constexpr auto isarithtyp {::dux::isflttyp<T> || ::dux::isinttyp<T>}; + template<typename T> constexpr static auto isarithtyp {::dux::isflttyp<T> || ::dux::isinttyp<T>}; } namespace dux { diff --git a/dux/include/dux/cxx/thrd.hh b/dux/include/dux/cxx/thrd.hh index 86f5c17..4e3da67 100644 --- a/dux/include/dux/cxx/thrd.hh +++ b/dux/include/dux/cxx/thrd.hh @@ -16,3 +16,7 @@ You should have received a copy of the GNU Affero General Public License along with dux. If not, see <https://www.gnu.org/licenses/>. */ + +namespace dux { + [[nodiscard]] auto ismainthrd() noexcept -> bool; +} diff --git a/dux/src/exit.cc b/dux/src/exit.cc index 785316a..526d3bb 100644 --- a/dux/src/exit.cc +++ b/dux/src/exit.cc @@ -19,6 +19,8 @@ # include <dux/priv> +# include <dux/thrd> + # include <sys/types.h> # if defined(dux_os_freebsd) # include <sys/syscall.h> @@ -27,12 +29,10 @@ # endif auto ::dux::exit(::dux::stat const _stat) noexcept -> void { -# if defined(dux_os_linux) - if (::dux_priv_posix_getpid() != static_cast<::pid_t>(::dux::syscall(__NR_gettid))) [[unlikely]] { /* Check if calling thread is also the main thread. Only thread exit and quick exit are allowed outside the main thread. */ + if (::dux::ismainthrd()) [[unlikely]] { /* Check if the calling thread is also the main thread. Only thread exit and quick exit may be invoked outside the main thread. */ ::dux::dbglog("dux :: \x1B[91mexit\x1B[0m :: Standard exit invoked outside main thread!\n"); ::dux::abrt(); } -# endif ::dux::priv::exitlock.store(true); ::dux::priv::exitstat = _stat; ::std::longjmp(::dux::priv::exitjmp,0x1); diff --git a/dux/src/ismainthrd.cc b/dux/src/ismainthrd.cc new file mode 100644 index 0000000..c5f2cf8 --- /dev/null +++ b/dux/src/ismainthrd.cc @@ -0,0 +1,33 @@ +/* + Copyright 2021, 2022 Gabriel Jensen. + + This file is part of dux. + + dux is free software: you can redistribute it and/or modify it under the + terms of the GNU Affero General Public License as published by the Free + Software Foundation, either version 3 of the License, or (at your + option) any later version. + + dux is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or + FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public + License for more details. + + You should have received a copy of the GNU Affero General Public License + along with dux. If not, see <https://www.gnu.org/licenses/>. +*/ + +# include <dux/priv> + +# include <dux/thrd> + +auto ::dux::ismainthrd() noexcept -> bool { +# if defined(dux_os_linux) + if (::dux_priv_posix_getpid() != static_cast<::pid_t>(::dux::syscall(__NR_gettid))) {return true;} /* Check if calling thread is also the main thread. Only thread exit and quick exit are allowed outside the main thread. */ +# endif + return false; /* I don't know how to check for this on other platforms. */ +} + +# pragma GCC diagnostic ignored "-Wmissing-declarations" + +extern "C" auto dux_ismainthrd() -> bool {return ::dux::ismainthrd();} |