Ejemplo n.º 1
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;
}
Ejemplo n.º 2
0
bool
RawDumpCmdQueThread::
getCommand(sp<RawDumpCmdCookie> &rCmdCookie)
{
    FUNCTION_IN;
    //
    bool ret = false;
    //
    Mutex::Autolock _l(mCmdMtx);
    //
    MY_LOGD("+ tid(%d), que size(%d)", ::gettid(), mCmdQ.size());
    //
    while ( mCmdQ.empty() && ! exitPending() )
    {
        mCmdCond.wait(mCmdMtx);    
    }
    // get the latest frame, e.g. drop the 
    if ( !mCmdQ.empty() )
    {
        rCmdCookie = *mCmdQ.begin();
        mCmdQ.erase(mCmdQ.begin());
        ret = true;
        MY_LOGD(" frame[%d] in slot[%d] is dequeued.", rCmdCookie->getFrameCnt(),rCmdCookie->getFrameCnt() );
    }
    //
    MY_LOGD("- tid(%d), que size(%d), ret(%d)", ::gettid(), mCmdQ.size(), ret);
    //
    FUNCTION_OUT;
    //
    return ret;
}
Ejemplo n.º 3
0
//-----------------------------------------------------------------------------
MBOOL
CapBufMgrImp::
pushBuf(IImageBuffer* pImageBuffer, MBOOL const isFullSize)
{
    Mutex::Autolock _l(mLock);
    //
    MY_LOGD("(%d),Buf(0x%08X),TS(%d.%06d)",
            isFullSize,
            (MUINT32)pImageBuffer,
            (MUINT32)((pImageBuffer->getTimestamp()/1000)/1000000), 
            (MUINT32)((pImageBuffer->getTimestamp()/1000)%1000000));
    //
    mlpImgBuf.push_back(pImageBuffer);
    if(pImageBuffer->getTimestamp() > 0)
    {
        mCond.signal();
    }
    //
    if(!mbUse)
    {
        mbUse = MTRUE;
    }
    //
    return MTRUE;
}
Ejemplo n.º 4
0
//-----------------------------------------------------------------------------
MBOOL
CapBufMgrImp::
enqueBuf(IImageBuffer* pImageBuffer, MBOOL const isFullSize)
{
    Mutex::Autolock _l(mLock);
    //
    pImageBuffer->setTimestamp(0);
    //
    mlpImgBuf.push_back(pImageBuffer);
    if(mDequeBufCnt == 0)
    {
        MY_LOGE("mDequeBufCnt is 0");
    }
    else
    {
        mDequeBufCnt--;
    }
    //
    mCondDequeBuf.signal();
    //
    MY_LOGD("(%d),Buf(0x%08X),TS(%d.%06d),DBC(%d)",
            isFullSize,
            (MUINT32)pImageBuffer,
            (MUINT32)((pImageBuffer->getTimestamp()/1000)/1000000), 
            (MUINT32)((pImageBuffer->getTimestamp()/1000)%1000000),
            mDequeBufCnt);
    //
    return MTRUE;
}
Ejemplo n.º 5
0
//flushes current_, and leaves a new current in place, which might have some
//data left over from the last one.
void
DestThreadedBufferPriv::bufswap()
{
    ByteBuf * b = current_ ;
    current_ = NULL;
    ByteBufPtr prev = b ;
    {
        MutexGuard mg(lock_);
        if( puterr_ )
        {
            PANICV( errbuf_.c_str());
        }
        if( available_.empty())
        {
            flush_.wait( mg );
        }
        if( puterr_ )
        {
            PANICV( errbuf_.c_str());
        }
        if( available_.empty())
        {
            PANICV( "no buffers available after flush");
        }
        current_ = available_.front();
        available_.pop_front();
    }
    //put the unpushed portion of old current_ onto new one.
    current_->reset();
    writeq_->push( prev.release());
}
Ejemplo n.º 6
0
 void addJob(const blocking_job &job)
 {
     MutexGuard lock(&mutex_);
     queue_.push_back(job);
     
     cond_.notify();
 }
