1 #include "accessing.h" 2 3 /* Reserve this mapping and return whether 'fileid' is associated with an 4 accessor. */ 5 6 bool Accessing::reserve(fileid_t fileid) 7 { 8 _lock.lock(); 9 10 return _accessors.find(fileid) != _accessors.end(); 11 } 12 13 /* Return the accessor for 'fileid' and release this mapping. */ 14 15 Accessor *Accessing::get(fileid_t fileid) 16 { 17 FileMapping::iterator entry = _accessors.find(fileid); 18 Accessor *accessor; 19 20 if (entry == _accessors.end()) 21 accessor = NULL; 22 else 23 accessor = entry->second; 24 25 _lock.unlock(); 26 return accessor; 27 } 28 29 /* Associate 'fileid' with the given 'accessor' and release this mapping. */ 30 31 void Accessing::set(fileid_t fileid, Accessor *accessor) 32 { 33 FileMapping::iterator entry = _accessors.find(fileid); 34 35 if (entry == _accessors.end()) 36 _accessors[fileid] = accessor; 37 38 _lock.unlock(); 39 } 40 41 // vim: tabstop=4 expandtab shiftwidth=4