aboutsummaryrefslogtreecommitdiffstats
path: root/common/nextpnr.h
diff options
context:
space:
mode:
authorwhitequark <whitequark@whitequark.org>2020-05-23 19:50:09 +0000
committerwhitequark <whitequark@whitequark.org>2020-05-23 20:57:26 +0000
commite7bb04769d5d7262d3ecfd0de49953078174a880 (patch)
tree20100cd95832d9da3dcebcdb263ba5b05482ffe2 /common/nextpnr.h
parent2692c6f6cce41d22847058c85715e8822feb9b87 (diff)
downloadnextpnr-e7bb04769d5d7262d3ecfd0de49953078174a880.tar.gz
nextpnr-e7bb04769d5d7262d3ecfd0de49953078174a880.tar.bz2
nextpnr-e7bb04769d5d7262d3ecfd0de49953078174a880.zip
Port nextpnr-{ice40,ecp5} to WASI.
This involves very few changes, all typical to WASM ports: * WASM doesn't currently support threads or atomics so those are disabled. * WASM doesn't currently support exceptions so the exception machinery is stubbed out. * WASM doesn't (and can't) have mmap(), so an emulation library is used. That library currently doesn't support MAP_SHARED flags, so MAP_PRIVATE is used instead. There is also an update to bring ECP5 bbasm CMake rules to parity with iCE40 ones, since although it is possible to embed chipdb into nextpnr on WASM, a 200 MB WASM file has very few practical uses. The README is not updated and there is no included toolchain file because at the moment it's not possible to build nextpnr with upstream boost and wasi-libc. Boost requires a patch (merged, will be available in boost 1.74.0), wasi-libc requires a few unmerged patches.
Diffstat (limited to 'common/nextpnr.h')
-rw-r--r--common/nextpnr.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h
index 66bba997..4d481d06 100644
--- a/common/nextpnr.h
+++ b/common/nextpnr.h
@@ -33,7 +33,9 @@
#include <boost/functional/hash.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/range/adaptor/reversed.hpp>
+#ifndef NPNR_DISABLE_THREADS
#include <boost/thread.hpp>
+#endif
#ifndef NEXTPNR_H
#define NEXTPNR_H
@@ -647,6 +649,7 @@ struct DeterministicRNG
struct BaseCtx
{
+#ifndef NPNR_DISABLE_THREADS
// Lock to perform mutating actions on the Context.
std::mutex mutex;
boost::thread::id mutex_owner;
@@ -655,6 +658,7 @@ struct BaseCtx
// method will lock/unlock it when its' released the main mutex to make
// sure the UI is not starved.
std::mutex ui_mutex;
+#endif
// ID String database.
mutable std::unordered_map<std::string, int> *idstring_str_to_idx;
@@ -706,28 +710,36 @@ struct BaseCtx
// Must be called before performing any mutating changes on the Ctx/Arch.
void lock(void)
{
+#ifndef NPNR_DISABLE_THREADS
mutex.lock();
mutex_owner = boost::this_thread::get_id();
+#endif
}
void unlock(void)
{
+#ifndef NPNR_DISABLE_THREADS
NPNR_ASSERT(boost::this_thread::get_id() == mutex_owner);
mutex.unlock();
+#endif
}
// Must be called by the UI before rendering data. This lock will be
// prioritized when processing code calls yield().
void lock_ui(void)
{
+#ifndef NPNR_DISABLE_THREADS
ui_mutex.lock();
mutex.lock();
+#endif
}
void unlock_ui(void)
{
+#ifndef NPNR_DISABLE_THREADS
mutex.unlock();
ui_mutex.unlock();
+#endif
}
// Yield to UI by unlocking the main mutex, flashing the UI mutex and
@@ -737,10 +749,12 @@ struct BaseCtx
// Must be called with the main lock taken.
void yield(void)
{
+#ifndef NPNR_DISABLE_THREADS
unlock();
ui_mutex.lock();
ui_mutex.unlock();
lock();
+#endif
}
IdString id(const std::string &s) const { return IdString(this, s); }