Made locking code portable

Rewrote the Lock class to work under both Linux, MacOS, and Windows by
replacing the usage of fcntl with msvcrt on the Windows platform.