1616#include " llvm/Config/llvm-config.h"
1717#include " llvm/Support/Compiler.h"
1818#include " llvm/Support/Debug.h"
19- #include " llvm/Support/ExtensibleRTTI.h"
2019#include " llvm/Support/ErrorHandling.h"
20+ #include " llvm/Support/ExtensibleRTTI.h"
2121#include " llvm/Support/raw_ostream.h"
2222
2323#include < atomic>
@@ -122,23 +122,23 @@ class LLVM_ABI TaskDispatcher {
122122 virtual void shutdown () = 0;
123123
124124 // / Work on dispatched tasks until the given future is ready.
125- virtual void work_until (future_base& F) = 0;
125+ virtual void work_until (future_base & F) = 0;
126126};
127127
128128// / Runs all tasks on the current thread.
129129class LLVM_ABI InPlaceTaskDispatcher : public TaskDispatcher {
130130public:
131131 void dispatch (std::unique_ptr<Task> T) override ;
132132 void shutdown () override ;
133- void work_until (future_base& F) override ;
133+ void work_until (future_base & F) override ;
134134
135135private:
136136 thread_local static SmallVector<std::unique_ptr<Task>> TaskQueue;
137-
137+
138138#if LLVM_ENABLE_THREADS
139139 std::mutex DispatchMutex;
140140 std::condition_variable WorkFinishedCV;
141- SmallVector<future_base*> WaitingFutures;
141+ SmallVector<future_base *> WaitingFutures;
142142#endif
143143};
144144
@@ -152,7 +152,8 @@ class LLVM_ABI DynamicThreadPoolTaskDispatcher : public TaskDispatcher {
152152
153153 void dispatch (std::unique_ptr<Task> T) override ;
154154 void shutdown () override ;
155- void work_until (future_base& F) override ;
155+ void work_until (future_base &F) override ;
156+
156157private:
157158 bool canRunMaterializationTaskNow ();
158159 bool canRunIdleTaskNow ();
@@ -171,26 +172,24 @@ class LLVM_ABI DynamicThreadPoolTaskDispatcher : public TaskDispatcher {
171172#endif // LLVM_ENABLE_THREADS
172173
173174// / Status for future/promise state
174- enum class FutureStatus : uint8_t {
175- NotReady = 0 ,
176- Ready = 1 ,
177- NotValid = 2
178- };
175+ enum class FutureStatus : uint8_t { NotReady = 0 , Ready = 1 , NotValid = 2 };
179176
180177// / Type-erased base class for futures
181178class future_base {
182179public:
183180 bool is_ready () const {
184- return state_->status_ .load (std::memory_order_acquire) != FutureStatus::NotReady;
181+ return state_->status_ .load (std::memory_order_acquire) !=
182+ FutureStatus::NotReady;
185183 }
186184
187185 // / Check if the future is in a valid state (not moved-from and not consumed)
188186 bool valid () const {
189- return state_ && state_->status_ .load (std::memory_order_acquire) != FutureStatus::NotValid;
187+ return state_ && state_->status_ .load (std::memory_order_acquire) !=
188+ FutureStatus::NotValid;
190189 }
191190
192191 // / Wait for the future to be ready, helping with task dispatch
193- void wait (TaskDispatcher& D) {
192+ void wait (TaskDispatcher & D) {
194193 // Keep helping with task dispatch until our future is ready
195194 if (!is_ready ())
196195 D.work_until (*this );
@@ -202,19 +201,19 @@ class future_base {
202201 std::atomic<FutureStatus> status_{FutureStatus::NotReady};
203202 };
204203
205- future_base (state_base* state) : state_(state) {}
204+ future_base (state_base * state) : state_(state) {}
206205 future_base () = default ;
207- ~future_base () {
206+ ~future_base () {
208207 if (valid ())
209208 report_fatal_error (" get() must be called before future destruction" );
210- delete state_;
209+ delete state_;
211210 }
212211
213212 // Move constructor and assignment
214- future_base (future_base&& other) noexcept : state_(other.state_) {
213+ future_base (future_base && other) noexcept : state_(other.state_) {
215214 other.state_ = nullptr ;
216215 }
217- future_base& operator =(future_base&& other) noexcept {
216+ future_base & operator =(future_base && other) noexcept {
218217 if (this != &other) {
219218 delete state_;
220219 state_ = other.state_ ;
@@ -223,87 +222,85 @@ class future_base {
223222 return *this ;
224223 }
225224
226- state_base* state_;
225+ state_base * state_;
227226};
228227
229228// / ORC-aware future class that can help with task dispatch while waiting
230229
231230template <typename T> class future ;
232231template <typename T> class promise ;
233- template <typename T>
234- class future : public future_base {
232+ template <typename T> class future : public future_base {
235233public:
236234 struct state : public future_base ::state_base {
237- template <typename U>
238- struct value_storage {
235+ template <typename U> struct value_storage {
239236 U value_;
240237 };
241-
242- template <>
243- struct value_storage <void > {
238+
239+ template <> struct value_storage <void > {
244240 // No value_ member for void
245241 };
246-
242+
247243 value_storage<T> storage;
248244 };
249245
250246 future () = delete ;
251- future (const future&) = delete ;
252- future& operator =(const future&) = delete ;
253- future (future&&) = default ;
254- future& operator =(future&&) = default ;
247+ future (const future &) = delete ;
248+ future & operator =(const future &) = delete ;
249+ future (future &&) = default ;
250+ future & operator =(future &&) = default ;
255251
256252 // / Get the value, helping with task dispatch while waiting.
257253 // / This will destroy the underlying value, so this must only be called once.
258- T get (TaskDispatcher& D) {
254+ T get (TaskDispatcher & D) {
259255 if (!valid ())
260256 report_fatal_error (" get() must only be called once" );
261257 wait (D);
262- auto old_status = state_->status_ .exchange (FutureStatus::NotValid, std::memory_order_release);
258+ auto old_status = state_->status_ .exchange (FutureStatus::NotValid,
259+ std::memory_order_release);
263260 if (old_status != FutureStatus::Ready)
264261 report_fatal_error (" get() must only be called once" );
265262 return take_value ();
266263 }
267264
268265private:
269266 friend class promise <T>;
270-
267+
271268 template <typename U = T>
272269 typename std::enable_if<!std::is_void<U>::value, U>::type take_value () {
273- return std::move (static_cast <typename future<T>::state*>(state_)->storage .value_ );
270+ return std::move (
271+ static_cast <typename future<T>::state *>(state_)->storage .value_ );
274272 }
275-
273+
276274 template <typename U = T>
277275 typename std::enable_if<std::is_void<U>::value, U>::type take_value () {}
278276
279- explicit future (state* state) : future_base(state) {}
277+ explicit future (state * state) : future_base(state) {}
280278};
281279
282280// / ORC-aware promise class that works with ORC future
283- template <typename T>
284- class promise {
281+ template <typename T> class promise {
285282 friend class future <T>;
286-
283+
287284public:
288285 promise () : state_(new typename future<T>::state()), future_created_(false ) {}
289-
286+
290287 ~promise () {
291288 // Delete state only if get_future() was never called
292289 if (!future_created_) {
293290 delete state_;
294291 }
295292 }
296-
297- promise (const promise&) = delete ;
298- promise& operator =(const promise&) = delete ;
299-
300- promise (promise&& other) noexcept
301- : state_(other.state_), future_created_(other.future_created_) {
293+
294+ promise (const promise &) = delete ;
295+ promise & operator =(const promise &) = delete ;
296+
297+ promise (promise && other) noexcept
298+ : state_(other.state_), future_created_(other.future_created_) {
302299 other.state_ = nullptr ;
303300 other.future_created_ = false ;
304301 }
305-
306- promise& operator =(promise&& other) noexcept {
302+
303+ promise & operator =(promise && other) noexcept {
307304 if (this != &other) {
308305 if (!future_created_) {
309306 delete state_;
@@ -329,24 +326,29 @@ class promise {
329326 // but that if the user calls set_value(v) for any value v that they get a
330327 // member function error, instead of no member named 'value_'.
331328 template <typename U = T>
332- void set_value (const typename std::conditional<std::is_void<T>::value, std::nullopt_t , T>::type& value) {
329+ void
330+ set_value (const typename std::conditional<std::is_void<T>::value,
331+ std::nullopt_t , T>::type &value) {
333332 assert (state_ && " Invalid promise state" );
334333 state_->storage .value_ = value;
335334 state_->status_ .store (FutureStatus::Ready, std::memory_order_release);
336335 }
337-
336+
338337 template <typename U = T>
339- void set_value (typename std::conditional<std::is_void<T>::value, std::nullopt_t , T>::type&& value) {
338+ void set_value (typename std::conditional<std::is_void<T>::value,
339+ std::nullopt_t , T>::type &&value) {
340340 assert (state_ && " Invalid promise state" );
341341 state_->storage .value_ = std::move (value);
342342 state_->status_ .store (FutureStatus::Ready, std::memory_order_release);
343343 }
344344
345345 template <typename U = T>
346- typename std::enable_if<std::is_void<U>::value, void >::type set_value (const std::nullopt_t & value) = delete;
346+ typename std::enable_if<std::is_void<U>::value, void >::type
347+ set_value (const std::nullopt_t &value) = delete ;
347348
348349 template <typename U = T>
349- typename std::enable_if<std::is_void<U>::value, void >::type set_value (std::nullopt_t && value) = delete;
350+ typename std::enable_if<std::is_void<U>::value, void >::type
351+ set_value (std::nullopt_t &&value) = delete ;
350352
351353 template <typename U = T>
352354 typename std::enable_if<std::is_void<U>::value, void >::type set_value () {
@@ -355,14 +357,14 @@ class promise {
355357 }
356358
357359 // / Swap with another promise
358- void swap (promise& other) noexcept {
360+ void swap (promise & other) noexcept {
359361 using std::swap;
360362 swap (state_, other.state_ );
361363 swap (future_created_, other.future_created_ );
362364 }
363365
364366private:
365- typename future<T>::state* state_;
367+ typename future<T>::state * state_;
366368 bool future_created_;
367369};
368370
@@ -371,7 +373,7 @@ class promise {
371373
372374namespace std {
373375template <typename T>
374- void swap (llvm::orc::promise<T>& lhs, llvm::orc::promise<T>& rhs) noexcept {
376+ void swap (llvm::orc::promise<T> & lhs, llvm::orc::promise<T> & rhs) noexcept {
375377 lhs.swap (rhs);
376378}
377379} // End namespace std
0 commit comments