Replace usleep with util::sleep_for (#19643)

* replace usleep with sleep_for

* sleep microseconds

* sleep nanoseconds

* Trigger Build
albatross
Dean Lee 2021-01-05 01:03:11 +08:00 committed by GitHub
parent 6104e4c09e
commit c1cf0882bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 34 additions and 28 deletions

View File

@ -465,7 +465,7 @@ struct Updater {
while(battery_cap < min_battery_cap) {
battery_cap = battery_capacity();
battery_cap_text = std::to_string(battery_cap);
usleep(1000000);
util::sleep_for(1000);
}
set_running();
}
@ -483,7 +483,7 @@ struct Updater {
while(battery_cap < min_battery_cap) {
battery_cap = battery_capacity();
battery_cap_text = std::to_string(battery_cap);
usleep(1000000);
util::sleep_for(1000);
}
set_running();
}
@ -756,7 +756,7 @@ struct Updater {
assert(glGetError() == GL_NO_ERROR);
// no simple way to do 30fps vsync with surfaceflinger...
usleep(30000);
util::sleep_for(30);
}
if (update_thread_handle.joinable()) {

View File

@ -22,6 +22,7 @@
#include "cereal/gen/cpp/car.capnp.h"
#include "common/util.h"
#include "common/utilpp.h"
#include "common/params.h"
#include "common/swaglog.h"
#include "common/timing.h"
@ -85,7 +86,7 @@ void safety_setter_thread() {
LOGW("got CarVin %s", str_vin.c_str());
break;
}
usleep(100*1000);
util::sleep_for(100);
}
// VIN query done, stop listening to OBDII
@ -101,7 +102,7 @@ void safety_setter_thread() {
params = Params().read_db_bytes("CarParams");
if (params.size() > 0) break;
usleep(100*1000);
util::sleep_for(100);
}
LOGW("got %d bytes CarParams", params.size());
@ -193,7 +194,7 @@ bool usb_connect() {
// must be called before threads or with mutex
void usb_retry_connect() {
LOGW("attempting to connect");
while (!usb_connect()) { usleep(100*1000); }
while (!usb_connect()) { util::sleep_for(100); }
LOGW("connected to board");
}
@ -260,8 +261,7 @@ void can_recv_thread() {
uint64_t cur_time = nanos_since_boot();
int64_t remaining = next_frame_time - cur_time;
if (remaining > 0){
useconds_t sleep = remaining / 1000;
usleep(sleep);
std::this_thread::sleep_for(std::chrono::nanoseconds(remaining));
} else {
if (ignition){
LOGW("missed cycles (%d) %lld", (int)-1*remaining/dt, remaining);
@ -288,7 +288,7 @@ void can_health_thread() {
healthData.setHwType(cereal::HealthData::HwType::UNKNOWN);
pm.send("health", msg);
usleep(500*1000);
util::sleep_for(500);
}
// run at 2hz
@ -388,7 +388,7 @@ void can_health_thread() {
}
pm.send("health", msg);
panda->send_heartbeat();
usleep(500*1000);
util::sleep_for(500);
}
}
@ -508,7 +508,7 @@ void pigeon_thread() {
ignition_last = ignition;
// 10ms - 100 Hz
usleep(10*1000);
util::sleep_for(10);
}
delete pigeon;

View File

@ -6,7 +6,7 @@
#include "common/swaglog.h"
#include "common/gpio.h"
#include "common/utilpp.h"
#include "panda.h"
#ifdef QCOM2
@ -30,7 +30,7 @@ void panda_set_power(bool power){
err += gpio_set(GPIO_STM_RST_N, is_legacy ? false : true);
err += gpio_set(GPIO_STM_BOOT0, false);
usleep(100*1000); // 100 ms
util::sleep_for(100); // 100 ms
err += gpio_set(GPIO_STM_RST_N, is_legacy ? power : (!power));
assert(err == 0);

View File

@ -6,6 +6,7 @@
#include "common/swaglog.h"
#include "common/gpio.h"
#include "common/utilpp.h"
#include "pigeon.h"
@ -32,27 +33,27 @@ Pigeon * Pigeon::connect(const char * tty){
}
void Pigeon::init() {
usleep(1000*1000);
util::sleep_for(1000);
LOGW("panda GPS start");
// power off pigeon
set_power(0);
usleep(100*1000);
util::sleep_for(100);
// 9600 baud at init
set_baud(9600);
// power on pigeon
set_power(1);
usleep(500*1000);
util::sleep_for(500);
// baud rate upping
send("\x24\x50\x55\x42\x58\x2C\x34\x31\x2C\x31\x2C\x30\x30\x30\x37\x2C\x30\x30\x30\x33\x2C\x34\x36\x30\x38\x30\x30\x2C\x30\x2A\x31\x35\x0D\x0A"s);
usleep(100*1000);
util::sleep_for(100);
// set baud rate to 460800
set_baud(460800);
usleep(100*1000);
util::sleep_for(100);
// init from ubloxd
// To generate this data, run test/ubloxd.py with the print statements enabled in the write function in panda/python/serial.py

View File

@ -21,6 +21,7 @@
#include "msm_cam_sensor.h"
#include "common/util.h"
#include "common/utilpp.h"
#include "common/timing.h"
#include "common/swaglog.h"
#include "common/params.h"
@ -2025,7 +2026,7 @@ static void* ops_thread(void* arg) {
front_op_id_last = front_op.op_id;
}
usleep(50000);
util::sleep_for(50);
}
return NULL;

View File

@ -13,6 +13,7 @@
#include <atomic>
#include "common/util.h"
#include "common/utilpp.h"
#include "common/swaglog.h"
#include "camera_qcom2.h"
@ -1087,7 +1088,7 @@ static void* ae_thread(void* arg) {
}
}
usleep(50000);
util::sleep_for(50);
}
return NULL;

View File

@ -291,7 +291,7 @@ int Params::read_db_value_blocking(const char* key, char** value, size_t* value_
if (result == 0) {
break;
} else {
usleep(100000); // 0.1 s
util::sleep_for(100); // 0.1 s
}
}

View File

@ -242,7 +242,7 @@ void encoder_thread(RotateState *rotate_state, int cam_idx) {
int err = visionstream_init(&stream, cameras_logged[cam_idx].stream_type, false, &buf_info);
if (err != 0) {
LOGD("visionstream connect fail");
usleep(100000);
util::sleep_for(100);
continue;
}

View File

@ -6,7 +6,7 @@
#include "common/visionipc.h"
#include "common/timing.h"
#include "common/utilpp.h"
#include "RawLogger.h"
int main() {
@ -19,7 +19,7 @@ int main() {
err = visionstream_init(&stream, VISION_STREAM_YUV, false, &buf_info);
if (err != 0) {
printf("visionstream fail\n");
usleep(100000);
util::sleep_for(100);
}
break;
}

View File

@ -5,6 +5,7 @@
#include <cassert>
#include <sys/resource.h>
#include "common/utilpp.h"
#include "common/visionbuf.h"
#include "common/visionipc.h"
#include "common/swaglog.h"
@ -42,7 +43,7 @@ int main(int argc, char **argv) {
err = visionstream_init(&stream, VISION_STREAM_YUV_FRONT, true, &buf_info);
if (err) {
printf("visionstream connect fail\n");
usleep(100000);
util::sleep_for(100);
continue;
}
LOGW("connected with buffer size: %d", buf_info.buf_len);

View File

@ -8,6 +8,7 @@
#include "common/visionipc.h"
#include "common/swaglog.h"
#include "common/clutil.h"
#include "common/utilpp.h"
#include "models/driving.h"
#include "messaging.hpp"
@ -132,7 +133,7 @@ int main(int argc, char **argv) {
err = visionstream_init(&stream, VISION_STREAM_YUV, true, &buf_info);
if (err) {
LOGW("visionstream connect failed");
usleep(100000);
util::sleep_for(100);
continue;
}
LOGW("connected with buffer size: %d", buf_info.buf_len);

View File

@ -235,7 +235,7 @@ int main() {
publisher.send("procLog", msg);
usleep(2000000); // 2 secs
util::sleep_for(2000); // 2 secs
}
return 0;

View File

@ -3,6 +3,7 @@
#include <unistd.h>
#include "common/swaglog.h"
#include "common/utilpp.h"
#include "bmx055_magn.hpp"
@ -37,7 +38,7 @@ int BMX055_Magn::init(){
LOGE("Enabling power failed: %d", ret);
goto fail;
}
usleep(5 * 1000); // wait until the chip is powered on
util::sleep_for(5); // wait until the chip is powered on
// read chip ID
ret = read_register(BMX055_MAGN_I2C_REG_ID, buffer, 1);