Add atomic operations to replace pthread locks