• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C++ WorkItem类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中WorkItem的典型用法代码示例。如果您正苦于以下问题:C++ WorkItem类的具体用法?C++ WorkItem怎么用?C++ WorkItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了WorkItem类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: ProcessItems

void WorkQueue::ProcessItems(unsigned threadIndex)
{
    bool wasActive = false;

    for (;;)
    {
        if (shutDown_)
            return;

        if (pausing_ && !wasActive)
            Time::Sleep(0);
        else
        {
            queueMutex_.Acquire();
            if (!queue_.Empty())
            {
                wasActive = true;

                WorkItem* item = queue_.Front();
                queue_.PopFront();
                queueMutex_.Release();
                item->workFunction_(item, threadIndex);
                item->completed_ = true;
            }
            else
            {
                wasActive = false;

                queueMutex_.Release();
                Time::Sleep(0);
            }
        }
    }
}
开发者ID:boberfly,项目名称:Urho3D,代码行数:34,代码来源:WorkQueue.cpp


示例2: wxLogMessage

void* WorkerThread::Entry()
{
	WorkItem* item;

	wxLogMessage( _T( "WorkerThread started" ) );

	while ( !TestDestroy() ) {
		// sleep an hour or until a new WorkItem arrives (DoWork() will wake us up).
		Sleep( 3600 * 1000 );
		while ( !TestDestroy() && ( item = m_workItems.Pop() ) != NULL ) {
			try {
				wxLogMessage( _T( "running WorkItem %p, prio = %d" ), item, item->m_priority );
				item->Run();
			}
			catch ( ... ) {
				// better eat all exceptions thrown by WorkItem::Run(),
				// don't want to let the thread die on a single faulty WorkItem.
				wxLogMessage( _T( "WorkerThread caught exception thrown by WorkItem::Run" ) );
			}
			CleanupWorkItem( item );
			// give other threads some air
			Yield();
		}
	}

	// cleanup leftover WorkItems
	while ( ( item = m_workItems.Pop() ) != NULL ) {
		CleanupWorkItem( item );
	}

	wxLogMessage( _T( "WorkerThread stopped" ) );
	return 0;
}
开发者ID:N2maniac,项目名称:springlobby-join-fork,代码行数:33,代码来源:thread.cpp


示例3: while

void WorkItemQueue::Process()
{
	while (!m_dying) {
		WorkItem* item = NULL;
		boost::unique_lock<boost::mutex> lock(m_mutex);
		while ((!m_dying) && (item = Pop())) {
			try {
				//                LslDebug( "running WorkItem %p, prio = %d", item, item->m_priority );
				item->Run();
			} catch (std::exception& e) {
				// better eat all exceptions thrown by WorkItem::Run(),
				// don't want to let the thread die on a single faulty WorkItem.
				LslDebug("WorkerThread caught exception thrown by WorkItem::Run -- %s", e.what());
			} catch (...) {
				LslDebug("WorkerThread caught exception thrown by WorkItem::Run");
			}
			CleanupWorkItem(item);
		}
		// cleanup leftover WorkItems
		while ((item = Pop()) != NULL) {
			CleanupWorkItem(item);
		}
		if (!m_dying)
			//wait for the next Push
			m_cond.wait(lock);
	}
}
开发者ID:apoleon,项目名称:lsl,代码行数:27,代码来源:thread.cpp


示例4: lk

 void ReplicationExecutor::doOperationWithGlobalExclusiveLock(
         OperationContext* txn,
         const CallbackHandle& cbHandle) {
     boost::unique_lock<boost::mutex> lk(_mutex);
     if (_inShutdown)
         return;
     const WorkQueue::iterator iter = cbHandle._iter;
     const uint64_t generation = iter->generation;
     invariant(generation == cbHandle._generation);
     WorkItem work = *iter;
     iter->callback = CallbackFn();
     _freeQueue.splice(_freeQueue.begin(), _exclusiveLockInProgressQueue, iter);
     lk.unlock();
     {
         boost::lock_guard<boost::mutex> terribleLock(_terribleExLockSyncMutex);
         work.callback(CallbackData(this,
                                    cbHandle,
                                    (work.isCanceled ?
                                     Status(ErrorCodes::CallbackCanceled, "Callback canceled") :
                                     Status::OK()),
                                    txn));
     }
     lk.lock();
     signalEvent_inlock(work.finishedEvent);
 }
开发者ID:Aaron20141021,项目名称:mongo,代码行数:25,代码来源:replication_executor.cpp


示例5: while

