tools/replay: replace deprecated usleep(0) with std::this_thread::yield (#23544)

* use std::this_thread::yield()

* use yield in cameraServer::waitFinish

* rename waitFinish to waitForSent
pull/24505/head
Dean Lee 3 years ago committed by GitHub
parent c007c7e681
commit 3863a88356
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      selfdrive/ui/replay/camera.cc
  2. 4
      selfdrive/ui/replay/camera.h
  3. 4
      selfdrive/ui/replay/replay.cc
  4. 2
      selfdrive/ui/replay/util.cc

@ -77,10 +77,16 @@ void CameraServer::pushFrame(CameraType type, FrameReader *fr, const cereal::Enc
if (cam.width != fr->width || cam.height != fr->height) { if (cam.width != fr->width || cam.height != fr->height) {
cam.width = fr->width; cam.width = fr->width;
cam.height = fr->height; cam.height = fr->height;
waitFinish(); waitForSent();
startVipcServer(); startVipcServer();
} }
++publishing_; ++publishing_;
cam.queue.push({fr, eidx}); cam.queue.push({fr, eidx});
} }
void CameraServer::waitForSent() {
while (publishing_ > 0) {
std::this_thread::yield();
}
}

@ -11,9 +11,7 @@ public:
CameraServer(std::pair<int, int> camera_size[MAX_CAMERAS] = nullptr, bool send_yuv = false); CameraServer(std::pair<int, int> camera_size[MAX_CAMERAS] = nullptr, bool send_yuv = false);
~CameraServer(); ~CameraServer();
void pushFrame(CameraType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx); void pushFrame(CameraType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx);
inline void waitFinish() { void waitForSent();
while (publishing_ > 0) usleep(0);
}
protected: protected:
struct Camera { struct Camera {

@ -383,7 +383,7 @@ void Replay::stream() {
publishMessage(evt); publishMessage(evt);
} else if (camera_server_) { } else if (camera_server_) {
if (hasFlag(REPLAY_FLAG_FULL_SPEED)) { if (hasFlag(REPLAY_FLAG_FULL_SPEED)) {
camera_server_->waitFinish(); camera_server_->waitForSent();
} }
publishFrame(evt); publishFrame(evt);
} }
@ -391,7 +391,7 @@ void Replay::stream() {
} }
// wait for frame to be sent before unlock.(frameReader may be deleted after unlock) // wait for frame to be sent before unlock.(frameReader may be deleted after unlock)
if (camera_server_) { if (camera_server_) {
camera_server_->waitFinish(); camera_server_->waitForSent();
} }
if (eit == events_->end() && !hasFlag(REPLAY_FLAG_NO_LOOP)) { if (eit == events_->end() && !hasFlag(REPLAY_FLAG_NO_LOOP)) {

@ -305,7 +305,7 @@ void precise_nano_sleep(long sleep_ns) {
// spin wait // spin wait
if (sleep_ns > 0) { if (sleep_ns > 0) {
while ((nanos_since_boot() - start_sleep) <= sleep_ns) { while ((nanos_since_boot() - start_sleep) <= sleep_ns) {
usleep(0); std::this_thread::yield();
} }
} }
} }

Loading…
Cancel
Save