IAtari
Genetic algorithm generating AI capable to play Atari2600 games.
SMP.h
Go to the documentation of this file.
1 /*
2  This file is part of Leela Zero.
3  Copyright (C) 2017 Gian-Carlo Pascutto
4 
5  Leela Zero is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  Leela Zero is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with Leela Zero. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef SMP_H_INCLUDED
20 #define SMP_H_INCLUDED
21 
22 #include <atomic>
23 
29 namespace SMP {
36  int get_num_cpus();
37 
46  class Mutex {
47  public:
53  Mutex();
54 
60  ~Mutex() = default;
61  friend class Lock;
62  private:
63  std::atomic<bool> m_lock;
64  };
65 
74  class Lock {
75  public:
82  explicit Lock(Mutex & m);
88  ~Lock();
94  void lock();
100  void unlock();
101  private:
103  };
104 }
105 
106 // Avoids accidentally creating a temporary
107 #define LOCK(mutex, lock) SMP::Lock lock((mutex))
108 
109 #endif
Lock(Mutex &m)
Construct a Lock with a Mutex.
Definition: SMP.cpp:27
~Lock()
Standard destructor.
Definition: SMP.cpp:40
Mutex * m_mutex
Definition: SMP.h:102
Mutex()
Standard constructor (Set the Mutex as unlocked)
Definition: SMP.cpp:23
Class used to handle Mutex.
Definition: SMP.h:74
void lock()
Try to lock the Mutex.
Definition: SMP.cpp:32
void unlock()
Unlock the Mutex.
Definition: SMP.cpp:36
std::atomic< bool > m_lock
Definition: SMP.h:63
A Symmetric multiprocessing implementation.
~Mutex()=default
Standard destructor.
Class used to protect data shared with different threads.
Definition: SMP.h:46
int get_num_cpus()
Returns the number of hardware thread contexts. This value is supposed to be equals to the number of ...
Definition: SMP.cpp:44