android condition
2021/5/15 18:30:30
本文主要是介绍android condition,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
/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() must 11 * use the same mutex for a given Condition. 12 * 13 * On Android and Apple platforms, these are implemented as a simple wrapper 14 * around pthread condition variables. Care must be taken to abide by 15 * the pthreads semantics, in particular, a boolean predicate must 16 * 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 = 1 23 }; 24 25 enum WakeUpType { 26 WAKE_UP_ONE = 0, 27 WAKE_UP_ALL = 1 28 }; 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 timeout 37 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 #else 55 void* mState; 56 #endif 57 };
这篇关于android condition的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-26终极指南:Scrum中如何设置需求优先级
- 2024-06-26AI大模型企业应用实战(25)-为Langchain Agent添加记忆功能
- 2024-06-26小白家庭 nas 搭建方案-icode9专业技术文章分享
- 2024-06-23AI大模型企业应用实战(14)-langchain的Embedding
- 2024-06-23AI大模型企业应用实战(15)-langchain核心组件
- 2024-06-23AI大模型企业应用实战(16)-langchain核心组件
- 2024-06-23AI 大模型企业应用实战(06)-初识LangChain
- 2024-06-19EntBot.ai: AI Website Chatbot for Product Guides and Development Doc
- 2024-06-17zero-shot-learning-definition-examples-comparison
- 2024-06-06Package Easy(基于 NSIS 的打包exe安装包工具)使用方法-icode9专业技术文章分享