aGrUM  0.14.2
threadData.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005 by Christophe GONZALES and Pierre-Henri WUILLEMIN *
3  * {prenom.nom}_at_lip6.fr *
4  * *
5  * This program 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 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program 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 this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19  ***************************************************************************/
26 #ifndef GUM_THREAD_DATA_H
27 #define GUM_THREAD_DATA_H
28 
29 #include <new>
30 
31 #include <agrum/agrum.h>
32 
33 namespace gum {
34 
50  template < typename T_DATA >
51  // #TODO: replace by alignas(std::hardware_destructive_interference_size)
52  // when pyAgrum will be compiled in C++17
53  struct alignas(128) ThreadData {
54  // ##########################################################################
56  // ##########################################################################
58 
60  ThreadData(const T_DATA& theData) : data(theData) {}
61 
63  ThreadData(T_DATA&& theData) : data(std::move(theData)) {}
64 
66  ThreadData(const ThreadData< T_DATA >& from) : data(from.data) {}
67 
69  ThreadData(ThreadData< T_DATA >&& from) : data(std::move(from.data)) {}
70 
73 
75 
76  // ##########################################################################
78  // ##########################################################################
79 
81 
84  if (this != &from) data = from.data;
85  return *this;
86  }
87 
90  data = std::move(from.data);
91  return *this;
92  }
93 
95 
97  T_DATA data;
98  };
99 
100 } /* namespace gum */
101 
102 #endif /* GUM_THREAD_DATA_H */
ThreadData(const T_DATA &theData)
default constructor
Definition: threadData.h:60
ThreadData(T_DATA &&theData)
default constructor
Definition: threadData.h:63
STL namespace.
A wrapper that enables to store data in a way that prevents false cacheline sharing.
Definition: threadData.h:53
gum is the global namespace for all aGrUM entities
Definition: agrum.h:25
ThreadData(const ThreadData< T_DATA > &from)
copy constructor
Definition: threadData.h:66
ThreadData< T_DATA > & operator=(ThreadData< T_DATA > &&from)
move operator
Definition: threadData.h:89
ThreadData< T_DATA > & operator=(const ThreadData< T_DATA > &from)
copy operator
Definition: threadData.h:83
ThreadData(ThreadData< T_DATA > &&from)
move constructor
Definition: threadData.h:69
T_DATA data
the data we wish to store without cacheline parallel problem
Definition: threadData.h:97
~ThreadData()
destructor
Definition: threadData.h:72