Skip to content

Commit

Permalink
platform: scheduler: remove unused delay functions
Browse files Browse the repository at this point in the history
  • Loading branch information
joelguittet committed May 29, 2024
1 parent 2655822 commit cb6c6c0
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 123 deletions.
14 changes: 0 additions & 14 deletions include/mender-scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,6 @@ mender_err_t mender_scheduler_work_deactivate(void *handle);
*/
mender_err_t mender_scheduler_work_delete(void *handle);

/**
* @brief Function used to initialize handle to be used with mender_scheduler_delay_until_* functions
* @param handle Delay handle
* @return MENDER_OK if the function succeeds, error code otherwise
*/
mender_err_t mender_scheduler_delay_until_init(unsigned long *handle);

/**
* @brief Function used to make a delay until a specified time
* @param delay Delay value (seconds)
* @return MENDER_OK if the function succeeds, error code otherwise
*/
mender_err_t mender_scheduler_delay_until_s(unsigned long *handle, uint32_t delay);

/**
* @brief Function used to create a mutex
* @param handle Mutex handle if the function succeeds, NULL otherwise
Expand Down
20 changes: 0 additions & 20 deletions platform/scheduler/freertos/src/mender-scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,26 +296,6 @@ mender_scheduler_work_delete(void *handle) {
return MENDER_OK;
}

mender_err_t
mender_scheduler_delay_until_init(unsigned long *handle) {

assert(NULL != handle);

/* Get uptime */
*handle = (unsigned long)xTaskGetTickCount();

return MENDER_OK;
}

mender_err_t
mender_scheduler_delay_until_s(unsigned long *handle, uint32_t delay) {

/* Sleep */
vTaskDelayUntil((TickType_t *)handle, (1000 * delay) / portTICK_PERIOD_MS);

return MENDER_OK;
}

mender_err_t
mender_scheduler_mutex_create(void **handle) {

Expand Down
19 changes: 0 additions & 19 deletions platform/scheduler/generic/weak/src/mender-scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,6 @@ mender_scheduler_work_delete(void *handle) {
return MENDER_NOT_IMPLEMENTED;
}

__attribute__((weak)) mender_err_t
mender_scheduler_delay_until_init(unsigned long *handle) {

(void)handle;

/* Nothing to do */
return MENDER_NOT_IMPLEMENTED;
}

__attribute__((weak)) mender_err_t
mender_scheduler_delay_until_s(unsigned long *handle, uint32_t delay) {

(void)handle;
(void)delay;

/* Nothing to do */
return MENDER_NOT_IMPLEMENTED;
}

__attribute__((weak)) mender_err_t
mender_scheduler_mutex_create(void **handle) {

Expand Down
44 changes: 0 additions & 44 deletions platform/scheduler/posix/src/mender-scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -325,50 +325,6 @@ mender_scheduler_work_delete(void *handle) {
return MENDER_OK;
}

mender_err_t
mender_scheduler_delay_until_init(unsigned long *handle) {

assert(NULL != handle);

/* Read clock */
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
*handle = (unsigned long)(now.tv_sec * 1000000 + now.tv_nsec / 1000);

return MENDER_OK;
}

mender_err_t
mender_scheduler_delay_until_s(unsigned long *handle, uint32_t delay) {

assert(NULL != handle);

/* Compute elapsed time (amount of time since start marker) */
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
unsigned long elapsed = (now.tv_sec * 1000000 + now.tv_nsec / 1000) - *handle;

/* Time to wait is the delay - elapsed time */
unsigned long delay_us = delay * 1000000;
unsigned long real_delay_us = (unsigned long)ceil((double)(delay_us - elapsed));
if ((0 < real_delay_us) && (real_delay_us <= delay_us)) {
struct timespec request;
struct timespec remaining;
remaining.tv_sec = real_delay_us / 1000000;
remaining.tv_nsec = (real_delay_us % 1000000) * 1000;
do {
request.tv_sec = remaining.tv_sec;
request.tv_nsec = remaining.tv_nsec;
} while (nanosleep(&request, &remaining) < 0);
}

/* Read clock */
clock_gettime(CLOCK_MONOTONIC, &now);
*handle = (unsigned long)(now.tv_sec * 1000000 + now.tv_nsec / 1000);

return MENDER_OK;
}

mender_err_t
mender_scheduler_mutex_create(void **handle) {

Expand Down
26 changes: 0 additions & 26 deletions platform/scheduler/zephyr/src/mender-scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,32 +247,6 @@ mender_scheduler_work_delete(void *handle) {
return MENDER_OK;
}

mender_err_t
mender_scheduler_delay_until_init(unsigned long *handle) {

assert(NULL != handle);

/* Get uptime */
*handle = (unsigned long)k_uptime_get();

return MENDER_OK;
}

mender_err_t
mender_scheduler_delay_until_s(unsigned long *handle, uint32_t delay) {

assert(NULL != handle);

/* Compute sleep time and sleep */
int64_t ms = (1000 * delay) - (k_uptime_get() - *handle);
k_msleep((ms > 0) ? ((int32_t)ms) : 1);

/* Update uptime */
*handle = (unsigned long)k_uptime_get();

return MENDER_OK;
}

mender_err_t
mender_scheduler_mutex_create(void **handle) {

Expand Down

0 comments on commit cb6c6c0

Please sign in to comment.