diff options
Diffstat (limited to 'common/nextpnr.h')
| -rw-r--r-- | common/nextpnr.h | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h index e53e4d01..7aa5b100 100644 --- a/common/nextpnr.h +++ b/common/nextpnr.h @@ -21,6 +21,8 @@ #include <algorithm> #include <assert.h> #include <memory> +#include <mutex> +#include <pthread.h> #include <stdexcept> #include <stdint.h> #include <string> @@ -337,6 +339,11 @@ class DeterministicRNG class BaseCtx : public IdStringDB, public DeterministicRNG { + private: + std::mutex mutex; + bool mutex_owned; + pthread_t mutex_owner; + public: std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets; std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells; @@ -344,6 +351,18 @@ class BaseCtx : public IdStringDB, public DeterministicRNG BaseCtx() {} ~BaseCtx() {} + void lock(void) + { + mutex.lock(); + mutex_owner = pthread_self(); + } + + void unlock(void) + { + NPNR_ASSERT(pthread_equal(pthread_self(), mutex_owner) != 0); + mutex.unlock(); + } + Context *getCtx() { return reinterpret_cast<Context *>(this); } const Context *getCtx() const { return reinterpret_cast<const Context *>(this); } |
