Skip to content

Commit 0c4f788

Browse files
committed
pbio/os: Don't poll on single yield.
Awaiting once is sometimes useful with a poll, but not always. Make the macro more general purpose by doing it explicitly, only when needed.
1 parent 0b854ba commit 0c4f788

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

lib/pbio/drv/charger/charger_mp2639a.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,13 +187,15 @@ pbio_error_t pbdrv_charger_mp2639a_process_thread(pbio_os_state_t *state, void *
187187

188188
#if PBDRV_CONFIG_CHARGER_MP2639A_MODE_PWM
189189
while (pbdrv_pwm_get_dev(platform.mode_pwm_id, &mode_pwm) != PBIO_SUCCESS) {
190-
PBIO_OS_AWAIT_ONCE_AND_POLL(state);
190+
pbio_os_request_poll();
191+
PBIO_OS_AWAIT_ONCE(state);
191192
}
192193
#endif
193194

194195
#if PBDRV_CONFIG_CHARGER_MP2639A_ISET_PWM
195196
while (pbdrv_pwm_get_dev(platform.iset_pwm_id, &iset_pwm) != PBIO_SUCCESS) {
196-
PBIO_OS_AWAIT_ONCE_AND_POLL(state);
197+
pbio_os_request_poll();
198+
PBIO_OS_AWAIT_ONCE(state);
197199
}
198200
#endif
199201

lib/pbio/drv/pwm/pwm_lp50xx_stm32.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ static pbio_error_t pbdrv_pwm_lp50xx_stm32_process_thread(pbio_os_state_t *state
123123
PBIO_OS_ASYNC_BEGIN(state);
124124

125125
// Need to allow all drivers to init first.
126-
PBIO_OS_AWAIT_ONCE_AND_POLL(state);
126+
pbio_os_request_poll();
127+
PBIO_OS_AWAIT_ONCE(state);
127128

128129
static const struct {
129130
uint8_t reg;

lib/pbio/drv/uart/uart_debug_first_port.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ static pbio_error_t pbdrv_uart_debug_process_thread(pbio_os_state_t *state, void
9090
PBIO_OS_ASYNC_BEGIN(state);
9191

9292
while (pbdrv_uart_get_instance(0, &debug_uart) != PBIO_SUCCESS) {
93-
PBIO_OS_AWAIT_ONCE_AND_POLL(state);
93+
pbio_os_request_poll();
94+
PBIO_OS_AWAIT_ONCE(state);
9495
}
9596

9697
pbdrv_uart_set_baud_rate(debug_uart, 115200);

lib/pbio/include/pbio/os.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -253,25 +253,15 @@ struct _pbio_os_process_t {
253253
} while (0)
254254

255255
/**
256-
* Yields the protothread here once and polls to request handling again
257-
* immediately.
258-
*
259-
* Can be useful if several protothreads are started at the same time but not
260-
* in any particular order. PBIO_OS_AWAIT_ONCE_AND_POLL can be used in a loop
261-
* until the other protothreads have finished initializing as defined by
262-
* mutually defined state variables.
263-
*
264-
* Should be used sparingly as it can cause busy waiting. Processes will keep
265-
* running, but there will always be another event pending after this is used.
256+
* Yields the protothread here once.
266257
*
267258
* @param [in] state Protothread state.
268259
*/
269-
#define PBIO_OS_AWAIT_ONCE_AND_POLL(state) \
260+
#define PBIO_OS_AWAIT_ONCE(state) \
270261
do { \
271262
do_yield_now = 1; \
272263
PBIO_OS_ASYNC_SET_CHECKPOINT(state); \
273264
if (do_yield_now) { \
274-
pbio_os_request_poll(); \
275265
return PBIO_ERROR_AGAIN; \
276266
} \
277267
} while (0)

0 commit comments

Comments
 (0)