fixed two stupid bugs: ifndef != ifdef and paying too little attention to never locking a mutex twice