Vuo  2.3.2
VuoModuleCompilationQueue.cc
Go to the documentation of this file.
1 
11 
12 const int VuoModuleCompilationQueue::maxConcurrentCompilations = 8;
13 
18 {
19  sourceFile = nullptr;
20  loadingGroup = nullptr;
21 }
22 
27 {
28  return (priority.first != other->priority.first ?
29  (priority.first < other->priority.first) :
30  (priority.second < other->priority.second));
31 }
32 
37 {
38 }
39 
44 {
45  std::unique_lock<std::mutex> lock(queueMutex);
46 
47  queue[item->sourcePath].push_back({item, false});
48 }
49 
56 {
57  Item *item = nullptr;
58 
59  std::unique_lock<std::mutex> lock(queueMutex);
60  queueChanged.wait(lock, [this, &item]()
61  {
62  int concurrentCompilations = 0;
63 
64  // Select the highest-priority item that is not already being compiled (if any).
65  auto selectedIter = queue.end();
66  for (auto i = queue.begin(); i != queue.end(); ++i)
67  {
68  if (! ripeItemIsCompiling(i) &&
69  (selectedIter == queue.end() || ripeItem(i)->hasHigherPriority(ripeItem(selectedIter))))
70  selectedIter = i;
71 
72  if (ripeItemIsCompiling(i))
73  ++concurrentCompilations;
74  }
75 
76  // If an item was selected and we haven't already reached the limit of concurrent compilations, return the item.
77  if (selectedIter != queue.end() && concurrentCompilations < maxConcurrentCompilations)
78  {
79  item = ripeItem(selectedIter);
80  ripeItemIsCompiling(selectedIter) = true;
81  return true;
82  }
83 
84  return false;
85  });
86 
87  return item;
88 }
89 
94 {
95  std::unique_lock<std::mutex> lock(queueMutex);
96 
97  auto i = queue.find(item->sourcePath);
98  pluckRipeItem(i);
99 
100  queueChanged.notify_one();
101 }
102 
107 VuoModuleCompilationQueue::Item * VuoModuleCompilationQueue::ripeItem(map<string, list< pair<Item *, bool> > >::iterator iter)
108 {
109  return iter->second.front().first;
110 }
111 
116 bool& VuoModuleCompilationQueue::ripeItemIsCompiling(map<string, list< pair<Item *, bool> > >::iterator iter)
117 {
118  return iter->second.front().second;
119 }
120 
124 void VuoModuleCompilationQueue::pluckRipeItem(map<string, list< pair<Item *, bool> > >::iterator iter)
125 {
126  delete iter->second.front().first;
127  iter->second.pop_front();
128 
129  if (iter->second.empty())
130  queue.erase(iter);
131 }