]> sourceware.org Git - systemtap.git/commitdiff
Use std::thread for threading and CPU counts
authorJosh Stone <jistone@redhat.com>
Tue, 3 May 2016 22:03:33 +0000 (15:03 -0700)
committerJosh Stone <jistone@redhat.com>
Tue, 3 May 2016 22:03:33 +0000 (15:03 -0700)
buildrun.cxx
main.cxx
session.cxx
stap-serverd.cxx

index b541b45ef4af69d333625b08a843ebdc4b098618..0656e70a05ded138a6c7dc820369e90336ee8eaa 100644 (file)
@@ -16,6 +16,7 @@
 #include <cstdlib>
 #include <fstream>
 #include <sstream>
+#include <thread>
 
 extern "C" {
 #include <signal.h>
@@ -64,7 +65,7 @@ run_make_cmd(systemtap_session& s, vector<string>& make_cmd,
     }
 
   // Exploit SMP parallelism, if available.
-  long smp = sysconf(_SC_NPROCESSORS_ONLN);
+  long smp = thread::hardware_concurrency();
   if (smp <= 0) smp = 1;
   // PR16276: but only if we're not running severely nproc-rlimited
   struct rlimit rlim;
index 4e81097d04c16568ab6d296abded919486988863..9c22f8633689c0d44e022b4783fba1f72b9d6859 100644 (file)
--- a/main.cxx
+++ b/main.cxx
@@ -37,6 +37,7 @@
 #include "stap-probe.h"
 
 #include <cstdlib>
+#include <thread>
 
 extern "C" {
 #include <glob.h>
@@ -303,15 +304,13 @@ setup_signals (sighandler_t handler)
 }
 
 
-static void*
-sdt_benchmark_thread(void* p)
+static void
+sdt_benchmark_thread(unsigned long i)
 {
-  unsigned long i = *(unsigned long*)p;
   PROBE(stap, benchmark__thread__start);
   while (i--)
     PROBE1(stap, benchmark, i);
   PROBE(stap, benchmark__thread__end);
-  return NULL;
 }
 
 
@@ -332,13 +331,13 @@ run_sdt_benchmark(systemtap_session& s)
   gettimeofday (&tv_before, NULL);
 
   PROBE(stap, benchmark__start);
-
-  pthread_t pthreads[threads];
-  for (unsigned long i = 0; i < threads; ++i)
-    pthread_create(&pthreads[i], NULL, sdt_benchmark_thread, &loops);
-  for (unsigned long i = 0; i < threads; ++i)
-    pthread_join(pthreads[i], NULL);
-
+    {
+      vector<thread> handles;
+      for (unsigned long i = 0; i < threads; ++i)
+        handles.push_back(thread(sdt_benchmark_thread, loops));
+      for (unsigned long i = 0; i < threads; ++i)
+        handles[i].join();
+    }
   PROBE(stap, benchmark__end);
 
   times (& tms_after);
index f83641b0044e2e63fa84307aa89e78881add9994..0f8d6c73951eec3674b18fb1d9eb4d27c3e1d7b1 100644 (file)
@@ -28,6 +28,7 @@
 
 #include <cerrno>
 #include <cstdlib>
+#include <thread>
 
 extern "C" {
 #include <getopt.h>
@@ -1414,7 +1415,7 @@ systemtap_session::parse_cmdline (int argc, char * const argv [])
 
         case LONG_OPT_BENCHMARK_SDT:
           // XXX This option is secret, not supported, subject to change at our whim
-          benchmark_sdt_threads = sysconf(_SC_NPROCESSORS_ONLN);
+          benchmark_sdt_threads = thread::hardware_concurrency();
           break;
 
         case LONG_OPT_BENCHMARK_SDT_LOOPS:
index f0f36d12c13a25c61c77e513a5e3e5d5d8a48bcc..f379f9e4892435456a038ac715dc1b52f357c8db 100644 (file)
@@ -27,6 +27,7 @@
 #include <climits>
 #include <iostream>
 #include <map>
+#include <thread>
 
 extern "C" {
 #include <unistd.h>
@@ -985,7 +986,7 @@ initialize (int argc, char **argv) {
   // Initial values.
   use_db_password = false;
   port = 0;
-  max_threads = sysconf( _SC_NPROCESSORS_ONLN ); // Default to number of processors
+  max_threads = thread::hardware_concurrency(); // Default to number of processors
   max_uncompressed_req_size = 50000; // 50 KB: default max uncompressed request size
   max_compressed_req_size = 5000; // 5 KB: default max compressed request size
   keep_temp = false;
This page took 0.041199 seconds and 5 git commands to generate.