本文整理汇总了C++中Condition::broadcast方法的典型用法代码示例。如果您正苦于以下问题:C++ Condition::broadcast方法的具体用法?C++ Condition::broadcast怎么用?C++ Condition::broadcast使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Condition
的用法示例。
在下文中一共展示了Condition::broadcast方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: onDisplayError
void RemoteDisplayClient::onDisplayError(int32_t error) {
ALOGI("onDisplayError error=%d", error);
Mutex::Autolock autoLock(mLock);
mDone = true;
mCondition.broadcast();
}
示例2: timer_event_thread_proc
static void* timer_event_thread_proc(void*)
{
for (;;)
{
int status;
pthread_mutex_lock(&gTimerMutex);
timespec spec = gTimeSpec;
// mark our global to be zero
// so we don't call timedwait again on a stale value
gTimeSpec.tv_sec = 0;
gTimeSpec.tv_nsec = 0;
if (spec.tv_sec == 0 && spec.tv_nsec == 0)
status = pthread_cond_wait(&gTimerCond, &gTimerMutex);
else
status = pthread_cond_timedwait(&gTimerCond, &gTimerMutex, &spec);
if (status == 0) // someone signaled us with a new time
{
pthread_mutex_unlock(&gTimerMutex);
}
else
{
SkASSERT(status == ETIMEDOUT); // no need to unlock the mutex (its unlocked)
// this is the payoff. Signal the event queue to wake up
// and also check the delay-queue
gEventQCondition.broadcast();
}
}
return 0;
}
示例3: onDisplayDisconnected
void RemoteDisplayClient::onDisplayDisconnected() {
ALOGI("onDisplayDisconnected");
Mutex::Autolock autoLock(mLock);
mDone = true;
mCondition.broadcast();
}
示例4: _lock
void
ImageCreateThread::
postCommand(Command const& rCmd)
{
Mutex::Autolock _lock(mCmdQueMtx);
//
if ( ! mCmdQue.empty() )
{
Command const& rBegCmd = *mCmdQue.begin();
MY_LOGW("que size:%d > 0 with begin Command::%s", mCmdQue.size(), rBegCmd.name());
}
//
mCmdQue.push_back(rCmd);
mCmdQueCond.broadcast();
//
MY_LOGD("- new command::%s", rCmd.name());
}
示例5: _lock
void
DisplayDelayThread::
postCommand(Command const& rCmd)
{
Mutex::Autolock _lock(mCmdQueMtx);
//
if ( ! mCmdQue.empty() )
{
Command const& rBegCmd = *mCmdQue.begin();
MY_LOGW("que size:%d > 0 with begin cmd::%s", mCmdQue.size(), rBegCmd.name());
}
//
mCmdQue.push_back(rCmd);
mCmdQueCond.broadcast();
//
MY_LOGD_IF(ENABLE_LOG_PER_FRAME, "- new command::%s", rCmd.name());
}
示例6: broadcast
bool CondManager::broadcast(string condName, vector<unsigned>& threads, string& errorMsg) {
Condition* cond = getCondition(condName);
if (cond == NULL) {
errorMsg = "condition " + condName + " undefined";
return false;
} else {
vector<WaitParam*> itemList;
cond->broadcast(itemList);
threads.resize(itemList.size());
vector<unsigned>::iterator ti = threads.begin();
for (vector<WaitParam*>::iterator wi = itemList.begin(), we = itemList.end(); wi != we; wi++, ti++) {
WaitParam* wp = *wi;
*ti = wp->threadId;
mutexManager->addBlockedThread(wp->threadId, wp->mutexName);
delete wp;
}
return true;
}
}
示例7: process
virtual void process(const mpi::Address &source, void *message, int32 size)
{
if (size == 4) {
mutex.lock();
numTerminated++;
cond.broadcast();
mutex.unlock();
free(message);
return;
}
if (checkSum) {
// -------------------------------------------------------
// checksum
// -------------------------------------------------------
int *msg = (int *)message;
int N = size/sizeof(int);
int checkSum = computeCheckSum1toN(msg,N);
if (msg[0] != checkSum)
throw std::runtime_error("invalid checksum!");
free(message);
mutex.lock();
numMessagesReceived ++;
numBytesReceived += size;
if (!shutDown) {
int tgt = rand() % source.group->size;
sendRandomMessage(mpi::Address(source.group,tgt));
}
mutex.unlock();
} else {
mutex.lock();
numMessagesReceived ++;
numBytesReceived += size;
if (!shutDown) {
int tgt = rand() % source.group->size;
mpi::async::send(mpi::Address(source.group,tgt),message,size);
}
mutex.unlock();
}
}
示例8: testBroadcast
void ConditionTest::testBroadcast()
{
Condition cond;
Mutex mtx;
WaitRunnable r1(cond, mtx);
WaitRunnable r2(cond, mtx);
TryWaitRunnable r3(cond, mtx);
Thread t1;
Thread t2;
Thread t3;
t1.start(r1);
Thread::sleep(200);
t2.start(r2);
Thread::sleep(200);
t3.start(r3);
assert (!r1.ran());
assert (!r2.ran());
assert (!r3.ran());
cond.signal();
t1.join();
assert (r1.ran());
assert (!t2.tryJoin(500));
assert (!t3.tryJoin(500));
cond.broadcast();
t2.join();
t3.join();
assert (r2.ran());
assert (r3.ran());
}
示例9: profile
bool
RawDumpCmdQueThread::
postCommand(IImageBuffer const * pImgBuffer)
{
FUNCTION_IN;
//
bool ret = true;
CamProfile profile(__FUNCTION__, "RawDumpCmdQueThread::postCommand");
//
{
Mutex::Autolock _l(mCmdMtx);
// add frame count for remember what frame it is.
mFrameCnt++;
//
if (NULL == pImgBuffer)
{
MY_LOGD("- Requester stop to dump: tid(%d), frame_count(%d), Q size(%d)", FREE_MEMORY_THRESHOLD, ::gettid(), mFrameCnt, mCmdQ.size());
mpCamMsgCbInfo->mNotifyCb(MTK_CAMERA_MSG_EXT_NOTIFY, MTK_CAMERA_MSG_EXT_NOTIFY_RAW_DUMP_STOPPED, 0, mpCamMsgCbInfo->mCbCookie);
return false;
}
MY_LOGD("+ tid(%d), frame_count (%d), buf_addr(%p), stride(%d), buf_size(%d), free(%d)",
::gettid(), mFrameCnt, pImgBuffer->getBufVA(0), pImgBuffer->getBufStridesInBytes(0), pImgBuffer->getBufSizeInBytes(0),
getFreeMemorySize());
//
if (!mCmdQ.empty())
{
MY_LOGD("queue is not empty, (%d) is in the head of queue, Q size (%d)", ((*mCmdQ.begin())->getFrameCnt()), mCmdQ.size());
}
// check if the memory threshold is enough
if ( FREE_MEMORY_THRESHOLD > getFreeMemorySize())
{
MY_LOGD("- Memory is under:%d: RAW DUMP IS STOPPED: tid(%d), frame_count(%d), Q size(%d)", FREE_MEMORY_THRESHOLD, ::gettid(), mFrameCnt, mCmdQ.size());
mpCamMsgCbInfo->mNotifyCb(MTK_CAMERA_MSG_EXT_NOTIFY, MTK_CAMERA_MSG_EXT_NOTIFY_RAW_DUMP_STOPPED, 0, mpCamMsgCbInfo->mCbCookie);
return false;
}
//
MUINT32 u4RealRawSize = pImgBuffer->getBufStridesInBytes(0) * pImgBuffer->getImgSize().h;
MUINT8 *pbuf = (MUINT8*) malloc (u4RealRawSize);
if (NULL == pbuf)
{
MY_LOGW("tid(%d) fail to allocate memory, frame_count (%d), buf_addr(%p), buf_size(%d)",
::gettid(), mFrameCnt, pImgBuffer->getBufVA(0), u4RealRawSize);
return false;
}
//
memcpy(pbuf,(MUINT8*)pImgBuffer->getBufVA(0), u4RealRawSize);
//
sp<RawDumpCmdCookie> cmdCookie(new RawDumpCmdCookie(mFrameCnt, new RawImageBufInfo(pImgBuffer->getImgSize().w,
pImgBuffer->getImgSize().h,
pImgBuffer->getBufStridesInBytes(0),
(MUINTPTR)pbuf,
u4RealRawSize,
pImgBuffer->getTimestamp()
)
, mspParamsMgr->getStr(MtkCameraParameters::KEY_RAW_PATH)));
mCmdQ.push_back(cmdCookie);
mCmdCond.broadcast();
MY_LOGD("- frame added: tid(%d), frame_count(%d), que size(%d)", ::gettid(), mFrameCnt, mCmdQ.size());
}
//
profile.print();
FUNCTION_OUT;
//
return ret;
}
示例10: SignalNonEmptyQueue
void SkEvent::SignalNonEmptyQueue()
{
gEventQCondition.broadcast();
}
示例11: xUNUSED
/*virtual*/
void_t
Test_Condition::unit(
culonglong_t &a_caseLoops
)
{
xUNUSED(a_caseLoops);
#if xENV_UNIX && xTODO
int_t iRv = - 1;
pthread_t thThreads[3] = {0};
clong_t liId1 = 1L;
clong_t liId2 = 2L;
clong_t liId3 = 3L;
// initialize
{
iRv = ::pthread_mutex_init(&g_mtMutex, xPTR_NULL); // mutex not recursive
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
iRv = ::pthread_cond_init(&g_cndCondition, xPTR_NULL);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
// for portability, explicitly create threads in a joinable state
pthread_attr_t atAttr /* = {{0}} */;
iRv = ::pthread_attr_init(&atAttr);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
iRv = ::pthread_attr_setdetachstate(&atAttr, PTHREAD_CREATE_JOINABLE);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
iRv = ::pthread_create(&thThreads[0], &atAttr, pvWatch, (void_t *)&liId1);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
iRv = ::pthread_create(&thThreads[1], &atAttr, pvJob, (void_t *)&liId2);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
iRv = ::pthread_create(&thThreads[2], &atAttr, pvJob, (void_t *)&liId3);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
iRv = ::pthread_attr_destroy(&atAttr);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
}
// wait for all threads to complete
for (size_t i = 0; i < g_cuiThreadsNum; ++ i) {
iRv = ::pthread_join(thThreads[i], xPTR_NULL);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
}
#if 0
Tracer() << xT("Main(): waited on ") << g_cuiThreadsNum << xT(" threads. Done");
#endif
// clean up
{
iRv = ::pthread_cond_destroy(&g_cndCondition);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
iRv = ::pthread_mutex_destroy(&g_mtMutex);
xTEST_MSG_EQ(0, iRv, NativeError::format(iRv));
}
// ::exit(0);
#if xTEMP_DISABLED
Condition cond;
cond.mutex();
cond.handle();
cond.create();
cond.wait(5000UL);
cond.signal();
cond.broadcast();
#endif
#endif // xENV_UNIX
}
示例12:
/* virtual */
bool_t
Test_Condition::unit()
{
#if xENV_UNIX
int_t iRv = - 1;
pthread_t threads[3] = {0};
clong_t id1 = 1L;
clong_t id2 = 2L;
clong_t id3 = 3L;
// initialize
{
iRv = ::pthread_mutex_init(&::mtMutex, xPTR_NULL); // mutex not recursive
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
iRv = ::pthread_cond_init(&::cndCondition, xPTR_NULL);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
// for portability, explicitly create threads in a joinable state
pthread_attr_t attr;
iRv = ::pthread_attr_init(&attr);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
iRv = ::pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
iRv = ::pthread_create(&threads[0], &attr, watch, (void_t *)&id1);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
iRv = ::pthread_create(&threads[1], &attr, job, (void_t *)&id2);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
iRv = ::pthread_create(&threads[2], &attr, job, (void_t *)&id3);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
iRv = ::pthread_attr_destroy(&attr);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
}
// wait for all threads to complete
{
Trace() << Format::str(xT("Main(): waited on {} threads..."), ::threadsNum);
for (size_t i = 0; i < ::threadsNum; ++ i) {
iRv = ::pthread_join(threads[i], xPTR_NULL);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
}
Trace() << Format::str(xT("Main(): waited on {} threads. Done"), ::threadsNum);
}
// clean up
{
iRv = ::pthread_cond_destroy(&::cndCondition);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
iRv = ::pthread_mutex_destroy(&::mtMutex);
xTEST_EQ_MSG(0, iRv, NativeError::format( static_cast<ulong_t>(iRv) ));
}
// ::exit(0);
#if xTEMP_DISABLED
Condition cond;
cond.mutex();
cond.handle();
cond.create();
cond.wait(5000UL);
cond.signal();
cond.broadcast();
#endif
#endif // xENV_UNIX
return true;
}