Introduces multithreading support to dev mode of generated media

Request for review:  This adds multithreading support to mediagenerator, fixing 404s that occur when running the server in dev mode.  By introducing a read-write lock on the mappings dictionary, this change prevents re-entrancy nonsense that can give you inconsistent mapping.

This uses a read-write lock implementation from Mateusz Kobos.

Warning, this change may be overly cautious in locking utils and middleware, to an extent.