swrap: Add error check around pthread mutex locks