Improve initial V8 fix

Further changes were made to fix the build issue on OSes without a
gettid syscall:
- https://codereview.chromium.org/649553002
- https://codereview.chromium.org/642223003

These changes improve the original fix and specifically return a correct
thread id on SmartOS.

Commits will be squashed and PR will be updated when tests are done
running from Jenkins on all supported platforms.