Skip to content

Commit fa6fcde

Browse files
author
flw5469
committed
update
1 parent dc83b76 commit fa6fcde

File tree

2 files changed

+31
-31
lines changed

2 files changed

+31
-31
lines changed

src/internal_modules/roc_core/target_posix_ext/roc_core/semaphore.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
#include "roc_core/semaphore.h"
1010
#include "roc_core/cpu_instructions.h"
1111
#include "roc_core/errno_to_str.h"
12-
#include "roc_core/panic.h"
1312
#include "roc_core/log.h"
13+
#include "roc_core/panic.h"
1414

1515
#include <errno.h>
1616
#include <time.h>
@@ -41,30 +41,31 @@ bool Semaphore::timed_wait(nanoseconds_t deadline) {
4141

4242
nanoseconds_t converted_deadline = deadline;
4343

44-
// convert deadline's domain into CLOCK_REALTIME if sem_clockwait is not available
45-
#ifndef ROC_HAVE_SEM_CLOCKWAIT
46-
converted_deadline += (core::timestamp(core::ClockUnix)-core::timestamp(core::ClockMonotonic));
47-
#endif
44+
// convert deadline's domain into CLOCK_REALTIME if sem_clockwait is not available
45+
#ifndef ROC_HAVE_SEM_CLOCKWAIT
46+
converted_deadline +=
47+
(core::timestamp(core::ClockUnix) - core::timestamp(core::ClockMonotonic));
48+
#endif
4849

49-
roc_log(roc::LogDebug,"origin time is %" PRId64"\n", deadline);
50-
roc_log(roc::LogDebug,"time is %" PRId64"\n", converted_deadline);
51-
roc_log(roc::LogDebug,"now time is %" PRId64"\n", core::timestamp(core::ClockMonotonic));
50+
roc_log(roc::LogDebug, "origin time is %" PRId64 "\n", deadline);
51+
roc_log(roc::LogDebug, "time is %" PRId64 "\n", converted_deadline);
52+
roc_log(roc::LogDebug, "now time is %" PRId64 "\n",
53+
core::timestamp(core::ClockMonotonic));
5254

5355
timespec ts;
5456
ts.tv_sec = long(converted_deadline / Second);
5557
ts.tv_nsec = long(converted_deadline % Second);
56-
57-
for (;;) {
5858

59-
#ifdef ROC_HAVE_SEM_CLOCKWAIT
60-
if (sem_clockwait(&sem_, CLOCK_MONOTONIC , &ts) == 0) {
59+
for (;;) {
60+
#ifdef ROC_HAVE_SEM_CLOCKWAIT
61+
if (sem_clockwait(&sem_, CLOCK_MONOTONIC, &ts) == 0) {
6162
return true;
6263
}
63-
#else
64+
#else
6465
if (sem_timedwait(&sem_, &ts) == 0) {
65-
return true;
66+
return true;
6667
}
67-
#endif
68+
#endif
6869

6970
if (errno == ETIMEDOUT) {
7071
return false;

src/tests/roc_pipeline/test_state_tracker.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@
1414
#include "roc_core/atomic.h"
1515
#include "roc_core/heap_arena.h"
1616
#include "roc_core/noop_arena.h"
17+
#include "roc_core/semaphore.h"
1718
#include "roc_core/thread.h"
1819
#include "roc_core/time.h"
1920
#include "roc_pipeline/config.h"
2021
#include "roc_pipeline/receiver_endpoint.h"
2122
#include "roc_pipeline/receiver_session_group.h"
22-
#include "roc_core/semaphore.h"
2323

2424
namespace roc {
2525
namespace pipeline {
@@ -88,31 +88,30 @@ TEST(state_tracker, multiple_timeout) {
8888
StateTracker state_tracker;
8989
TestThread** threads_ptr = new TestThread*[10];
9090

91-
//set threads that last for 1 second
91+
// set threads that last for 1 second
9292
for (int i = 0; i < 10; i++) {
93-
threads_ptr[i] =
94-
new TestThread(state_tracker, sndio::DeviceState_Active,
95-
core::timestamp(core::ClockMonotonic) + core::Millisecond * 1000);
93+
threads_ptr[i] = new TestThread(state_tracker, sndio::DeviceState_Active,
94+
core::timestamp(core::ClockMonotonic)
95+
+ core::Millisecond * 1000);
9696
}
9797

98-
//wait for start, then check if threads are running
98+
// wait for start, then check if threads are running
9999
for (int i = 0; i < 10; i++) {
100100
CHECK(threads_ptr[i]->start());
101101
// CHECK(threads_ptr[i]->running());
102102
// roc_log(LogDebug, "check running %d\n", i);
103-
104103
}
105104
core::sleep_for(core::ClockMonotonic, core::Millisecond * 10);
106105
for (int i = 0; i < 10; i++) {
107-
//roc_log(LogDebug, "check running %d\n", i);
108-
CHECK(threads_ptr[i]->running());
106+
// roc_log(LogDebug, "check running %d\n", i);
107+
CHECK(threads_ptr[i]->running());
109108
}
110109

111-
//sleep for 2 seconds, making the threads timeout
110+
// sleep for 2 seconds, making the threads timeout
112111
roc_log(LogDebug, "started running");
113112
core::sleep_for(core::ClockMonotonic, core::Millisecond * 2000);
114113

115-
//check if threads are stopped
114+
// check if threads are stopped
116115
for (int i = 0; i < 10; i++) {
117116
CHECK(!threads_ptr[i]->running());
118117
}
@@ -130,7 +129,7 @@ TEST(state_tracker, multiple_switch) {
130129
StateTracker state_tracker;
131130
TestThread** threads_ptr = new TestThread*[10];
132131

133-
//set threads without waiting time
132+
// set threads without waiting time
134133
for (int i = 0; i < 10; i++) {
135134
threads_ptr[i] = new TestThread(state_tracker, sndio::DeviceState_Active, -1);
136135
}
@@ -141,20 +140,20 @@ TEST(state_tracker, multiple_switch) {
141140

142141
roc_log(LogDebug, "started running");
143142

144-
//wait for threads starting
143+
// wait for threads starting
145144
core::sleep_for(core::ClockMonotonic, core::Millisecond * 500);
146145

147-
//check if the threads have started
146+
// check if the threads have started
148147
for (int i = 0; i < 10; i++) {
149148
CHECK(threads_ptr[i]->running());
150149
}
151150

152-
//register a packet
151+
// register a packet
153152
core::sleep_for(core::ClockMonotonic, core::Millisecond * 500);
154153
state_tracker.register_packet();
155154
core::sleep_for(core::ClockMonotonic, core::Millisecond * 500);
156155

157-
//check if the threads have been stopped
156+
// check if the threads have been stopped
158157
for (int i = 0; i < 10; i++) {
159158
CHECK(!(threads_ptr[i]->running()));
160159
}

0 commit comments

Comments
 (0)