From 8e6d68147c478e6864bd29d5029411a82ea7b290 Mon Sep 17 00:00:00 2001 From: Patrick Stewart Date: Mon, 7 Oct 2019 19:23:06 -0400 Subject: [PATCH] Support multithreading on Windows. Signed-off-by: Wilson Snyder --- Changes | 2 ++ include/verilated_threads.h | 6 +++++- include/verilatedos.h | 11 +++++++++-- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Changes b/Changes index c59b23a17..ec6d381d5 100644 --- a/Changes +++ b/Changes @@ -8,6 +8,8 @@ The contributors that suggested a given feature are shown in []. Thanks! *** Add --protect-ids to obscure information in objects, bug1521. [Todd Strader] +*** Support multithreading on Windows. [Patrick Stewart] + **** Increase case duplicate/incomplete to 16 bit tables, bug1545. [Yossi Nivin] diff --git a/include/verilated_threads.h b/include/verilated_threads.h index 355aa5b3f..6bd311e32 100644 --- a/include/verilated_threads.h +++ b/include/verilated_threads.h @@ -25,9 +25,11 @@ #include "verilatedos.h" #include "verilated.h" // for VerilatedMutex and clang annotations -#include // For sched_getcpu() #include #include +#if defined(__linux) +#include // For sched_getcpu() +#endif #if defined(__APPLE__) # include // For __cpuid_count() #endif @@ -211,6 +213,8 @@ public: } else { return (unsigned)info[1] >> 24; } +#elif defined(_WIN32) + return GetCurrentProcessorNumber(); #else return 0; #endif diff --git a/include/verilatedos.h b/include/verilatedos.h index 9410b1b69..5aeac7ee0 100644 --- a/include/verilatedos.h +++ b/include/verilatedos.h @@ -122,7 +122,9 @@ #endif #ifdef VL_THREADED -# ifdef __GNUC__ +# if defined(_MSC_VER) && _MSC_VER >= 1900 +# define VL_THREAD_LOCAL thread_local +# elif defined(__GNUC__) # if (__cplusplus < 201103L) && !defined(VL_THREADED_NO_C11_WARNING) # error "VL_THREADED/--threads support requires C++-11 or newer only; use newer compiler" # endif @@ -390,7 +392,12 @@ typedef unsigned long long vluint64_t; ///< 64-bit unsigned type // Threading related OS-specific functions #if VL_THREADED -# if defined(__i386__) || defined(__x86_64__) +# ifdef _WIN32 +# define WIN32_LEAN_AND_MEAN +# define NOMINMAX +# include "Windows.h" +# define VL_CPU_RELAX() YieldProcessor() +# elif defined(__i386__) || defined(__x86_64__) /// For more efficient busy waiting on SMT CPUs, let the processor know /// we're just waiting so it can let another thread run # define VL_CPU_RELAX() asm volatile("rep; nop" ::: "memory")