android condition

android condition,第1张

概述/system/core/libutils/include/utils/Condition.h 1//---------------------------------------------------------------------------23//DONOTUSE:pleaseusestd::condition_variableinstead.45/*6*Conditionvariableclass.Theimplement

/system/core/libutils/include/utils/Condition.h

 

 1 // --------------------------------------------------------------------------- 2  3 // DO NOT USE: please use std::condition_variable instead. 4  5 /* 6  * Condition variable class.  The implementation is system-dependent. 7  * 8  * Condition variables are paired up with mutexes.  Lock the mutex, 9  * call wait(), then either re-wait() if things aren't quite what you want,10  * or unlock the mutex and continue.  All threads calling wait() must11  * use the same mutex for a given Condition.12  *13  * On AndroID and Apple platforms, these are implemented as a simple wrapper14  * around pthread condition variables.  Care must be taken to abIDe by15  * the pthreads semantics, in particular, a boolean predicate must16  * be re-evaluated after a wake-up, as spurIoUs wake-ups may happen.17  */18 class Condition {19 public:20     enum {21         PRIVATE = 0,22         SHARED = 123     };24 25     enum WakeUpType {26         WAKE_UP_ONE = 0,27         WAKE_UP_ALL = 128     };29 30     Condition();31     explicit Condition(int type);32     ~Condition();33     // Wait on the condition variable.  Lock the mutex before calling.34     // Note that spurIoUs wake-ups may happen.35     status_t wait(Mutex& mutex);36     // same with relative timeout37     status_t waitrelative(Mutex& mutex, nsecs_t reltime);38     // Signal the condition variable, allowing one thread to continue.39     voID signal();40     // Signal the condition variable, allowing one or all threads to continue.41     voID signal(WakeUpType type) {42         if (type == WAKE_UP_ONE) {43             signal();44         } else {45             broadcast();46         }47     }48     // Signal the condition variable, allowing all threads to continue.49     voID broadcast();50 51 private:52 #if !defined(_WIN32)53     pthread_cond_t mCond;54 #else55     voID*   mState;56 #endif57 };

 

总结

以上是内存溢出为你收集整理的android condition全部内容,希望文章能够帮你解决android condition所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1004921.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存