diff --git a/ChangeLog b/ChangeLog index 88de5db..31fb448 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2020-06-23 NIIBE Yutaka + + * chopstx.c (chopstx_critical): New. + 2019-12-27 NIIBE Yutaka * contrib/spi-st.c (check_transmit, put_data): Fix handling diff --git a/chopstx.c b/chopstx.c index 15f0a5e..551bf71 100644 --- a/chopstx.c +++ b/chopstx.c @@ -1,7 +1,7 @@ /* * chopstx.c - Threads and only threads. * - * Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2019 + * Copyright (C) 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 * Flying Stone Technology * Author: NIIBE Yutaka * @@ -1700,3 +1700,23 @@ chopstx_conf_idle (int enable_sleep) return r; } + + +/** + * chopstx_critical - Construct a critical section + * @func: function to be called + * @arg: argument to function + * + * Run the function @func with @arg under CPU schedule lock. + * Return void * pointer. + */ +void * +chopstx_critical (void *func (void *), void *arg) +{ + void *p; + + chx_cpu_sched_lock (); + p = func (arg); + chx_cpu_sched_unlock (); + return p; +} diff --git a/chopstx.h b/chopstx.h index 45d7320..1342203 100644 --- a/chopstx.h +++ b/chopstx.h @@ -1,7 +1,8 @@ /* * chopstx.h - Threads and only threads. * - * Copyright (C) 2013, 2016, 2017, 2018 Flying Stone Technology + * Copyright (C) 2013, 2016, 2017, 2018, 2020 + * Flying Stone Technology * Author: NIIBE Yutaka * * This file is a part of Chopstx, a thread library for embedded. @@ -161,3 +162,5 @@ int chopstx_poll (uint32_t *usec_p, int n, struct chx_poll_head *const pd_array[]); int chopstx_conf_idle (int enable_sleep); + +void *chopstx_critical (void *func (void *), void *arg);