KiCad PCB EDA Suite
Loading...
Searching...
No Matches
spinlock.h
Go to the documentation of this file.
1
/*
2
* This program source code file is part of KiCad, a free EDA CAD application.
3
*
4
* Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5
*
6
* This program is free software: you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License as published by the
8
* Free Software Foundation, either version 3 of the License, or (at your
9
* option) any later version.
10
*
11
* This program is distributed in the hope that it will be useful, but
12
* WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
* General Public License for more details.
15
*
16
* You should have received a copy of the GNU General Public License along
17
* with this program. If not, see <http://www.gnu.org/licenses/>.
18
*/
19
20
#ifndef __KICAD_SPINLOCK_H
21
#define __KICAD_SPINLOCK_H
22
23
#include <atomic>
24
25
29
class
KISPINLOCK
30
{
31
public
:
32
KISPINLOCK
() :
33
m_lock
( false )
34
{}
35
36
void
lock
()
37
{
38
while
(
m_lock
.exchange(
true
, std::memory_order_acquire ) );
39
}
40
41
bool
try_lock
()
42
{
43
return
!
m_lock
.exchange(
true
, std::memory_order_acquire );
44
}
45
46
void
unlock
()
47
{
48
m_lock
.store(
false
, std::memory_order_release );
49
}
50
51
bool
test
()
52
{
53
return
m_lock
.load( std::memory_order_acquire );
54
}
55
56
private
:
57
std::atomic<bool>
m_lock
;
58
};
59
60
#endif
KISPINLOCK::lock
void lock()
Definition
spinlock.h:36
KISPINLOCK::unlock
void unlock()
Definition
spinlock.h:46
KISPINLOCK::test
bool test()
Definition
spinlock.h:51
KISPINLOCK::KISPINLOCK
KISPINLOCK()
Definition
spinlock.h:32
KISPINLOCK::m_lock
std::atomic< bool > m_lock
Definition
spinlock.h:57
KISPINLOCK::try_lock
bool try_lock()
Definition
spinlock.h:41
src
libs
core
include
core
spinlock.h
Generated on Sun Sep 21 2025 01:05:26 for KiCad PCB EDA Suite by
1.13.2