Added locking to the memory driver (untested).
Integrated locking in drv mem.