Esempio n. 1
0
void RemoteDisplayClient::onDisplayError(int32_t error) {
    ALOGI("onDisplayError error=%d", error);

    Mutex::Autolock autoLock(mLock);
    mDone = true;
    mCondition.broadcast();
}
Esempio n. 2
0
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;
}
Esempio n. 3
0
void RemoteDisplayClient::onDisplayDisconnected() {
    ALOGI("onDisplayDisconnected");

    Mutex::Autolock autoLock(mLock);
    mDone = true;
    mCondition.broadcast();
}
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());
}
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());
}
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;
    }
}
Esempio n. 7
0
    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();
      }
    }
Esempio n. 8
0
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());
}
Esempio n. 9
0
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;
}
Esempio n. 10
0
void SkEvent::SignalNonEmptyQueue()
{
    gEventQCondition.broadcast();
}
Esempio n. 11
0
/*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
}
Esempio n. 12
0
/* 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;
}