runtime: don't use runtime_lock in __go_get_backtrace_state
runtime: don't use runtime_lock in __go_get_backtrace_state

If getSiginfo does not know how to determine the PC, it will call
runtime_callers. That can happen in a thread that was started by
non-Go code, in which case the TLS variable g will not be set, in
which case runtime_lock will crash.

Avoid the problem by using atomic operations for the lock. This is OK
since creating a backtrace state is fast and never blocks.

The test case is TestCgoExternalThreadSIGPROF in the runtime package
on a system that getSiginfo doesn't handle specially.

Updates golang/go#20931

Change-Id: I6007c520e40ba2f00feabf404a7cce7df57fbcef
Reviewed-on: https://go-review.googlesource.com/50650
Reviewed-by: Than McIntosh <4b2922593166fc595a9b1a408f34f5d3817fe9d2@google.com>

golang/gofrontend,golang/gofrontend,golang/gofrontend,golang/gofrontend