Galois
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Simple.h
Go to the documentation of this file.
1 /*
2  * This file belongs to the Galois project, a C++ library for exploiting
3  * parallelism. The code is being released under the terms of the 3-Clause BSD
4  * License (a copy is located in LICENSE.txt at the top-level directory).
5  *
6  * Copyright (C) 2018, The University of Texas at Austin. All rights reserved.
7  * UNIVERSITY EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES CONCERNING THIS
8  * SOFTWARE AND DOCUMENTATION, INCLUDING ANY WARRANTIES OF MERCHANTABILITY,
9  * FITNESS FOR ANY PARTICULAR PURPOSE, NON-INFRINGEMENT AND WARRANTIES OF
10  * PERFORMANCE, AND ANY WARRANTY THAT MIGHT OTHERWISE ARISE FROM COURSE OF
11  * DEALING OR USAGE OF TRADE. NO WARRANTY IS EITHER EXPRESS OR IMPLIED WITH
12  * RESPECT TO THE USE OF THE SOFTWARE OR DOCUMENTATION. Under no circumstances
13  * shall University be liable for incidental, special, indirect, direct or
14  * consequential damages or loss of profits, interruption of business, or
15  * related expenses which may arise from use of Software or Documentation,
16  * including but not limited to those resulting from defects in Software and/or
17  * Documentation, or loss or inaccuracy of data of any kind.
18  */
19 
20 #ifndef GALOIS_WORKLIST_FIFO_H
21 #define GALOIS_WORKLIST_FIFO_H
22 
23 #include <deque>
24 #include <mutex>
25 
26 #include "galois/config.h"
27 #include "galois/gdeque.h"
30 
31 namespace galois {
32 namespace worklists {
33 
35 template <typename T, typename container = std::deque<T>, bool popBack = true>
36 class Wrapper : private boost::noncopyable {
38  container wl;
39 
40 public:
41  template <typename _T>
43 
44  template <bool b>
45  using rethread = Wrapper;
46 
47  typedef T value_type;
48 
49  void push(const value_type& val) {
50  std::lock_guard<substrate::PaddedLock<true>> lg(lock);
51  wl.push_back(val);
52  }
53 
54  template <typename Iter>
55  void push(Iter b, Iter e) {
56  std::lock_guard<substrate::PaddedLock<true>> lg(lock);
57  wl.insert(wl.end(), b, e);
58  }
59 
60  template <typename RangeTy>
61  void push_initial(const RangeTy& range) {
63  push(range.begin(), range.end());
64  }
65 
68  std::lock_guard<substrate::PaddedLock<true>> lg(lock);
69  if (!wl.empty()) {
70  if (popBack) {
71  retval = wl.back();
72  wl.pop_back();
73  } else {
74  retval = wl.front();
75  wl.pop_front();
76  }
77  }
78  return retval;
79  }
80 };
81 
82 template <typename T = int>
84 
85 template <typename T = int>
87 
88 template <typename T = int>
90 
91 template <typename T = int>
93 
98 
99 } // end namespace worklists
100 } // end namespace galois
101 
102 #endif
T value_type
Definition: Simple.h:47
galois::optional< value_type > pop()
Definition: Simple.h:66
Simple Container Wrapper worklist (not scalable).
Definition: Simple.h:36
void push(const value_type &val)
Definition: Simple.h:49
Galois version of boost::optional.
Definition: optional.h:34
static unsigned getTID()
Definition: ThreadPool.h:204
void push_initial(const RangeTy &range)
Definition: Simple.h:61
#define GALOIS_WLCOMPILECHECK(name)
Definition: WLCompileCheck.h:26
Definition: PaddedLock.h:35
void push(Iter b, Iter e)
Definition: Simple.h:55