Ejemplo n.º 7
0
int main()
{
	SetConsoleTitle("Login server for Knight Online v" STRINGIFY(__VERSION));

#ifdef WIN32
	// Override the console handler
	SetConsoleCtrlHandler(_ConsoleHandler, TRUE);
#endif

	HookSignals(&s_hEvent);

	g_pMain = new LoginServer();

	// Startup server
	if (g_pMain->Startup())
	{
		printf("\nServer started up successfully!\n");

		// Wait until console's signaled as closing
		s_hEvent.Wait();
	}
	else
	{
#ifdef WIN32
		system("pause");
#endif
	}

	printf("Server shutting down, please wait...\n");

	delete g_pMain;
	UnhookSignals();

	return 0;
}
Ejemplo n.º 8
0
void RemoteDisplayClient::onDisplayError(int32_t error) {
    ALOGI("onDisplayError error=%d", error);

    Mutex::Autolock autoLock(mLock);
    mDone = true;
    mCondition.broadcast();
}
/* Updates an attribute that meets the condition
...With its new value						*/
void Database::update(string rname, vector<string> attributes, vector<_Data> newvalues, Condition& c)
{
	int indr = 0;
	for (indr = 0; indr < allRelations.size(); ++indr)
	{
		if (allRelations[indr].GetName() == rname)
			break;
	}

	_Relation r2 = *(c.evaluate(&allRelations[indr]));
	for (int i = 0; i < r2.Columns[0].Rows.size(); ++i) {
		for (int j = 0; j < allRelations[indr].Columns[0].Rows.size(); ++j) {
			bool upd = true;
			for (int k = 0; k < allRelations[indr].Columns.size(); ++i) {
				if (r2.Columns[k].Rows[i].Data != allRelations[indr].Columns[k].Rows[j].Data) {
					upd = false;
					break;
				}
			}
			if (upd == true) {
				for (int y = 0; y < attributes.size(); ++y) {
					for (int z = 0; z < allRelations[indr].Columns.size(); ++z) {
						if (attributes[y] == allRelations[indr].Columns[z].Name) {
							allRelations[indr].Columns[z].Rows[j] = newvalues[y];
						}
					}
				}
			}
		}
	}
}
bool
ImageCreateThread::
getCommand(Command& rCmd)
{
    bool ret = false;
    //
    Mutex::Autolock _lock(mCmdQueMtx);
    //
    MY_LOGD_IF(ENABLE_LOG_PER_FRAME, "+ que size(%d)", mCmdQue.size());
    //
    //  Wait until the queue is not empty or this thread will exit.
    while   ( mCmdQue.empty() && ! exitPending() )
    {
        status_t status = mCmdQueCond.wait(mCmdQueMtx);
        if  ( NO_ERROR != status )
        {
            MY_LOGW("wait status(%d), que size(%d), exitPending(%d)", status, mCmdQue.size(), exitPending());
        }
    }
    //
    if  ( ! mCmdQue.empty() )
    {
        //  If the queue is not empty, take the first command from the queue.
        ret = true;
        rCmd = *mCmdQue.begin();
        mCmdQue.erase(mCmdQue.begin());
        MY_LOGD("command:%s", rCmd.name());
    }
    //
    MY_LOGD_IF(ENABLE_LOG_PER_FRAME, "- que size(%d), ret(%d)", mCmdQue.size(), ret);
    return  ret;
}
Ejemplo n.º 11
0
void DatabaseThread::AddRequest(Packet * pkt)
{
	_lock.Acquire();
	_queue.push(pkt);
	_lock.Release();
	s_hEvent.Signal();
}
Ejemplo n.º 12
0
void RemoteDisplayClient::onDisplayDisconnected() {
    ALOGI("onDisplayDisconnected");

    Mutex::Autolock autoLock(mLock);
    mDone = true;
    mCondition.broadcast();
}
Ejemplo n.º 13
0
void gridStartIterateFiltered(int32_t x, int32_t y, uint32_t radius, PointTree::Filter *filter, Condition const &condition)
{
	if (filter == NULL)
	{
		gridPointTree->query(x, y, radius);
	}
	else
	{
		gridPointTree->query(*filter, x, y, radius);
	}
	PointTree::ResultVector::iterator w = gridPointTree->lastQueryResults.begin(), i;
	for (i = w; i != gridPointTree->lastQueryResults.end(); ++i)
	{
		BASE_OBJECT *obj = static_cast<BASE_OBJECT *>(*i);
		if (!condition.test(obj))  // Check if we should skip this object.
		{
			filter->erase(gridPointTree->lastFilteredQueryIndices[i - gridPointTree->lastQueryResults.begin()]);  // Stop the object from appearing in future searches.
		}
		else if (isInRadius(obj->pos.x - x, obj->pos.y - y, radius))  // Check that search result is less than radius (since they can be up to a factor of sqrt(2) more).
		{
			*w = *i;
			++w;
		}
	}
	gridPointTree->lastQueryResults.erase(w, i);  // Erase all points that were a bit too far.
	gridPointTree->lastQueryResults.push_back(NULL);  // NULL-terminate the result.
	gridIterator = &gridPointTree->lastQueryResults[0];
	/*
	// In case you are curious.
	debug(LOG_WARNING, "gridStartIterateFiltered(%d, %d, %u) found %u objects", x, y, radius, (unsigned)gridPointTree->lastQueryResults.size() - 1);
	*/
}
status_t MSurface::registerBuffers(const BufferHeap& buffers) {
    INFO(__func__);
    Mutex::Autolock _l(mLock);
    ++registerBuffersCount;
    mCond.signal();
    return NO_ERROR;
}
Ejemplo n.º 15
0
bool Combat::CombatConditionFunc(Creature* caster, Creature* target, const CombatParams& params, void*)
{
    bool result = false;
    for (const Condition* condition : params.conditionList) {
        if (caster == target || !target->isImmune(condition->getType())) {
            Condition* conditionCopy = condition->clone();
            if (caster) {
                conditionCopy->setParam(CONDITIONPARAM_OWNER, caster->getID());
            }

            //TODO: infight condition until all aggressive conditions has ended
            result = target->addCombatCondition(conditionCopy);
        }
    }
    return result;
}
Ejemplo n.º 16
0
void MagicField::onStepInField(Creature* creature)
{
	//remove magic walls/wild growth
	if(id == ITEM_MAGICWALL || id == ITEM_WILDGROWTH || id == ITEM_MAGICWALL_SAFE || id == ITEM_WILDGROWTH_SAFE || isBlocking())
	{
		if(!creature->isInGhostMode())
			 g_game.internalRemoveItem(this, 1);

		return;
	}

	const ItemType& it = items[getID()];
	if(it.condition)
	{
		Condition* conditionCopy = it.condition->clone();
		uint32_t ownerId = getOwner();
		if(ownerId)
		{
			bool harmfulField = true;
			if(g_game.getWorldType() == WORLD_TYPE_NO_PVP || getTile()->hasFlag(TILESTATE_NOPVPZONE))
			{
				Creature* owner = g_game.getCreatureByID(ownerId);
				if(owner)
				{
					if(owner->getPlayer() || (owner->isSummon() && owner->getMaster()->getPlayer()))
						harmfulField = false;
				}
			}

			Player* targetPlayer = creature->getPlayer();
			if(targetPlayer)
			{
				Player* attackerPlayer = g_game.getPlayerByID(ownerId);
				if(attackerPlayer)
				{
					if(Combat::isProtected(attackerPlayer, targetPlayer))
						harmfulField = false;
				}
			}

			if(!harmfulField || (OTSYS_TIME() - createTime <= 5000) || creature->hasBeenAttacked(ownerId))
				conditionCopy->setParam(CONDITIONPARAM_OWNER, ownerId);
		}

		creature->addCondition(conditionCopy);
	}
}
Ejemplo n.º 17
0
  ssize_t Socket_Impl::
    size_ (ACE_Time_Value const* timeout)
    {
      ACE_Time_Value abs_time;

      if (timeout)
        abs_time = ACE_OS::gettimeofday () + *timeout;

      Lock l (mutex_);

      while (queue_.is_empty ())
        {
          if (timeout)
            {
              if (cond_.wait (&abs_time) != -1)
                break;
            }
          else
            {
              if (cond_.wait () != -1)
                break;
            }

          return -1; // errno is already set
        }

      // I can't get the head of the queue without actually dequeuing
      // the element.
      //
      Message_ptr m;

      if (queue_.dequeue_head (m) == -1)
        ACE_OS::abort ();

      if (queue_.enqueue_head (m) == -1)
        ACE_OS::abort ();

      if (m->find (NoData::id) != 0)
        {
          errno = ENOENT;
          return -1;
        }

      Data const* d = static_cast<Data const*>(m->find (Data::id));

      return static_cast<ssize_t> (d->size ());
    }
