@@ -303,6 +303,7 @@ SonicPiAPI::~SonicPiAPI()
303
303
void SonicPiAPI::Shutdown ()
304
304
{
305
305
LOG (INFO, " Shutdown" );
306
+ std::lock_guard<std::mutex> lg (m_osc_mtx);
306
307
307
308
switch (m_state)
308
309
{
@@ -396,7 +397,7 @@ bool SonicPiAPI::WaitUntilReady()
396
397
{
397
398
if (m_state == State::Created)
398
399
{
399
- return true ;
400
+ return true ;
400
401
}
401
402
402
403
int num_tries = 60 ;
@@ -424,10 +425,12 @@ bool SonicPiAPI::WaitUntilReady()
424
425
bool SonicPiAPI::PingUntilServerCreated ()
425
426
{
426
427
LOG (INFO, " Pinging Spider Server until a response is received..." );
428
+ std::lock_guard<std::mutex> lg (m_osc_mtx);
429
+
427
430
if (m_state == State::Created)
428
431
{
429
- return true ;
430
432
LOG (ERR, " Error! No need to ping server as it's already created!" );
433
+ return true ;
431
434
}
432
435
433
436
if (m_state != State::Initializing)
@@ -495,6 +498,8 @@ bool SonicPiAPI::Init(const fs::path& root)
495
498
496
499
m_pClient->Report (message);
497
500
LOG (ERR, " Call shutdown before init!" );
501
+ m_state = State::Error;
502
+ m_osc_mtx.unlock ();
498
503
return false ;
499
504
}
500
505
@@ -523,12 +528,15 @@ bool SonicPiAPI::Init(const fs::path& root)
523
528
message.text = " Could not find root path: " + root.string ();
524
529
525
530
m_pClient->Report (message);
531
+ m_state = State::Error;
532
+ m_osc_mtx.unlock ();
526
533
return false ;
527
534
}
528
535
529
536
if (!InitializePaths (root))
530
537
{
531
538
// oh no, something went wrong :-(
539
+ m_osc_mtx.unlock ();
532
540
return false ;
533
541
}
534
542
@@ -577,16 +585,17 @@ bool SonicPiAPI::Init(const fs::path& root)
577
585
578
586
LOG (INFO, " Log PAth: " + GetPath (SonicPiPath::LogPath).string ());
579
587
580
-
581
588
// Start the Boot Daemon
582
589
if (!StartBootDaemon ())
583
590
{
591
+ m_osc_mtx.unlock ();
584
592
return false ;
585
593
}
586
594
587
595
// Start the OC Server
588
596
if (!StartOscServer ())
589
597
{
598
+ m_osc_mtx.unlock ();
590
599
return false ;
591
600
}
592
601
@@ -596,6 +605,7 @@ bool SonicPiAPI::Init(const fs::path& root)
596
605
LOG (INFO, " API State set to: Initializing..." );
597
606
598
607
m_osc_mtx.unlock ();
608
+
599
609
LOG (INFO, " Going to start pinging server..." );
600
610
m_pingerThread = std::thread ([&]() {
601
611
PingUntilServerCreated ();
0 commit comments