summaryrefslogtreecommitdiff
path: root/common/throttle_ap.c
diff options
context:
space:
mode:
authorJack Rosenthal <jrosenth@chromium.org>2021-03-23 14:44:36 -0600
committerCommit Bot <commit-bot@chromium.org>2021-03-23 23:21:52 +0000
commit416b1307caa472cacabd227d72e72c56c7a7040d (patch)
tree3518d3ba01201ba440d57e0323b76052fe38a4c4 /common/throttle_ap.c
parent2ff6477da30081edc3f396c60b0089ccc42a9f78 (diff)
downloadchrome-ec-416b1307caa472cacabd227d72e72c56c7a7040d.tar.gz
throttle_ap: convert throttle_mutex to use K_MUTEX_DEFINE
K_MUTEX_DEFINE creates a statically-initialized mutex, and is now available for both Zephyr and CrOS EC OS. The previous way of initializing this mutex required a boolean variable, which could potentially be the cause of a race condition if the mutex had been initialized in two threads (this condition has not been observed, though). Change to K_MUTEX_DEFINE to demonstrate the new way to do this. BUG=b:177677037 BRANCH=none TEST=compile for zephyr and CrOS EC OS Signed-off-by: Jack Rosenthal <jrosenth@chromium.org> Change-Id: Id27e6bff975809a2ea51bb5e9ddb0e9e6971f066 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2782232 Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/throttle_ap.c')
-rw-r--r--common/throttle_ap.c7
1 files changed, 1 insertions, 6 deletions
diff --git a/common/throttle_ap.c b/common/throttle_ap.c
index e58256dab8..cfa97d93a5 100644
--- a/common/throttle_ap.c
+++ b/common/throttle_ap.c
@@ -24,8 +24,7 @@
/*****************************************************************************/
/* This enforces the virtual OR of all throttling sources. */
-static mutex_t throttle_mutex;
-STATIC_IF(CONFIG_ZEPHYR) bool throttle_mutex_inited;
+K_MUTEX_DEFINE(throttle_mutex);
static uint32_t throttle_request[NUM_THROTTLE_TYPES];
static int debounced_prochot_in;
static enum gpio_signal gpio_prochot_in = GPIO_COUNT;
@@ -36,10 +35,6 @@ void throttle_ap(enum throttle_level level,
{
uint32_t tmpval, bitmask;
- if (IS_ENABLED(CONFIG_ZEPHYR) && !throttle_mutex_inited) {
- (void)k_mutex_init(&throttle_mutex);
- throttle_mutex_inited = true;
- }
mutex_lock(&throttle_mutex);
bitmask = BIT(source);