Remove lock around ref count check in terminate.

Replace the global lock in terminate for the ref count check with atomics and a
local lock.

Bug: 19072064

Change-Id: I0cfd6564e227a75b8387a8788b16381d5bc2cc88
2 files changed