Support multithreading on Windows.

Signed-off-by: Wilson Snyder <wsnyder@wsnyder.org>
This commit is contained in:
Patrick Stewart 2019-10-07 19:23:06 -04:00 committed by Wilson Snyder
parent e08b9b84b5
commit 8e6d68147c
3 changed files with 16 additions and 3 deletions

View File

@ -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]

View File

@ -25,9 +25,11 @@
#include "verilatedos.h"
#include "verilated.h" // for VerilatedMutex and clang annotations
#include <sched.h> // For sched_getcpu()
#include <set>
#include <vector>
#if defined(__linux)
#include <sched.h> // For sched_getcpu()
#endif
#if defined(__APPLE__)
# include <cpuid.h> // For __cpuid_count()
#endif
@ -211,6 +213,8 @@ public:
} else {
return (unsigned)info[1] >> 24;
}
#elif defined(_WIN32)
return GetCurrentProcessorNumber();
#else
return 0;
#endif

View File

@ -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")