Ejemplo n.º 18
0
 void operator()(void)
 {
    for(int i = 0; i < numThreads; ++i)
    {
       sleep(1);
       waitSignal.wakeAll();
    }
 }
Ejemplo n.º 19
0
void Creature::executeConditions(uint32_t interval)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end();){
		if(!(*it)->onTick(this, interval)){
			Condition* condition = *it;

			onEndCondition(condition);
			it = conditions.erase(it);
			condition->onEnd(this, CONDITIONEND_DURATION);
			onEndCondition(condition, false);
			delete condition;
		}
		else{
			++it;
		}
	}
}
Ejemplo n.º 20
0
void Creature::removeCondition(MechanicType type)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end();){
		if((*it)->getMechanicType() == type){
			Condition* condition = *it;

			onEndCondition(condition);
			it = conditions.erase(it);
			condition->onEnd(this, CONDITIONEND_REMOVED);
			onEndCondition(condition, false);
			delete condition;
		}
		else{
			++it;
		}
	}
}
Ejemplo n.º 21
0
void Creature::removeCondition(const std::string& name, uint32_t sourceId)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end();){
		if((*it)->getName() == name && (*it)->getSourceId() == sourceId){
			Condition* condition = *it;

			onEndCondition(condition);
			it = conditions.erase(it);
			condition->onEnd(this, CONDITIONEND_REMOVED);
			onEndCondition(condition, false);
			delete condition;
		}
		else{
			++it;
		}
	}
}
Ejemplo n.º 22
0
void * pthread_func(void* p){
	mutex.lock();
	cout<<"this is child thread"<<endl;
	cond.wait();
	cout<<"waking"<<endl;
	mutex.unlock();
	pthread_exit(NULL);
}
Ejemplo n.º 23
0
ThreadReturnType PEGASUS_THREAD_CDECL deq(void * parm)
{
    Thread* my_thread = (Thread *)parm;

    parmdef * Parm = (parmdef *)my_thread->get_parm();
    MessageType type;

    int first = Parm->first;
    int second = Parm->second;
    int count = Parm->count;
    Condition * condstart = Parm->cond_start;
    MessageQueue * mq = Parm->mq;

    condstart->signal();

    Message * message;
    type = 0;

    while (type != CLOSE_CONNECTION_MESSAGE)
    {
        message = mq->dequeue();
        while (!message)
        {
            message = mq->dequeue();
        }

        type = message->getType();
        delete message;
    }

    if (verbose)
    {
#if defined (PEGASUS_OS_VMS)
        //
        // Threads::self returns long-long-unsigned.
        //
        printf("Received Cancel Message, %llu about to end\n", Threads::self());
#else
        cout << "Received Cancel Message, " << Threads::self() <<
            " about to end\n";
#endif
    }

    return ThreadReturnType(0);
}
Ejemplo n.º 24
0
void Creature::removeConditions(ConditionEnd_t reason, bool onlyPersistent/* = true*/)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end(); )
	{
		if(onlyPersistent && !(*it)->isPersistent())
		{
			++it;
			continue;
		}

		Condition* condition = *it;
		it = conditions.erase(it);

		condition->endCondition(this, reason);
		onEndCondition(condition->getType());
		delete condition;
	}
}
Ejemplo n.º 25
0
	std::cv_status wait_for(Condition& cv, Lock& lock, const std::chrono::duration<Rep, Period>& duration, const cancellation_token& token)
	{
		using handler_type = detail::cv_cancellation_handler<Condition, Lock>;
		handler_type handler(cv, lock);
		detail::cv_cancellation_guard<handler_type> guard(token, handler);
		if (guard.is_cancelled())
			return std::cv_status::no_timeout;
		return cv.wait_for(lock, duration);
	}
