From ed09f38012131850cd67c1392554653b56a37341 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 26 Dec 2021 09:41:24 -0500 Subject: [libc] remove RT_USING_LIBC --- components/cplusplus/Kconfig | 4 ++-- components/cplusplus/README.md | 2 -- components/cplusplus/cpp11/armclang/thread.cpp | 4 ++-- components/cplusplus/cpp11/gcc/mutex | 4 ++-- components/cplusplus/cpp11/gcc/mutex.cpp | 4 ++-- components/cplusplus/cpp11/gcc/thread | 2 +- components/cplusplus/cpp11/gcc/thread.cpp | 20 ++++++++++---------- 7 files changed, 19 insertions(+), 21 deletions(-) (limited to 'components/cplusplus') diff --git a/components/cplusplus/Kconfig b/components/cplusplus/Kconfig index 42b5cf9556..3d5757fe42 100644 --- a/components/cplusplus/Kconfig +++ b/components/cplusplus/Kconfig @@ -9,8 +9,8 @@ if RT_USING_CPLUSPLUS config RT_USING_CPLUSPLUS11 bool "Enable c++11 threading feature support" default n - select RT_USING_LIBC - select RT_LIBC_USING_FILEIO + select RT_USING_POSIX_FS + select RT_USING_POSIX_DEVIO select RT_USING_PTHREADS select RT_USING_RTC diff --git a/components/cplusplus/README.md b/components/cplusplus/README.md index d02048d1f1..46c8c78a69 100644 --- a/components/cplusplus/README.md +++ b/components/cplusplus/README.md @@ -11,8 +11,6 @@ Because RT-Thread RTOS is used in embedded system mostly, there are some rules f 4. Static class variables are discouraged. The time and place to call their constructor function could not be precisely controlled and make multi-threaded programming a nightmare. 5. Multiple inheritance is strongly discouraged, as it can cause intolerable confusion. -*NOTE*: The libc (RT_USING_LIBC in rtconfig.h) must be enable. - About GNU GCC compiler please add following string in your ld link script: diff --git a/components/cplusplus/cpp11/armclang/thread.cpp b/components/cplusplus/cpp11/armclang/thread.cpp index 6b38d9b3a7..e10ffb9cfe 100644 --- a/components/cplusplus/cpp11/armclang/thread.cpp +++ b/components/cplusplus/cpp11/armclang/thread.cpp @@ -95,8 +95,8 @@ extern "C" unsigned __ARM_TPL_thread_hw_concurrency() extern "C" int __ARM_TPL_tls_create(__ARM_TPL_tls_key *__key, void (*__at_exit)(void *)) { - pthread_key_t key; - + pthread_key_t key; + if (pthread_key_create(&key, __at_exit) == 0) { *__key = key; diff --git a/components/cplusplus/cpp11/gcc/mutex b/components/cplusplus/cpp11/gcc/mutex index cc593cc139..3fdf86632b 100644 --- a/components/cplusplus/cpp11/gcc/mutex +++ b/components/cplusplus/cpp11/gcc/mutex @@ -4,7 +4,7 @@ #error "C++ version lower than C++11" #endif -//#if defined(RT_USING_LIBC) && defined(RT_USING_PTHREADS) +//#if defined(RT_USING_PTHREADS) #include @@ -509,4 +509,4 @@ namespace std } } -//#endif // (RT_USING_LIBC) && (RT_USING_PTHREADS) \ No newline at end of file +//#endif //(RT_USING_PTHREADS) \ No newline at end of file diff --git a/components/cplusplus/cpp11/gcc/mutex.cpp b/components/cplusplus/cpp11/gcc/mutex.cpp index 014460ffde..e11f6d8990 100644 --- a/components/cplusplus/cpp11/gcc/mutex.cpp +++ b/components/cplusplus/cpp11/gcc/mutex.cpp @@ -34,7 +34,7 @@ namespace std get_once_functor_lock_ptr() = m_ptr; } - extern "C" + extern "C" { void once_proxy() { @@ -42,7 +42,7 @@ namespace std function once_call = std::move(once_functor); // no need to hold the lock anymore - unique_lock* lock_ptr = get_once_functor_lock_ptr(); + unique_lock* lock_ptr = get_once_functor_lock_ptr(); get_once_functor_lock_ptr() = nullptr; lock_ptr->unlock(); diff --git a/components/cplusplus/cpp11/gcc/thread b/components/cplusplus/cpp11/gcc/thread index 5b64decd6a..60e3ec964c 100644 --- a/components/cplusplus/cpp11/gcc/thread +++ b/components/cplusplus/cpp11/gcc/thread @@ -4,7 +4,7 @@ #error "C++ version lower than C++11" #endif -//#if defined(RT_USING_LIBC) && defined(RT_USING_PTHREADS) +//#if defined(RT_USING_PTHREADS) #include #include diff --git a/components/cplusplus/cpp11/gcc/thread.cpp b/components/cplusplus/cpp11/gcc/thread.cpp index 947170da25..3979da0dc4 100644 --- a/components/cplusplus/cpp11/gcc/thread.cpp +++ b/components/cplusplus/cpp11/gcc/thread.cpp @@ -35,17 +35,17 @@ namespace std { auto raw_ptr = b.get(); // transfer the ownership of the invoker to the new thread - raw_ptr->this_ptr = std::move(b); + raw_ptr->this_ptr = std::move(b); int err = pthread_create(&_m_thr.__cpp_thread_t, NULL, &execute_native_thread_routine, raw_ptr); - if (err) + if (err) { raw_ptr->this_ptr.reset(); throw_system_error(err, "Failed to create a thread"); } - - } + + } thread::~thread() { @@ -59,12 +59,12 @@ namespace std if (joinable()) err = pthread_join(native_handle(), NULL); - - if (err) + + if (err) { throw_system_error(err, "thread::join failed"); } - + _m_thr = id(); } @@ -78,14 +78,14 @@ namespace std { throw_system_error(err, "thread::detach failed"); } - + _m_thr = id(); } // TODO: not yet actually implemented. // The standard states that the returned value should only be considered a hint. - unsigned thread::hardware_concurrency() noexcept - { + unsigned thread::hardware_concurrency() noexcept + { int __n = _RT_NPROCS; if (__n < 0) __n = 0; -- cgit v1.3.1