Pteros  2.0
Molecular modeling library for human beings!
atomic_wrapper.h
1 /*
2  *
3  * This source code is part of
4  * ******************
5  * *** Pteros ***
6  * ******************
7  * molecular modeling library
8  *
9  * Copyright (c) 2009-2013, Semen Yesylevskyy
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of Artistic License:
13  *
14  * Please note, that Artistic License is slightly more restrictive
15  * then GPL license in terms of distributing the modified versions
16  * of this software (they should be approved first).
17  * Read http://www.opensource.org/licenses/artistic-license-2.0.php
18  * for details. Such license fits scientific software better then
19  * GPL because it prevents the distribution of bugged derivatives.
20  *
21 */
22 
23 #ifndef ATOMIC_WRAPPER_H_INCLUDED
24 #define ATOMIC_WRAPPER_H_INCLUDED
25 
26 #include <atomic>
27 
28 // Wrapper over std::atomic to make it usable in std::vector
29 template <typename T>
30 struct atomic_wrapper {
31  std::atomic<T> _a;
32 
33  atomic_wrapper():_a(){}
34 
35  atomic_wrapper(const std::atomic<T> &a):_a(a.load()){}
36 
37  atomic_wrapper(const atomic_wrapper &other):_a(other._a.load()){}
38 
39  atomic_wrapper &operator=(const atomic_wrapper &other){
40  _a.store(other._a.load());
41  }
42 
43  T load(){
44  return _a.load();
45  }
46 
47  void store(const T& v){
48  _a.store(v);
49  }
50 };
51 
52 #endif