CountDownLatch.h revision cd139dc7
1cd139dc7SShuo Chen// excerpts from http://code.google.com/p/muduo/ 2cd139dc7SShuo Chen// 3cd139dc7SShuo Chen// Use of this source code is governed by a BSD-style license 4cd139dc7SShuo Chen// that can be found in the License file. 5cd139dc7SShuo Chen// 6cd139dc7SShuo Chen// Author: Shuo Chen (giantchen at gmail dot com) 7cd139dc7SShuo Chen 8cd139dc7SShuo Chen#ifndef MUDUO_BASE_COUNTDOWNLATCH_H 9cd139dc7SShuo Chen#define MUDUO_BASE_COUNTDOWNLATCH_H 10cd139dc7SShuo Chen 11cd139dc7SShuo Chen#include "Mutex.h" 12cd139dc7SShuo Chen#include "Condition.h" 13cd139dc7SShuo Chen 14cd139dc7SShuo Chen#include <boost/noncopyable.hpp> 15cd139dc7SShuo Chen 16cd139dc7SShuo Chennamespace muduo 17cd139dc7SShuo Chen{ 18cd139dc7SShuo Chen 19cd139dc7SShuo Chenclass CountDownLatch : boost::noncopyable 20cd139dc7SShuo Chen{ 21cd139dc7SShuo Chen public: 22cd139dc7SShuo Chen 23cd139dc7SShuo Chen CountDownLatch(int count); 24cd139dc7SShuo Chen 25cd139dc7SShuo Chen void wait(); 26cd139dc7SShuo Chen 27cd139dc7SShuo Chen void countDown(); 28cd139dc7SShuo Chen 29cd139dc7SShuo Chen int getCount() const; 30cd139dc7SShuo Chen 31cd139dc7SShuo Chen private: 32cd139dc7SShuo Chen mutable MutexLock mutex_; 33cd139dc7SShuo Chen Condition condition_; 34cd139dc7SShuo Chen int count_; 35cd139dc7SShuo Chen}; 36cd139dc7SShuo Chen 37cd139dc7SShuo Chen} 38cd139dc7SShuo Chen#endif // MUDUO_BASE_COUNTDOWNLATCH_H 39