Go to the documentation of this file.
21 _future_state(FS_pending) {
49 _done_event = done_event;
68 nassertr_always(
done(),
nullptr);
85 ref_ptr = _result_ref.p();
125 if (futures.empty()) {
127 fut->_future_state = (AtomicAdjust::Integer)FS_finished;
129 }
else if (futures.size() == 1) {
130 return futures[0].p();
141 INLINE
bool AsyncFuture::
143 return set_future_state(FS_locked_pending);
149 INLINE
void AsyncFuture::
150 unlock(FutureState new_state) {
151 nassertv(new_state != FS_locked_pending);
152 FutureState orig_state = (FutureState)
AtomicAdjust::set(_future_state, (AtomicAdjust::Integer)new_state);
153 nassertv(orig_state == FS_locked_pending);
162 INLINE
bool AsyncFuture::
163 set_future_state(FutureState state) {
164 FutureState orig_state = (FutureState)
167 (AtomicAdjust::Integer)FS_pending,
168 (AtomicAdjust::Integer)state);
170 while (orig_state == FS_locked_pending) {
174 (AtomicAdjust::Integer)FS_pending,
175 (AtomicAdjust::Integer)state);
178 return orig_state == FS_pending;
186 return _futures.size();
194 nassertr(i < _futures.size(),
nullptr);
195 return _futures[i].p();
203 nassertr(i < _futures.size(),
nullptr);
204 return _futures[i]->get_result();
bool cancelled() const
Returns true if the future was cancelled.
static Integer get(const Integer &var)
Atomically retrieves the snapshot value of the indicated variable.
static Integer compare_and_exchange(Integer &mem, Integer old_value, Integer new_value)
Atomic compare and exchange.
A base class for all things that want to be reference-counted.
Specific future that collects the results of several futures.
AsyncFuture * get_future(size_t i) const
Returns the nth future that was passed into the constructor.
AsyncFuture()
Initializes the future in the pending state.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
TypedWritableReferenceCount * get_ptr() const
Retrieves a pointer to the actual value stored in the parameter.
This class represents a thread-safe handle to a promised future result of an asynchronous operation,...
static AsyncFuture * gather(Futures futures)
Creates a new future that returns `done()` when all of the contained futures are done.
get_done_event
Returns the event name that will be triggered when the future finishes.
size_t get_num_futures() const
Returns the number of futures that were passed to the constructor.
TypedObject * get_result() const
Returns this future's result.
set_done_event
Sets the event name that will be triggered when the future finishes.
void set_result(std::nullptr_t)
Sets this future's result.
bool done() const
Returns true if the future is done or has been cancelled.
static Integer set(Integer &var, Integer new_value)
Atomically changes the indicated variable and returns the original value.
An optional parameter associated with an event.
A base class for things which need to inherit from both TypedWritable and from ReferenceCount.
static void force_yield()
Suspends the current thread for the rest of the current epoch.
This is an abstract class that all classes which use TypeHandle, and also provide virtual functions t...