ImageEngine/cortex — pull request #267 by ldmoser (2014-05-09 23:08:08+00:00)
Title: Using mutex on all access to the internal directory nodes in StreamIndexedIO

The previous change introduced a bug where a multi-threaded access to the hierarchy could cause access to deleted SubIndexNode instances. We haven't been able to isolate the bug with a simple test.

The solution was to use mutex before accessing the children of any DirectoryNode and for that I've added a function that returns a scoped_lock with the required access (read/write) only the directory actually requires locking (in case it has one or more SubIndexNode as child).
Instead of using one single mutex for all locations in the file, I've created a pool of mutexes that are chosen deterministically for the DirectoryNode to be accessed, in the attempt to avoid blocking threads too much.