From e5e58ebdbce65112f7ca30ba36436df358dd5f93 Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Wed, 17 Nov 2021 02:02:02 +0000 Subject: [PATCH] build: Update CMake to use system threads With the help of Gabriel Ferreira and Tommaso Pecorella. --- build-support/core-config-template.h | 1 - .../custom-modules/ns3-configtable.cmake | 1 - .../custom-modules/ns3-module-macros.cmake | 5 +++- build-support/macros-and-definitions.cmake | 9 ++----- doc/tutorial/source/getting-started.rst | 3 --- src/core/CMakeLists.txt | 26 +++---------------- src/fd-net-device/CMakeLists.txt | 5 ---- test.py | 2 -- 8 files changed, 9 insertions(+), 43 deletions(-) diff --git a/build-support/core-config-template.h b/build-support/core-config-template.h index 15560067d..221486095 100644 --- a/build-support/core-config-template.h +++ b/build-support/core-config-template.h @@ -15,7 +15,6 @@ #cmakedefine01 HAVE_STDLIB_H #cmakedefine01 HAVE_GETENV #cmakedefine01 HAVE_SIGNAL_H -#cmakedefine01 HAVE_PTHREAD_H #cmakedefine HAVE_RT #endif //NS3_CORE_CONFIG_H diff --git a/build-support/custom-modules/ns3-configtable.cmake b/build-support/custom-modules/ns3-configtable.cmake index 40839ed2f..365bc763a 100644 --- a/build-support/custom-modules/ns3-configtable.cmake +++ b/build-support/custom-modules/ns3-configtable.cmake @@ -25,7 +25,6 @@ # Tap Bridge : enabled # Tap FdNetDevice : enabled # Tests : not enabled (defaults to disabled) -# Threading Primitives : enabled # Use sudo to set suid bit : not enabled (option --enable-sudo not selected) # XmlIo : enabled # diff --git a/build-support/custom-modules/ns3-module-macros.cmake b/build-support/custom-modules/ns3-module-macros.cmake index fb9639cdb..8dd9d10a1 100644 --- a/build-support/custom-modules/ns3-module-macros.cmake +++ b/build-support/custom-modules/ns3-module-macros.cmake @@ -110,7 +110,10 @@ function(build_lib) endif() # Split ns and non-ns libraries to manage their propagation properly - set(non_ns_libraries_to_link) + set(non_ns_libraries_to_link + ${CMAKE_THREAD_LIBS_INIT} + ) + set(ns_libraries_to_link) foreach(library ${BLIB_LIBRARIES_TO_LINK}) diff --git a/build-support/macros-and-definitions.cmake b/build-support/macros-and-definitions.cmake index 645cb2c0b..3767cfa6b 100644 --- a/build-support/macros-and-definitions.cmake +++ b/build-support/macros-and-definitions.cmake @@ -688,13 +688,8 @@ macro(process_options) set(THREADS_PREFER_PTHREAD_FLAG) find_package(Threads QUIET) - if(${CMAKE_USE_PTHREADS_INIT}) - include_directories(${THREADS_PTHREADS_INCLUDE_DIR}) - set(HAVE_PTHREAD_H TRUE) # for core-config.h - set(THREADS_ENABLED TRUE) - set(THREADS_FOUND TRUE) - else() - message(FATAL_ERROR Pthreads are required by ns-3) + if(NOT ${Threads_FOUND}) + message(FATAL_ERROR Threads are required by ns-3) endif() set(Python3_LIBRARIES) diff --git a/doc/tutorial/source/getting-started.rst b/doc/tutorial/source/getting-started.rst index 4d37ae66c..c70c6889e 100644 --- a/doc/tutorial/source/getting-started.rst +++ b/doc/tutorial/source/getting-started.rst @@ -563,8 +563,6 @@ output that looks similar to the following: -- Looking for C++ include signal.h - found -- Looking for C++ include netpacket/packet.h -- Looking for C++ include netpacket/packet.h - found - -- Looking for C++ include semaphore.h - -- Looking for C++ include semaphore.h - found -- Looking for getenv -- Looking for getenv - found -- Processing src/antenna @@ -653,7 +651,6 @@ output that looks similar to the following: Tap Bridge : ON Tap FdNetDevice : ON Tests : ON - Threading Primitives : ON Modules configured to be built: diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 966dff903..a96927364 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -120,26 +120,6 @@ elseif( ) endif() -set(thread_sources - model/system-thread.cc - model/unix-fd-reader.cc - model/unix-system-condition.cc - model/unix-system-mutex.cc -) -set(thread_headers - model/system-condition.h - model/system-mutex.h - model/system-thread.h - model/unix-fd-reader.h -) -set(libraries_to_link - ${libraries_to_link} - pthread -) -set(thread_test_sources - test/threaded-test-suite.cc -) - if(${ENABLE_EXAMPLES}) set(example_as_test_sources model/example-as-test.cc @@ -169,7 +149,6 @@ set(source_files ${rt_sources} ${osclock_sources} ${int64x64_sources} - ${thread_sources} ${example_as_test_sources} ${embedded_version_sources} helper/csv-reader.cc @@ -234,13 +213,13 @@ set(source_files model/system-wall-clock-timestamp.cc model/length.cc model/trickle-timer.cc + model/unix-fd-reader.cc ) # Define core lib headers set(header_files ${rt_headers} ${int64x64_headers} - ${thread_headers} ${example_as_test_headers} ${embedded_version_headers} helper/csv-reader.h @@ -334,6 +313,7 @@ set(header_files model/type-name.h model/type-traits.h model/uinteger.h + model/unix-fd-reader.h model/unused.h model/valgrind.h model/vector.h @@ -343,7 +323,6 @@ set(header_files set(test_sources ${example_as_test_suite} ${gsl_test_sources} - ${thread_test_sources} test/attribute-container-test-suite.cc test/attribute-test-suite.cc test/build-profile-test-suite.cc @@ -363,6 +342,7 @@ set(test_sources test/ptr-test-suite.cc test/sample-test-suite.cc test/simulator-test-suite.cc + test/threaded-test-suite.cc test/time-test-suite.cc test/timer-test-suite.cc test/traced-callback-test-suite.cc diff --git a/src/fd-net-device/CMakeLists.txt b/src/fd-net-device/CMakeLists.txt index 7afec7d4d..0982e9f82 100644 --- a/src/fd-net-device/CMakeLists.txt +++ b/src/fd-net-device/CMakeLists.txt @@ -6,11 +6,6 @@ option( set(module_enabled_features) # modulegen_customizations consumes this list -mark_as_advanced(ENABLE_THREADING) -set(ENABLE_THREADING - ${HAVE_PTHREAD_H} -) - check_include_file_cxx( net/ethernet.h HAVE_NET_ETHERNET_H diff --git a/test.py b/test.py index 30a8502f7..ce39ef4d0 100755 --- a/test.py +++ b/test.py @@ -61,7 +61,6 @@ interesting_config_items = [ "NS3_ENABLED_CONTRIBUTED_MODULES", "NS3_MODULE_PATH", "ENABLE_REAL_TIME", - "ENABLE_THREADING", "ENABLE_EXAMPLES", "ENABLE_TESTS", "EXAMPLE_DIRECTORIES", @@ -77,7 +76,6 @@ interesting_config_items = [ ] ENABLE_REAL_TIME = False -ENABLE_THREADING = False ENABLE_EXAMPLES = True ENABLE_TESTS = True NSCLICK = False