blob: efb7be6996a64e34b53792f08aeaf1d9c62313e1 [file] [log] [blame]
Ken Liu91d44da2018-09-20 22:42:31 +08001/*
Summer Qin66f1e032020-01-06 15:40:03 +08002 * Copyright (c) 2018-2020, Arm Limited. All rights reserved.
Ken Liu91d44da2018-09-20 22:42:31 +08003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
Ken Liu91d44da2018-09-20 22:42:31 +08007#include "tfm_thread.h"
8#include "tfm_utils.h"
9#include "tfm_wait.h"
10
Ken Liu35f89392019-03-14 14:51:05 +080011void tfm_event_wait(struct tfm_event_t *pevnt)
Ken Liu91d44da2018-09-20 22:42:31 +080012{
Ken Liuf250b8b2019-12-27 16:31:24 +080013 TFM_CORE_ASSERT(pevnt && pevnt->magic == TFM_EVENT_MAGIC);
Ken Liu91d44da2018-09-20 22:42:31 +080014
Summer Qin66f1e032020-01-06 15:40:03 +080015 pevnt->owner = tfm_core_thrd_get_curr_thread();
16 tfm_core_thrd_set_state(pevnt->owner, THRD_STATE_BLOCK);
17 tfm_core_thrd_activate_schedule();
Ken Liu35f89392019-03-14 14:51:05 +080018}
Ken Liu91d44da2018-09-20 22:42:31 +080019
Ken Liu35f89392019-03-14 14:51:05 +080020void tfm_event_wake(struct tfm_event_t *pevnt, uint32_t retval)
21{
Ken Liuf250b8b2019-12-27 16:31:24 +080022 TFM_CORE_ASSERT(pevnt && pevnt->magic == TFM_EVENT_MAGIC);
Ken Liu35f89392019-03-14 14:51:05 +080023
Summer Qin66f1e032020-01-06 15:40:03 +080024 if (pevnt->owner && pevnt->owner->state == THRD_STATE_BLOCK) {
25 tfm_core_thrd_set_state(pevnt->owner, THRD_STATE_RUNNING);
26 tfm_core_thrd_set_retval(pevnt->owner, retval);
Ken Liu7ddb4c62020-04-10 13:12:21 +080027 pevnt->owner = NULL;
Summer Qin66f1e032020-01-06 15:40:03 +080028 tfm_core_thrd_activate_schedule();
Ken Liu91d44da2018-09-20 22:42:31 +080029 }
Ken Liu91d44da2018-09-20 22:42:31 +080030}