aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/nextpnr.h13
-rw-r--r--common/placer1.cc10
-rw-r--r--common/router1.cc1
3 files changed, 14 insertions, 10 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h
index 1f75434d..e9cda565 100644
--- a/common/nextpnr.h
+++ b/common/nextpnr.h
@@ -20,6 +20,7 @@
#include <algorithm>
#include <assert.h>
+#include <condition_variable>
#include <memory>
#include <mutex>
#include <pthread.h>
@@ -346,8 +347,9 @@ class BaseCtx : public IdStringDB
{
private:
std::mutex mutex;
- bool mutex_owned;
pthread_t mutex_owner;
+
+ std::mutex generation_mutex;
public:
std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets;
@@ -360,6 +362,7 @@ class BaseCtx : public IdStringDB
{
mutex.lock();
mutex_owner = pthread_self();
+
}
void unlock(void)
@@ -368,6 +371,14 @@ class BaseCtx : public IdStringDB
mutex.unlock();
}
+ // TODO(q3k): get rid of this hack
+ void yield(void)
+ {
+ for (int i = 0; i < 10; i++) {
+ pthread_yield();
+ }
+ }
+
Context *getCtx() { return reinterpret_cast<Context *>(this); }
const Context *getCtx() const { return reinterpret_cast<const Context *>(this); }
diff --git a/common/placer1.cc b/common/placer1.cc
index b58893ce..c8ba71a4 100644
--- a/common/placer1.cc
+++ b/common/placer1.cc
@@ -29,7 +29,6 @@
#include <list>
#include <map>
#include <ostream>
-#include <pthread.h>
#include <queue>
#include <set>
#include <stdarg.h>
@@ -157,14 +156,7 @@ class SAPlacer
// Main simulated annealing loop
for (int iter = 1;; iter++) {
- // TODO(q3k): unwat
- pthread_yield();
- pthread_yield();
- pthread_yield();
- pthread_yield();
- pthread_yield();
- pthread_yield();
- pthread_yield();
+ ctx->yield();
ctx->lock();
n_move = n_accept = 0;
improved = false;
diff --git a/common/router1.cc b/common/router1.cc
index bde3be31..3a0aa19b 100644
--- a/common/router1.cc
+++ b/common/router1.cc
@@ -495,6 +495,7 @@ bool router1(Context *ctx)
#endif
return false;
}
+ ctx->yield();
ctx->lock();
iterCnt++;