1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/accessing.cc Sun Jan 24 19:29:07 2021 +0100
1.3 @@ -0,0 +1,41 @@
1.4 +#include "accessing.h"
1.5 +
1.6 +/* Reserve this mapping and return whether 'fileid' is associated with an
1.7 + accessor. */
1.8 +
1.9 +bool Accessing::reserve(fileid_t fileid)
1.10 +{
1.11 + _lock.lock();
1.12 +
1.13 + return _accessors.find(fileid) != _accessors.end();
1.14 +}
1.15 +
1.16 +/* Return the accessor for 'fileid' and release this mapping. */
1.17 +
1.18 +Accessor *Accessing::get(fileid_t fileid)
1.19 +{
1.20 + FileMapping::iterator entry = _accessors.find(fileid);
1.21 + Accessor *accessor;
1.22 +
1.23 + if (entry == _accessors.end())
1.24 + accessor = NULL;
1.25 + else
1.26 + accessor = entry->second;
1.27 +
1.28 + _lock.unlock();
1.29 + return accessor;
1.30 +}
1.31 +
1.32 +/* Associate 'fileid' with the given 'accessor' and release this mapping. */
1.33 +
1.34 +void Accessing::set(fileid_t fileid, Accessor *accessor)
1.35 +{
1.36 + FileMapping::iterator entry = _accessors.find(fileid);
1.37 +
1.38 + if (entry == _accessors.end())
1.39 + _accessors[fileid] = accessor;
1.40 +
1.41 + _lock.unlock();
1.42 +}
1.43 +
1.44 +// vim: tabstop=4 expandtab shiftwidth=4