mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-08-21 16:23:46 +08:00
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 old-commit-hash: 3863a88356650242147a4f282e52d195413864ca
This commit is contained in:
@@ -77,10 +77,16 @@ void CameraServer::pushFrame(CameraType type, FrameReader *fr, const cereal::Enc
|
||||
if (cam.width != fr->width || cam.height != fr->height) {
|
||||
cam.width = fr->width;
|
||||
cam.height = fr->height;
|
||||
waitFinish();
|
||||
waitForSent();
|
||||
startVipcServer();
|
||||
}
|
||||
|
||||
++publishing_;
|
||||
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();
|
||||
void pushFrame(CameraType type, FrameReader* fr, const cereal::EncodeIndex::Reader& eidx);
|
||||
inline void waitFinish() {
|
||||
while (publishing_ > 0) usleep(0);
|
||||
}
|
||||
void waitForSent();
|
||||
|
||||
protected:
|
||||
struct Camera {
|
||||
|
||||
@@ -383,7 +383,7 @@ void Replay::stream() {
|
||||
publishMessage(evt);
|
||||
} else if (camera_server_) {
|
||||
if (hasFlag(REPLAY_FLAG_FULL_SPEED)) {
|
||||
camera_server_->waitFinish();
|
||||
camera_server_->waitForSent();
|
||||
}
|
||||
publishFrame(evt);
|
||||
}
|
||||
@@ -391,7 +391,7 @@ void Replay::stream() {
|
||||
}
|
||||
// wait for frame to be sent before unlock.(frameReader may be deleted after unlock)
|
||||
if (camera_server_) {
|
||||
camera_server_->waitFinish();
|
||||
camera_server_->waitForSent();
|
||||
}
|
||||
|
||||
if (eit == events_->end() && !hasFlag(REPLAY_FLAG_NO_LOOP)) {
|
||||
|
||||
@@ -305,7 +305,7 @@ void precise_nano_sleep(long sleep_ns) {
|
||||
// spin wait
|
||||
if (sleep_ns > 0) {
|
||||
while ((nanos_since_boot() - start_sleep) <= sleep_ns) {
|
||||
usleep(0);
|
||||
std::this_thread::yield();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user