From b60b38d241807003fd18952469db660e4b0989dc Mon Sep 17 00:00:00 2001 From: limeng151 Date: Sat, 3 Jul 2021 18:06:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9semaphore=E9=87=8C=E5=A4=B1?= =?UTF-8?q?=E8=B4=A5=E7=9A=84=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: limeng151 Change-Id: Iadc09d627e87652a59334aed98ed9e6f8bc42cdf --- kernel_lite/ipc_posix/semaphore/SemTest.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/kernel_lite/ipc_posix/semaphore/SemTest.cpp b/kernel_lite/ipc_posix/semaphore/SemTest.cpp index 11cac3cf2..91883c39f 100755 --- a/kernel_lite/ipc_posix/semaphore/SemTest.cpp +++ b/kernel_lite/ipc_posix/semaphore/SemTest.cpp @@ -224,6 +224,7 @@ void *ThreadSemTryWait(void *arg) for (int i = 0; i < loop; i++) { if (sem_trywait(sem) == 0) { break; + } Msleep(10); } @@ -254,11 +255,9 @@ HWTEST_F(SemTest, testThreadSemTryWait, Function | MediumTest | Level3) EXPECT_EQ(sem_post(&sem), 0) << "sem_post errno = " << errno; EXPECT_EQ(sem_post(&sem), 0) << "sem_post errno = " << errno; - Msleep(20); + reInt = pthread_join(tid, nullptr); EXPECT_EQ(sem_getvalue(&sem, &semValue), 0) << "> sem_getvalue errno = " << errno; EXPECT_EQ(semValue, 1); - - reInt = pthread_join(tid, nullptr); EXPECT_EQ(reInt, 0) << "pthread_join failed, errno=" << reInt; EXPECT_EQ(sem_destroy(&sem), 0) << "> sem_destroy errno = " << errno; } @@ -275,10 +274,11 @@ void *ThreadSemTimedWait(void *arg) clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec = ts.tv_sec + (ts.tv_nsec + KERNEL_100MS_BY_NS) / KERNEL_NS_PER_SECOND; ts.tv_nsec = (ts.tv_nsec + KERNEL_100MS_BY_NS) % KERNEL_NS_PER_SECOND; - + Msleep(50); EXPECT_EQ(sem_timedwait(sem, &ts), 0) << "sem_timedwait errno = " << errno; - EXPECT_EQ(sem_getvalue(sem, &semValue), 0) << "sem_getvalue errno = " << errno; + + Msleep(100); EXPECT_EQ(semValue, 1); return nullptr; } @@ -306,11 +306,9 @@ HWTEST_F(SemTest, testThreadSemTimedWait, Function | MediumTest | Level3) EXPECT_EQ(sem_post(&sem), 0) << "> sem_post errno = " << errno; EXPECT_EQ(sem_post(&sem), 0) << "> sem_post errno = " << errno; - Msleep(100); + reInt = pthread_join(tid, nullptr); EXPECT_EQ(sem_getvalue(&sem, &semValue), 0) << "> sem_getvalue errno = " << errno; EXPECT_EQ(semValue, 1); - - reInt = pthread_join(tid, nullptr); EXPECT_EQ(reInt, 0) << "pthread_join failed, errno=" << reInt; EXPECT_EQ(sem_destroy(&sem), 0) << "> sem_destroy errno = " << errno; } -- GitLab