buffer: only acquire buffer lock if the buffer is shared

The file backend sets shared at construction and never
changes it, so guarding it is unnecessary.
buffer: remove unused static function
iterator: new state machine iterator