improve the logic of locking in the function
Merge pull request #1419 from sijchen/fix_sm4_mt

[Encoder] improve the logic of locking in the function
Merge remote-tracking branch 'upstream/master' into travis.osx