Skip to content

Commit 9933ede

Browse files
committed
pbio/sys/main: Make start requested check public.
This will be used to coordinate parallel tasks that wait on programs to start.
1 parent 87ebf19 commit 9933ede

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/pbio/include/pbsys/main.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,24 @@ typedef struct _pbsys_main_program_t {
7474

7575
pbsys_main_program_start_request_type_t pbsys_main_program_get_start_request_type(void);
7676

77+
/**
78+
* Requests a program to be started soon.
79+
*
80+
* @param [in] id Program identifier or slot.
81+
* @param [in] start_request_type Who is making the request.
82+
* @returns ::PBIO_ERROR_BUSY if a start request was already made or a program is already running.
83+
* ::PBIO_ERROR_NOT_SUPPORTED if the program is not available.
84+
* ::PBIO_SUCCESS otherwise.
85+
*/
7786
pbio_error_t pbsys_main_program_request_start(pbio_pybricks_user_program_id_t id, pbsys_main_program_start_request_type_t start_request_type);
7887

88+
/**
89+
* Checks if a program start request has been made.
90+
*
91+
* @returns @c true if a request was already made, @c false if not.
92+
*/
93+
bool pbsys_main_program_start_is_requested();
94+
7995
/**
8096
* Validates the program that is being requested to start.
8197
*
@@ -133,6 +149,10 @@ static inline pbio_error_t pbsys_main_program_request_start(pbio_pybricks_user_p
133149
return PBIO_ERROR_NOT_SUPPORTED;
134150
}
135151

152+
static inline bool pbsys_main_program_start_is_requested() {
153+
return false;
154+
}
155+
136156
static inline pbio_error_t pbsys_main_program_validate(pbsys_main_program_t *program) {
137157
return PBIO_ERROR_NOT_SUPPORTED;
138158
}

lib/pbio/sys/main.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,7 @@
2626
// Singleton with information about the currently (or soon) active program.
2727
static pbsys_main_program_t program;
2828

29-
/**
30-
* Checks if a start request has been made for the main program.
31-
*
32-
* @param [in] program A pointer to the main program structure.
33-
* @returns true if a start request has been made, false otherwise.
34-
*/
35-
static bool pbsys_main_program_start_requested() {
29+
bool pbsys_main_program_start_is_requested() {
3630
return program.start_request_type != PBSYS_MAIN_PROGRAM_START_REQUEST_TYPE_NONE;
3731
}
3832

@@ -58,7 +52,7 @@ pbsys_main_program_start_request_type_t pbsys_main_program_get_start_request_typ
5852
pbio_error_t pbsys_main_program_request_start(pbio_pybricks_user_program_id_t id, pbsys_main_program_start_request_type_t start_request_type) {
5953

6054
// Can't start new program if already running or new requested.
61-
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING) || pbsys_main_program_start_requested()) {
55+
if (pbsys_status_test(PBIO_PYBRICKS_STATUS_USER_PROGRAM_RUNNING) || pbsys_main_program_start_is_requested()) {
6256
return PBIO_ERROR_BUSY;
6357
}
6458

@@ -98,7 +92,7 @@ int main(int argc, char **argv) {
9892
// Drives all processes while we wait for user input.
9993
pbio_os_run_processes_and_wait_for_event();
10094

101-
if (!pbsys_main_program_start_requested()) {
95+
if (!pbsys_main_program_start_is_requested()) {
10296
continue;
10397
}
10498

0 commit comments

Comments
 (0)