summaryrefslogtreecommitdiff
path: root/common/irq_locking.c
blob: 1146145c5e7e72efdde2c2c64d3f3671a78a780d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* Copyright 2020 The ChromiumOS Authors
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

/*
 * This file is used for platform/ec implementations of irq_lock and irq_unlock
 * which are defined by Zephyr.
 */

#include "task.h"
#include "util.h"

static uint32_t lock_count;

uint32_t irq_lock(void)
{
	interrupt_disable();
	return lock_count++;
}

void irq_unlock(uint32_t key)
{
	lock_count = key;

	/*
	 * Since we're allowing nesting locks, we only actually want to release
	 * the lock if the lock count reached 0.
	 */
	if (lock_count == 0)
		interrupt_enable();
}