void WorkQueue_Impl::worker_main()
{
	while (true)
	{
		int wakeup_reason = Event::wait(stop_event, work_available_event);
		if (wakeup_reason != 1)
			break;
		MutexSection mutex_lock(&mutex);
		if (!queued_items.empty())
		{
			WorkItem *item = queued_items.front();
			queued_items.erase(queued_items.begin());
			mutex_lock.unlock();
			item->process_work();
			mutex_lock.lock();
			finished_items.push_back(item);
			mutex_lock.unlock();
			set_wakeup_event();
		}
		else
		{
			work_available_event.reset();
		}
	}
}
开发者ID:Cassie90,项目名称:ClanLib,代码行数:25,代码来源:work_queue.cpp


示例6: avgRenderTime

QTime Job::avgRenderTime(int& days)
{
   QTime sum,diff,midnight;
   QDateTime left,right;
   int tempDays,counter = 0,hour;

   //24*60*60*1000 = 86400000
   const long MS_PER_DAY = 86400000;

   long daySeconds, timeSeconds;
   WorkItem* currentItem = finished.first();
   days = 0;

   //traverse finished list
   while(currentItem)
   {
      left = currentItem->getFinish();
      right = currentItem->getStart();
      diff = left.time() - right.time();

      //if the hours combine to more than 24 add a day
      hour = diff.hour() + sum.hour();
      if(hour >= 24)
         days++;

      //add to sum
      sum = diff + sum;

      //find the days between start time and finish time
      tempDays = right.daysTo(left);

      //if the difference is greater than one day add the difference
      if(tempDays > 0)
      {
         days = days + tempDays - 1;
         if(diff >= midnight)
            days++;
      }

      currentItem = finished.next();
      counter++;
   }

   //now calculate the average.
   //days must be converted into ms
   //sum must be converted into ms
   //the two must be added and devided by counter
   daySeconds = ((double)days/counter)*24*60*60*1000;
   timeSeconds = sum.hour()*60*60*1000 + sum.minute()*60*1000 + sum.second()*1000 + sum.msec();

   if(counter > 0)
      timeSeconds = timeSeconds/counter + daySeconds;
   else
      timeSeconds = 0;

   midnight = midnight.addMSecs(timeSeconds%MS_PER_DAY);

   days = timeSeconds/MS_PER_DAY;
   return midnight;
}
开发者ID:AlphaPixel,项目名称:3DNature,代码行数:60,代码来源:job.cpp


示例7: removeItem

SOM_Scope short  SOMLINK removeItem(Day *somSelf,  Environment *ev,
                                string start, string end, string desc)
{
    DayData *somThis = DayGetData(somSelf);
    short    i;
    WorkItem *item;
    DayMethodDebug("Day","removeItem");

    for (i=0; i < sequenceLength(somThis->workList); i++ )
    {
      item = sequenceElement(somThis->workList,i);

      if ( (strcmp(start, item->_get_startTime(ev)) == 0) &&
           (strcmp(end, item->_get_endTime(ev)) == 0) &&
           (strcmp(desc, item->_get_task(ev)) == 0) )
      {
         sequenceLength(somThis->workList)--;
                                                                         
         for (i; i < sequenceLength(somThis->workList); i++)
         {
           sequenceElement(somThis->workList,i) =
             sequenceElement(somThis->workList, i+1);
         }

         somSelf->sompSetDirty(ev);
         return 0;
      }
    }
    return -1L;       // item not found
}
开发者ID:OS2World,项目名称:DEV-SAMPLES-SOM-OOProgSOM-DSOM,代码行数:30,代码来源:DAY.CPP


示例8: jobFailed

void ServerObject::jobFailed(const QString& str, QThread* thread)
{
	Thread* thr = (Thread*)thread;
	WorkItem *nextItem;
	if (unpaused) 
	{
		//jobs->renderFailed(((Thread*)thread)->getInfo());
		uint jobid;
		nextItem = jobs->getItem(&jobid);
		
		
		// here is where we queue in the next job in the list
		if (nextItem) {
			emit finished(thr->getHost().append(" ").append(str));
			thr->setJobId(jobid);
			thr->setJobName(nextItem->getJob()->getJobName());
			thr->setInfo(nextItem);
			thr->start();
		}
		else{
			emit finished(thr->getHost().append(" ").append(str));
			emit finished(tr("All jobs finished on ").append(thr->getHost()));
		}
	}
	else {
		emit finished(thr->getHost().append(" ").append("paused"));
	}
}
开发者ID:AlphaPixel,项目名称:3DNature,代码行数:28,代码来源:serverobject.cpp


示例9: ptr

