Commit 2f24a37d authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 43c43472
......@@ -49,13 +49,22 @@ using namespace golang;
template<typename Key, typename Value>
using dict = std::unordered_map<Key, Value>;
struct dict : std::unordered_map<Key, Value> {
// has returns whether container d (e.g. dict) has element k.
bool has(const Key &k) const {
const dict *d = this;
return d->find(k) != d.end();
}
// has returns whether container d (e.g. dict) has element k.
template<typename Container, typename Key>
bool has(const Container &d, Key k) {
return d.find(k) != d.end();
}
// get implements `d[k] -> (v, ok)`.
tuple<Value, bool> get(const Key &k) const {
const dict *d = this;
auto _ = d->find(k);
if (_ == d->end())
return make_tuple(Value(), false);
return make_tuple(_.second(), true);
}
};
template<typename Key>
using set = std::unordered_set<Key>;
......@@ -262,13 +271,17 @@ void Conn::_pin1(SrvReq *req) {
// XXX defer: reply either ack or nak on error
// XXX return error?
_File *f;
bool ok;
wconn->_filemu.lock();
if (has(wconn->_filetab, req->foid)) {
tie(f, ok) = wconn->_filetab.get(req->foid);
//if (has(wconn->_filetab, req->foid)) {
if (!ok) {
wconn->_filemu.unlock();
// XXX err = we are not watching the file - why wcfs sent us this update?
}
_File *f = _->second;
//_File *f = _->second;
// XXX relock wconn -> f
......@@ -372,7 +385,7 @@ tuple<WatchLink*, error> WCFS::_openwatch() {
wlink->_wc = wc;
wlink->_f = f;
wlink->_rx_eof = makechan<structZ>();
wlink->_acceptq = makechan<XXX>();
wlink->_acceptq = makechan<rxPkt>();
wlink->_req_next = 1;
wlink->_txclosed = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment