Skip to content

Commit

Permalink
Improve sleep resilience considering only their granularity
Browse files Browse the repository at this point in the history
  • Loading branch information
cguimaraes committed Feb 1, 2023
1 parent 7d3f8b3 commit 53baf73
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/system/arduino/esp32/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wa
/*------------------ Sleep ------------------*/
int z_sleep_us(unsigned int time) { return usleep(time); }

int z_sleep_ms(unsigned int time) { return usleep(time * 1000U); }
int z_sleep_ms(unsigned int time) {
for (unsigned int i = 0; i < time; i++) {
z_sleep_us(1000);
}

return 0;
}

int z_sleep_s(unsigned int time) { return sleep(time); }

Expand Down
8 changes: 7 additions & 1 deletion src/system/arduino/opencr/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ int z_sleep_ms(unsigned int time) {
return 0;
}

int z_sleep_s(unsigned int time) { return z_sleep_ms(time * 1000U); }
int z_sleep_s(unsigned int time) {
for (unsigned int i = 0; i < time; i++) {
z_sleep_ms(1000);
}

return 0;
}

/*------------------ Instant ------------------*/
void __z_clock_gettime(z_clock_t *ts) {
Expand Down
8 changes: 7 additions & 1 deletion src/system/emscripten/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,13 @@ int z_sleep_ms(unsigned int time) {
return 0;
}

int z_sleep_s(unsigned int time) { return z_sleep_ms(time * 1000); }
int z_sleep_s(unsigned int time) {
for (unsigned int i = 0; i < time; i++) {
z_sleep_ms(1000);
}

return 0;
}

/*------------------ Instant ------------------*/
z_clock_t z_clock_now(void) { return z_time_now(); }
Expand Down
8 changes: 7 additions & 1 deletion src/system/espidf/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wa
/*------------------ Sleep ------------------*/
int z_sleep_us(unsigned int time) { return usleep(time); }

int z_sleep_ms(unsigned int time) { return usleep(time * 1000U); }
int z_sleep_ms(unsigned int time) {
for (unsigned int i = 0; i < time; i++) {
z_sleep_us(1000);
}

return 0;
}

int z_sleep_s(unsigned int time) { return sleep(time); }

Expand Down
3 changes: 2 additions & 1 deletion src/system/mbed/system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) {

/*------------------ Sleep ------------------*/
int z_sleep_us(unsigned int time) {
return -1; // Not supported
ThisThread::sleep_for(chrono::milliseconds(((time / 1000) + (time % 1000 == 0 ? 0 : 1))));
return 0;
}

int z_sleep_ms(unsigned int time) {
Expand Down
8 changes: 7 additions & 1 deletion src/system/unix/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,13 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wa
/*------------------ Sleep ------------------*/
int z_sleep_us(unsigned int time) { return usleep(time); }

int z_sleep_ms(unsigned int time) { return z_sleep_us(time * 1000U); }
int z_sleep_ms(unsigned int time) {
for (unsigned int i = 0; i < time; i++) {
z_sleep_us(1000);
}

return 0;
}

int z_sleep_s(unsigned int time) { return sleep(time); }

Expand Down
8 changes: 7 additions & 1 deletion src/system/zephyr/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,13 @@ int8_t _z_condvar_wait(_z_condvar_t *cv, _z_mutex_t *m) { return pthread_cond_wa
/*------------------ Sleep ------------------*/
int z_sleep_us(unsigned int time) { return usleep(time); }

int z_sleep_ms(unsigned int time) { return usleep(time * 1000U); }
int z_sleep_ms(unsigned int time) {
for (unsigned int i = 0; i < time; i++) {
z_sleep_us(1000);
}

return 0;
}

int z_sleep_s(unsigned int time) { return sleep(time); }

Expand Down

0 comments on commit 53baf73

Please sign in to comment.