Improve semaphore manage.
Signed-off-by: Shanjin Yang <1150660744@qq.com>