move withMutexLock to Foreign.hs