sip_transaction: race condition on terminate

Fixed a race condition in the pjsip_tsx_terminate function that allowed the
state to potentially be set to terminated twice that subsequently ended in
a crash.