Move pthread yield hack into BaseCtx

This commit is contained in:
Sergiusz Bazanski 2018-07-20 13:15:22 +01:00
parent b84a446eef
commit b4b111a053
3 changed files with 14 additions and 10 deletions

View File

@ -20,6 +20,7 @@
#include <algorithm> #include <algorithm>
#include <assert.h> #include <assert.h>
#include <condition_variable>
#include <memory> #include <memory>
#include <mutex> #include <mutex>
#include <pthread.h> #include <pthread.h>
@ -346,9 +347,10 @@ class BaseCtx : public IdStringDB
{ {
private: private:
std::mutex mutex; std::mutex mutex;
bool mutex_owned;
pthread_t mutex_owner; pthread_t mutex_owner;
std::mutex generation_mutex;
public: public:
std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets; std::unordered_map<IdString, std::unique_ptr<NetInfo>> nets;
std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells; std::unordered_map<IdString, std::unique_ptr<CellInfo>> cells;
@ -360,6 +362,7 @@ class BaseCtx : public IdStringDB
{ {
mutex.lock(); mutex.lock();
mutex_owner = pthread_self(); mutex_owner = pthread_self();
} }
void unlock(void) void unlock(void)
@ -368,6 +371,14 @@ class BaseCtx : public IdStringDB
mutex.unlock(); 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); } Context *getCtx() { return reinterpret_cast<Context *>(this); }
const Context *getCtx() const { return reinterpret_cast<const Context *>(this); } const Context *getCtx() const { return reinterpret_cast<const Context *>(this); }

View File

@ -29,7 +29,6 @@
#include <list> #include <list>
#include <map> #include <map>
#include <ostream> #include <ostream>
#include <pthread.h>
#include <queue> #include <queue>
#include <set> #include <set>
#include <stdarg.h> #include <stdarg.h>
@ -157,14 +156,7 @@ class SAPlacer
// Main simulated annealing loop // Main simulated annealing loop
for (int iter = 1;; iter++) { for (int iter = 1;; iter++) {
// TODO(q3k): unwat ctx->yield();
pthread_yield();
pthread_yield();
pthread_yield();
pthread_yield();
pthread_yield();
pthread_yield();
pthread_yield();
ctx->lock(); ctx->lock();
n_move = n_accept = 0; n_move = n_accept = 0;
improved = false; improved = false;

View File

@ -495,6 +495,7 @@ bool router1(Context *ctx)
#endif #endif
return false; return false;
} }
ctx->yield();
ctx->lock(); ctx->lock();
iterCnt++; iterCnt++;