Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 0fc6b6c in mainline


Ignore:
Timestamp:
2019-07-01T14:52:42Z (16 months ago)
Author:
Jaroslav Jindrak <dzejrou@…>
Branches:
master
Children:
a552044
Parents:
0d299c93
Message:

cpp: make sure that promise::get_future increments the refcount since the state is shared between the future and the promise

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/__bits/thread/promise.hpp

    r0d299c93 r0fc6b6c  
    162162            future<R> get_future()
    163163            {
     164                assert(this->state_);
     165
     166                /**
     167                 * Note: Future constructor that takes a shared
     168                 *       state as its argument does not call increment
     169                 *       because a future can be created as the only
     170                 *       owner of that state (e.g. when created by
     171                 *       std::async), so we have to do it here.
     172                 */
     173                this->state_->increment();
     174
    164175                return future<R>{this->state_};
    165176            }
     
    253264            future<R&> get_future()
    254265            {
     266                assert(this->state_);
     267
     268                /**
     269                 * Note: Future constructor that takes a shared
     270                 *       state as its argument does not call increment
     271                 *       because a future can be created as the only
     272                 *       owner of that state (e.g. when created by
     273                 *       std::async), so we have to do it here.
     274                 */
     275                this->state_->increment();
     276
    255277                return future<R&>{this->state_};
    256278            }
     
    315337            future<void> get_future()
    316338            {
     339                assert(this->state_);
     340
     341                /**
     342                 * Note: Future constructor that takes a shared
     343                 *       state as its argument does not call increment
     344                 *       because a future can be created as the only
     345                 *       owner of that state (e.g. when created by
     346                 *       std::async), so we have to do it here.
     347                 */
     348                this->state_->increment();
     349
    317350                return future<void>{this->state_};
    318351            }
Note: See TracChangeset for help on using the changeset viewer.