Wait for single object portable thread and mutex timeout

Implements missing timeout functionality for non linux systems and fixes return value on timeout.