Skip to content

Commit f924eda

Browse files
committed
utils/ptp: exit_uv() on socket fail
1 parent 22fbe2b commit f924eda

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/utils/ptp.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "utils/thread.h"
4444
#include "compat/platform_sched.h"
4545
#include "debug.h"
46+
#include "host.h"
4647

4748
#define MOD_NAME "[PTP] "
4849
#define PTP_PORT_EVENT 319
@@ -276,10 +277,15 @@ void Ptp_clock::processPtpPkt(uint8_t *buf, size_t len, uint64_t pkt_ts){
276277

277278
}
278279

279-
void Ptp_clock::wait_for_lock(){
280+
bool Ptp_clock::wait_for_lock(){
280281
std::unique_lock<std::mutex> l(mut);
281282

282-
cv.wait(l, [&]{ return locked; });
283+
using namespace std::chrono_literals;
284+
while(!cv.wait_for(l, 1s, [&]{ return locked; })){
285+
if(!should_run) return false;
286+
}
287+
288+
return true;
283289
}
284290

285291
uint64_t Ptp_clock::get_time(){
@@ -311,6 +317,8 @@ void Ptp_clock::ptp_worker_event(){
311317

312318
if(!ptp_sock){
313319
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Failed to create sock\n");
320+
exit_uv(-1);
321+
should_run = false;
314322
return;
315323
}
316324

@@ -340,6 +348,8 @@ void Ptp_clock::ptp_worker_general(){
340348

341349
if(!ptp_sock){
342350
log_msg(LOG_LEVEL_ERROR, MOD_NAME "Failed to create sock\n");
351+
exit_uv(-1);
352+
should_run = false;
343353
return;
344354
}
345355

src/utils/ptp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ class Ptp_clock{
107107
uint64_t get_time();
108108

109109
const char* get_clock_id_str();
110-
void wait_for_lock();
110+
bool wait_for_lock();
111111
[[nodiscard]] bool is_locked() const;
112112

113113
private:

0 commit comments

Comments
 (0)