1 /******************************************************************************
2  * preempt.c
3  *
4  * Track atomic regions in the hypervisor which disallow sleeping.
5  *
6  * Copyright (c) 2010, Keir Fraser <keir@xen.org>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include <xen/preempt.h>
23 #include <xen/irq.h>
24 #include <asm/system.h>
25 
26 DEFINE_PER_CPU(unsigned int, __preempt_count);
27 
in_atomic(void)28 bool_t in_atomic(void)
29 {
30     return preempt_count() || in_irq() || !local_irq_is_enabled();
31 }
32 
33 #ifndef NDEBUG
ASSERT_NOT_IN_ATOMIC(void)34 void ASSERT_NOT_IN_ATOMIC(void)
35 {
36     ASSERT(!preempt_count());
37     ASSERT(!in_irq());
38     ASSERT(local_irq_is_enabled());
39 }
40 #endif
41