Portable, atomic locking API