inline F32 ThreadPool::WorkItemWrapper::getPriority()
{
   WorkItem* item = ptr();
   AssertFatal( item != 0, "ThreadPool::WorkItemWrapper::getPriority - called on dead item" );

   // Compute a scaled priority value based on the item's context.
   return ( item->getContext()->getAccumulatedPriorityBias() * item->getPriority() );
}
开发者ID:fr1tz,项目名称:terminal-overload,代码行数:8,代码来源:threadPool.cpp


示例10: Callback

    static void Callback(PTP_CALLBACK_INSTANCE, PVOID state, PTP_WORK)
    {
        WorkItem* workItem = static_cast<WorkItem*>(state);

        workItem->callback_();
        ::CloseThreadpoolWork(workItem->work_);
        workItem->selfReferenceSPtr_.reset();
    }
开发者ID:vturecek,项目名称:Service-Fabric,代码行数:8,代码来源:Threadpool.cpp


示例11: while

WorkList::~WorkList() {
    // Delete any WorkItems in the queue:
    WorkItem*   item;
    cci_debug_printf("%s", __FUNCTION__);
    char        buf[2048];
    char*       pbuf        = (char*)buf;
    while (remove(&item)) {
        cci_debug_printf("WorkList::~WorkList() deleting %s", item->print(pbuf));
        delete item;
        }

    DeleteCriticalSection(&cs);
    }
开发者ID:Brainiarc7,项目名称:pbis,代码行数:13,代码来源:WorkItem.cpp


示例12: Resume

void WorkQueue::Complete(unsigned priority)
{
    completing_ = true;

    if (threads_.Size())
    {
        Resume();

        // Take work items also in the main thread until queue empty or no high-priority items anymore
        while (!queue_.Empty())
        {
            queueMutex_.Acquire();
            if (!queue_.Empty() && queue_.Front()->priority_ >= priority)
            {
                WorkItem* item = queue_.Front();
                queue_.PopFront();
                queueMutex_.Release();
                item->workFunction_(item, 0);
                item->completed_ = true;
            }
            else
            {
                queueMutex_.Release();
                break;
            }
        }

        // Wait for threaded work to complete
        while (!IsCompleted(priority))
        {
        }

        // If no work at all remaining, pause worker threads by leaving the mutex locked
        if (queue_.Empty())
            Pause();
    }
    else
    {
        // No worker threads: ensure all high-priority items are completed in the main thread
        while (!queue_.Empty() && queue_.Front()->priority_ >= priority)
        {
            WorkItem* item = queue_.Front();
            queue_.PopFront();
            item->workFunction_(item, 0);
            item->completed_ = true;
        }
    }

    PurgeCompleted(priority);
    completing_ = false;
}
开发者ID:boberfly,项目名称:Urho3D,代码行数:51,代码来源:WorkQueue.cpp


示例13: worklist_remove

EXTERN_C    int  worklist_remove(long*              rpcmsg,
                                 ccs_pipe_t*        pipe,
                                 k5_ipc_stream*      stream,
                                 time_t*            sst) {
        WorkItem*   item    = NULL;
        cc_int32    err     = worklist.remove(&item);

        *rpcmsg         = item->type();
        *pipe           = item->take_pipe();
        *stream         = item->take_payload();
        *sst            = item->sst();
        delete item;
        return err;
        }
开发者ID:FarazShaikh,项目名称:LikewiseSMB2,代码行数:14,代码来源:WorkQueue.cpp


示例14: run

 void* run() {
     // Remove 1 item at a time and process it. Blocks if no items are 
     // available to process.
     for (int i = 0;; i++) {
         printf("thread %lu, loop %d - waiting for item...\n", 
               (long unsigned int)self(), i);
         WorkItem* item = m_queue.remove();
         printf("thread %lu, loop %d - got one item\n", 
               (long unsigned int)self(), i);
         printf("thread %lu, loop %d - item: message - %s, number - %d\n", 
               (long unsigned int)self(), i, item->getMessage(), 
                item->getNumber());
         delete item;
     }
     return NULL;
 }
开发者ID:astwish,项目名称:wqueue,代码行数:16,代码来源:main.cpp


示例15: disown

Job::~Job()
{
   WorkItem* tempItem;
   working.first();
   while(!working.isEmpty())
   {
      tempItem = working.take();

      //set workitems job pointer to null
      tempItem->setParentJob(0);

      //put work items in a special list of WorkQueue class to be deleted
      //when they are finished.
      emit disown(tempItem);
   }
}
开发者ID:AlphaPixel,项目名称:3DNature,代码行数:16,代码来源:job.cpp


