Implemented all re-entrant lock functionality in one place