Ejemplo n.º 26
0
	void wait(Condition& cv, Lock& lock, const cancellation_token& token)
	{
		using handler_type = detail::cv_cancellation_handler<Condition, Lock>;
		handler_type handler(cv, lock);
		detail::cv_cancellation_guard<handler_type> guard(token, handler);
		if (guard.is_cancelled())
			return;
		cv.wait(lock);
	}
Ejemplo n.º 27
0
	std::cv_status wait_until(Condition& cv, Lock& lock, const std::chrono::time_point<Clock, Duration>& time_point, const cancellation_token& token)
	{
		using handler_type = detail::cv_cancellation_handler<Condition, Lock>;
		handler_type handler(cv, lock);
		detail::cv_cancellation_guard<handler_type> guard(token, handler);
		if (guard.is_cancelled())
			return std::cv_status::no_timeout;
		return cv.wait_until(lock, time_point);
	}
Ejemplo n.º 28
0
void Creature::executeConditions(uint32_t interval)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end(); )
	{
		if((*it)->executeCondition(this, interval))
		{
			++it;
			continue;
		}

		Condition* condition = *it;
		it = conditions.erase(it);

		condition->endCondition(this, CONDITIONEND_TICKS);
		onEndCondition(condition->getType());
		delete condition;
	}
}
Ejemplo n.º 29
0
		std::vector<T> list(const Condition & condition) {
			std::vector<T> lst;
			for (;hasNext(); next()) {
				if (condition.test(&get())) {
					lst.push_back(get());
				}
			}
			return lst;
		}
Ejemplo n.º 30
0
void Creature::removeCondition(ConditionType_t type, ConditionId_t id)
{
	for(ConditionList::iterator it = conditions.begin(); it != conditions.end(); )
	{
		if((*it)->getType() != type || (*it)->getId() != id)
		{
			++it;
			continue;
		}

		Condition* condition = *it;
		it = conditions.erase(it);

		condition->endCondition(this, CONDITIONEND_ABORT);
		onEndCondition(condition->getType());
		delete condition;
	}
}