示例16: while

void ThreadPool::IOThreadMain()
{
	while (m_Running)
	{
		if (m_IOHasWork.Acquire(500))
		{
			WorkItem itm;
			if (!m_IOWorkQueue.try_pop(itm))
			{
				continue;
			}

			itm.pFunct(itm.pArg);
		}
	}
}
开发者ID:lindend,项目名称:lighting-thesis,代码行数:16,代码来源:ThreadPool.cpp


示例17: queueIsEmpty

    std::shared_ptr<Artworks::ArtworkMetadata> SpellCheckWorker::processWorkItem(WorkItem &workItem) {
        std::shared_ptr<Artworks::ArtworkMetadata> result;
        if (workItem.isSeparator()) {
            emit queueIsEmpty();
        } else {
            this->processSpellingQuery(workItem.m_Item);

            if (workItem.isMilestone()) {
                QThread::msleep(SPELLCHECK_WORKER_SLEEP_DELAY);
            }

            result = std::dynamic_pointer_cast<Artworks::ArtworkMetadata>(workItem.m_Item->getBasicModelSource());
        }

        return result;
    }
开发者ID:Ribtoks,项目名称:xpiks,代码行数:16,代码来源:spellcheckworker.cpp


示例18: inList

bool Job::inList(Que* list, QString itemInfo)
{
   if(list)
   {
      //traverse list from front
      WorkItem* listWalker = list->first();
      while(listWalker)
      {
         //return true if ID matches
         if(listWalker->getFrameInfo() == itemInfo)
            return true;
         listWalker = list->next();
      }
   }
   //did not find matching ID in list
   return false;
}
开发者ID:AlphaPixel,项目名称:3DNature,代码行数:17,代码来源:job.cpp


示例19: GetCurrentThreadId

DWORD WINAPI Pool::threadFunction(void* context)
{
	DWORD currentThreadId = GetCurrentThreadId();
	//работаем пока хотим, что поток жил или не убиваем его
	printf("Thread: %d\n", currentThreadId);
	fflush(stdin);
	Pool *pool = (Pool*)context;

	while(true)
	{
		//выходим из потока, если ему повелел killer
		EnterCriticalSection(&pool->killCriticalSection);
		if (pool->killThreads->at(currentThreadId) == true)
		{
			LeaveCriticalSection(&pool->killCriticalSection);
			break;
		}
		LeaveCriticalSection(&pool->killCriticalSection);
		printf("Work thread: %d wait on semaphore\n", currentThreadId);
		//ждЄм пока нет новой задачи
		WaitForSingleObject(pool->semaphoreFreeThread, INFINITE);
		printf("Work thread: %d now was work\n", currentThreadId);
		//отмечаем, что поток начнЄт работать
		EnterCriticalSection(&pool->timeLifeCriticalSection);
		pool->handlersAndTime->at(currentThreadId) = SIGN_THREAD_NOW_WORK;
		LeaveCriticalSection(&pool->timeLifeCriticalSection);

		//атомарно получаем работу и удал¤ем еЄ из очереди
		//чтобы несколько потоко не выполн¤ли одно и тоже
		EnterCriticalSection(&pool->worksCriticalSection);
		WorkItem work = pool->queueWorks->back();
		pool->queueWorks->pop_back();
		LeaveCriticalSection(&pool->worksCriticalSection);

		//работаем
		work.function(work.context);

		//врем¤ когда поток перестал работать
		EnterCriticalSection(&pool->timeLifeCriticalSection);
		DWORD currentTime = GetTickCount();
		pool->handlersAndTime->at(currentThreadId) = currentTime;
		LeaveCriticalSection(&pool->timeLifeCriticalSection);
	}

	return 0;
}
开发者ID:vitiaaap29,项目名称:thread_pool_and_dll,代码行数:46,代码来源:Pool.cpp


示例20: _buf

WorkItem::WorkItem(const WorkItem& item) : _buf(NULL), _rpcmsg(0), _pipe(NULL), _sst(0) {

    k5_ipc_stream    _buf = NULL;
    krb5int_ipc_stream_new(&_buf);
    krb5int_ipc_stream_write(_buf,
                     krb5int_ipc_stream_data(item.payload()),
                     krb5int_ipc_stream_size(item.payload()) );
    WorkItem(_buf, item._pipe, item._rpcmsg, item._sst);
    }
开发者ID:Brainiarc7,项目名称:pbis,代码行数:9,代码来源:WorkItem.cpp



注:本文中的WorkItem类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ WorkList类代码示例发布时间:2022-05-31
下一篇:
C++ Work类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap