cloud-sat/workers/sharer.hpp

50 lines
1.3 KiB
C++
Raw Normal View History

2022-09-08 13:54:29 +08:00
#ifndef _sharer_hpp_INCLUDED
#define _sharer_hpp_INCLUDED
#include "../utils/paras.hpp"
2022-12-04 23:30:36 +08:00
#include <boost/thread.hpp>
2022-09-08 13:54:29 +08:00
class basesolver;
class sharer {
public:
int id;
2023-02-24 07:58:40 +00:00
int share_intv, share_lits, dps;
2022-12-04 23:30:36 +08:00
mutable boost::mutex mtx;
boost::condition_variable cond;
int terminated;
int waitings;
2022-09-08 13:54:29 +08:00
vec<vec<clause_store *>> bucket[32]; //need to update
2022-12-04 23:30:36 +08:00
2022-09-08 13:54:29 +08:00
vec<basesolver *> producers, consumers;
vec<clause_store *> cls;
2023-02-24 07:58:40 +00:00
sharer(int idx, int intv, int lits, int share_dps = 0) {
2022-09-08 13:54:29 +08:00
share_intv = intv;
share_lits = lits;
2023-02-24 07:58:40 +00:00
dps = share_dps;
2022-09-08 13:54:29 +08:00
id = idx;
2022-12-04 23:30:36 +08:00
waitings = terminated = 0;
}
void set_terminated() {
boost::mutex::scoped_lock lock(mtx);
terminated = 1;
cond.notify_one();
}
bool should_sharing() const {
boost::mutex::scoped_lock lock(mtx);
return waitings == producers.size();
}
void waiting_for_all_ready() {
boost::mutex::scoped_lock lock(mtx);
while (waitings != producers.size() && !terminated) {
cond.wait(lock);
}
}
void sharing_finish() {
boost::mutex::scoped_lock lock(mtx);
waitings = 0;
// printf("c sharing thread finish sharing\n");
cond.notify_all();
2022-09-08 13:54:29 +08:00
}
int sort_clauses(int x);
};
#endif