Ejemplo n.º 1
6
	//---------------------------------------------------------------------
	Page::Page(PageID pageID, PagedWorldSection* parent)
		: mID(pageID)
		, mParent(parent)
		, mDeferredProcessInProgress(false)
		, mModified(false)
		, mDebugNode(0)
	{
		WorkQueue* wq = Root::getSingleton().getWorkQueue();
		mWorkQueueChannel = wq->getChannel("Ogre/Page");
		wq->addRequestHandler(mWorkQueueChannel, this);
		wq->addResponseHandler(mWorkQueueChannel, this);
		touch();
	}
Ejemplo n.º 2
0
        void QueueWork()
        {
            MyWorkItem *work1;
            MyWorkItem *work2;
            
            work1 = new MyWorkItem(TotalWorkItems++, true);
            work2 = new MyWorkItem(TotalWorkItems++, true);

            WqLow->QueueWork(work1);
            WqHigh->QueueWork(work2);
        }
Ejemplo n.º 3
0
int main()
{
    WorkQueue q;
    work_t w = work_t(1, 2, 3, 4);
    q.add(w);
    assert(q.get().bot_y == w.bot_y);
    assert(q.get().id == 0);
    assert(q.remove(0).bot_y == w.bot_y);

    return 0;
}
Ejemplo n.º 4
0
DWORD WorkQueue::workThreadCallback(void* context)
{
    ASSERT_ARG(context, context);

    WorkQueue* queue = static_cast<WorkQueue*>(context);

    if (!queue->tryRegisterAsWorkThread())
        return 0;

    queue->performWorkOnRegisteredWorkThread();
    return 0;
}
Ejemplo n.º 5
0
void printWorkQueue(WorkQueue& queue) {
  WorkQueue local_queue(queue);
  printf("WorkQueue: %d elements\n", queue.size());
  for (long unsigned int request_index = 0;
          request_index < queue.size();
          ++request_index) {
    WorkRequest req = local_queue.top();
    local_queue.pop();
    printf("queue[%d]: node_index: %d, time_diff: %f\n", request_index,
            req.getIndex(), req.getTimeDiff());
  }
}
Ejemplo n.º 6
0
        void QueueExtraWork()
        {
            MyWorkItem *work1;
            
            work1 = new MyWorkItem(TotalWorkItems++, true);
            WqLow->QueueWork(work1);

            work1 = new MyWorkItem(TotalWorkItems++, true);
            WqLow->QueueWork(work1);

            work1 = new MyWorkItem(TotalWorkItems++, true);
            WqLow->QueueWork(work1);
        }
Ejemplo n.º 7
0
void Scheduler::renderFinished(WorkItem* item)
{
   WorkQueue* temp = priorityList.first();
   bool containsItem = false;
   if(item)
   {
      while((temp)&&(!containsItem))
      {
         containsItem = temp->renderFinished(item);
         temp = priorityList.next();
      }
   }
}
Ejemplo n.º 8
0
Octree::Octree(Context* context) :
    Component(context),
    Octant(BoundingBox(-DEFAULT_OCTREE_SIZE, DEFAULT_OCTREE_SIZE), 0, 0, this),
    numLevels_(DEFAULT_OCTREE_LEVELS)
{
    // Resize threaded ray query intermediate result vector according to number of worker threads
    WorkQueue* workQueue = GetSubsystem<WorkQueue>();
    rayQueryResults_.Resize(workQueue ? workQueue->GetNumThreads() + 1 : 1);

    // If the engine is running headless, subscribe to RenderUpdate events for manually updating the octree
    // to allow raycasts and animation update
    if (!GetSubsystem<Graphics>())
        SubscribeToEvent(E_RENDERUPDATE, HANDLER(Octree, HandleRenderUpdate));
}
Ejemplo n.º 9
0
	//------------------------------------------------------------------------
	BackgroundProcessTicket ResourceBackgroundQueue::addRequest(ResourceRequest& req)
	{
		WorkQueue* queue = Root::getSingleton().getWorkQueue();

		Any data(req);

		WorkQueue::RequestID requestID = 
			queue->addRequest(mWorkQueueChannel, (uint16)req.type, data);


		mOutstandingRequestSet.insert(requestID);

		return requestID;
	}
Ejemplo n.º 10
0
TEST(WorkQueue, cancel) {
    RunLoop loop(uv_default_loop());

    WorkQueue queue;

    auto work = [&]() {
        FAIL() << "Should never be called";
    };

    queue.push(work);
    queue.push(work);
    queue.push(work);
    queue.push(work);
    queue.push(work);
}
Ejemplo n.º 11
0
void MethodTransform::sync_all() {
  std::vector<MethodTransform*> transforms;
  for (auto& centry : s_cache) {
    transforms.push_back(centry.second);
  }
  std::vector<WorkItem<MethodTransform>> workitems(transforms.size());
  auto mt_sync = [](MethodTransform* mt) { mt->sync(); };
  for (size_t i = 0; i < transforms.size(); i++) {
    workitems[i].init(mt_sync, transforms[i]);
  }
  WorkQueue wq;

  if (workitems.size() > 0) {
    wq.run_work_items(&workitems[0], (int)workitems.size());
  }
}
Ejemplo n.º 12
0
    StatusWith<ReplicationExecutor::CallbackHandle> ReplicationExecutor::scheduleWorkAt(
            Date_t when,
            const CallbackFn& work) {

        boost::lock_guard<boost::mutex> lk(_mutex);
        WorkQueue temp;
        StatusWith<CallbackHandle> cbHandle = enqueueWork_inlock(&temp, work);
        if (!cbHandle.isOK())
            return cbHandle;
        cbHandle.getValue()._iter->readyDate = when;
        WorkQueue::iterator insertBefore = _sleepersQueue.begin();
        while (insertBefore != _sleepersQueue.end() && insertBefore->readyDate <= when)
            ++insertBefore;
        _sleepersQueue.splice(insertBefore, temp, temp.begin());
        return cbHandle;
    }
Ejemplo n.º 13
0
void test_work_queue() {
  WorkQueue<string> q;
  string t = "hello";
  q.push(t);
  string s;
  if(q.try_pop(s, 500)){
    cout << "got " << s << " from queue" << endl;
  }
  bool ok = q.try_pop(s,500);
  if(ok) {
    cout << "failed, should have timed out" << endl;
  }
  else{
    cout << "passed, timed out as expected" << endl;
  }
}
Ejemplo n.º 14
0
static void didCloseOnConnectionWorkQueue(WorkQueue& workQueue, CoreIPC::Connection*)
{
    // If the connection has been closed and we haven't responded in the main thread for 10 seconds
    // the process will exit forcibly.
    const double watchdogDelay = 10;

    workQueue.dispatchAfterDelay(bind(static_cast<void(*)()>(watchdogCallback)), watchdogDelay);
}
Ejemplo n.º 15
0
void ChildProcess::didCloseOnConnectionWorkQueue(WorkQueue& workQueue, CoreIPC::Connection*)
{
    // If the connection has been closed and we haven't responded in the main thread for 10 seconds
    // the process will exit forcibly.
    static const double watchdogDelay = 10.0;
    
    workQueue.scheduleWorkAfterDelay(WorkItem::create(watchdogCallback), watchdogDelay);
}
    //---------------------------------------------------------------------
    TerrainPagedWorldSection::TerrainPagedWorldSection(const String& name, PagedWorld* parent, SceneManager* sm)
        : PagedWorldSection(name, parent, sm)
        , mTerrainGroup(0)
        , mTerrainDefiner(0)
        , mHasRunningTasks(false)
        , mLoadingIntervalMs(900)
    {
        // we always use a grid strategy
        setStrategy(parent->getManager()->getStrategy("Grid2D"));

        WorkQueue* wq = Root::getSingleton().getWorkQueue();
        mWorkQueueChannel = wq->getChannel("Ogre/TerrainPagedWorldSection");
        wq->addRequestHandler(mWorkQueueChannel, this);
        wq->addResponseHandler(mWorkQueueChannel, this);

        mNextLoadingTime = Root::getSingletonPtr()->getTimer()->getMilliseconds();
    }
Ejemplo n.º 17
0
Results FastqWriterThread(WorkQueue<Results>& queue, const string& fname)
{
    ofstream ccsFastq(fname);
    Results counts;
    while (queue.ConsumeWith(WriteFastqRecords, ref(ccsFastq), ref(counts)))
        ;
    return counts;
}
Ejemplo n.º 18
0
Results BamWriterThread(WorkQueue<Results>& queue, unique_ptr<BamWriter>&& ccsBam,
                        unique_ptr<PbiBuilder>&& ccsPbi)
{
    Results counts;
    while (queue.ConsumeWith(WriteBamRecords, ref(*ccsBam), ref(ccsPbi), ref(counts)))
        ;
    return counts;
}
Ejemplo n.º 19
0
//--------------------------------------------------------------------------
void MeshLodTests::blockedWaitForLodGeneration(const MeshPtr& mesh)
{
    bool success = false;
    const int timeout = 5000;
    WorkQueue* wq = Root::getSingleton().getWorkQueue();
    for (int i = 0; i < timeout; i++) 
    {
        OGRE_THREAD_SLEEP(1);
        wq->processResponses(); // Injects the Lod if ready
        if (mesh->getNumLodLevels() != 1) {
            success = true;
            break;
        }
    }
    // timeout
    CPPUNIT_ASSERT(success);
}
Ejemplo n.º 20
0
// store equivalence class in VertexInfo for each vertex
static
vector<VertexInfoSet> partitionGraph(ptr_vector<VertexInfo> &infos,
                                     WorkQueue &work_queue, const NGHolder &g,
                                     EquivalenceType eq) {
    const size_t num_verts = infos.size();

    vector<VertexInfoSet> classes;
    unordered_map<ClassInfo, unsigned> classinfomap;

    // assume we will have lots of classes, so we don't waste time resizing
    // these structures.
    classes.reserve(num_verts);
    classinfomap.reserve(num_verts);

    // get distances from start (or accept) for all vertices
    // only one of them is used at a time, never both
    vector<NFAVertexDepth> depths;
    vector<NFAVertexRevDepth> rdepths;

    if (eq == LEFT_EQUIVALENCE) {
        calcDepths(g, depths);
    } else {
        calcDepths(g, rdepths);
    }

    // partition the graph based on CharReach
    for (VertexInfo &vi : infos) {
        ClassInfo::ClassDepth depth;

        if (eq == LEFT_EQUIVALENCE) {
            depth = depths[vi.vert_index];
        } else {
            depth = rdepths[vi.vert_index];
        }
        ClassInfo ci(g, vi, depth, eq);

        auto ii = classinfomap.find(ci);
        if (ii == classinfomap.end()) {
            // vertex is in a new equivalence class by itself.
            unsigned eq_class = classes.size();
            vi.equivalence_class = eq_class;
            classes.push_back({&vi});
            classinfomap.emplace(move(ci), eq_class);
        } else {
            // vertex is added to an existing class.
            unsigned eq_class = ii->second;
            vi.equivalence_class = eq_class;
            classes.at(eq_class).insert(&vi);

            // we now know that this particular class has more than one
            // vertex, so we add it to the work queue
            work_queue.push(eq_class);
        }
    }

    DEBUG_PRINTF("partitioned, %zu equivalence classes\n", classes.size());
    return classes;
}
Ejemplo n.º 21
0
void *worker(void *vtp)
{
    fprintf(stderr, "Worker working\n");
    WorkQueue<Task> *tqp = (WorkQueue<Task> *)vtp;
    Task tsk;
    for (;;) {
	if (!tqp->take(&tsk)) {
	    fprintf(stderr, "Worker: take failed\n");
	    return (void*)0;
	}
	fprintf(stderr, "WORKER: got task %d\n", tsk.m_id);
	if (tsk.m_id > 20) {
	    tqp->workerExit();
	    break;
	}
    }
    return (void*)1;
}
Ejemplo n.º 22
0
	//---------------------------------------------------------------------
	Page::~Page()
	{
		WorkQueue* wq = Root::getSingleton().getWorkQueue();
		wq->removeRequestHandler(mWorkQueueChannel, this);
		wq->removeResponseHandler(mWorkQueueChannel, this);

		destroyAllContentCollections();
		if (mDebugNode)
		{
			// destroy while we have the chance
			SceneNode::ObjectIterator it = mDebugNode->getAttachedObjectIterator();
			while(it.hasMoreElements())
				mParent->getSceneManager()->destroyMovableObject(it.getNext());
			mDebugNode->removeAndDestroyAllChildren();
			mParent->getSceneManager()->destroySceneNode(mDebugNode);

			mDebugNode = 0;
		}
	}
Ejemplo n.º 23
0
QString Scheduler::getJobName(uint jobID)
{
   //search for WorkQueue containing Job with jobID
   Job* tempJob;
   WorkQueue* tempQue = priorityList.first();
   while(tempQue)
   {
      tempJob = tempQue->getJob(jobID);
      if(tempJob)
      {
         //found Job containin jobID (getting pointer removes job from list so have to put it back)
         tempQue->addJob(tempJob);
         return (tempJob->getJobName());
      }
      tempQue = priorityList.next();
   }
   //did not find Job with jobID
   return (QString("No Job With Matching ID"));
}
Ejemplo n.º 24
0
	static int worker(void* self)
	{
		try
		{
			WorkQueue* queue = static_cast<WorkQueue*>(self);

			while (true)
			{
				auto work = queue->waitForWork();

				work->run();
			}
		}
		catch (StopWorker&)
		{
		}

		return 0;
	}
    //---------------------------------------------------------------------
    TerrainPagedWorldSection::~TerrainPagedWorldSection()
    {
        //remove the pending tasks, but keep the front one, as it may have been in running
        if(!mPagesInLoading.empty())
            mPagesInLoading.erase( ++mPagesInLoading.begin(), mPagesInLoading.end() );

        while(!mPagesInLoading.empty())
        {
            OGRE_THREAD_SLEEP(50);
            Root::getSingleton().getWorkQueue()->processResponses();
        }

        WorkQueue* wq = Root::getSingleton().getWorkQueue();
        wq->removeRequestHandler(mWorkQueueChannel, this);
        wq->removeResponseHandler(mWorkQueueChannel, this);

        OGRE_DELETE mTerrainGroup;
        if(mTerrainDefiner)
            OGRE_DELETE mTerrainDefiner;
    }
Ejemplo n.º 26
0
void AsyncThreadManager::itemConsumer(WorkQueue& workQueue, condition_variable& workAvailable, recursive_mutex& queueMutex, bool &finished)
{
	while(true)
	{
		cz::unique_lock<cz::recursive_mutex> queueLock(queueMutex);
		while(!finished && workQueue.empty())
			workAvailable.wait(queueLock);

		if (finished)
			break;

		detail::AsyncWorkItemBase* workItem = workQueue.front();
		workQueue.pop();
		// unlock so other threads can remove work items while we compute this one
		queueLock.unlock();

		// Compute the result (this will put the value in the "future" object the user is holding)
		workItem->run();
		CZ_DELETE workItem;
	}
}
Ejemplo n.º 27
0
int RebuildAIComponent::DoTick(U32 delta)
{
	GameItem* mainItem = parentChit->GetItem();
	Vector2I sector = ToSector(parentChit->Position());
	CoreScript* cs = CoreScript::GetCore(sector);

	if (ticker.Delta(delta) && mainItem && cs) {

		// Create workers, if needed.
		Rectangle2F b = ToWorld2F(InnerSectorBounds(sector));
		CChitArray arr;
		ItemNameFilter workerFilter(ISC::worker);
		Context()->chitBag->QuerySpatialHash(&arr, b, 0, &workerFilter);
		if (arr.Empty()) {
			if (mainItem->wallet.Gold() >= WORKER_BOT_COST) {
				ReserveBank::GetWallet()->Deposit(&mainItem->wallet, WORKER_BOT_COST);
				Context()->chitBag->NewWorkerChit(cs->ParentChit()->Position(), parentChit->Team());
			}
		}

		// Pull a task off the queue and send a worker out.
		if (workItems.Size()) {
			WorkQueue* workQueue = cs->GetWorkQueue();
			if (workQueue) {
				WorkItem wi = workItems.Pop();
				BuildScript buildScript;
				int id = 0;
				buildScript.GetDataFromStructure(wi.structure, &id);
				if (workQueue->AddAction(wi.pos, id, float(wi.rot), 0)) {
					GLOUTPUT(("ReBuild: Structure %s at %d,%d r=%d POP to work queue.\n", wi.structure.safe_str(), wi.pos.x, wi.pos.y, int(wi.rot)));
				}
				else {
					GLOUTPUT(("ReBuild: Re-Push structure %s at %d,%d to work queue.\n", wi.structure.safe_str(), wi.pos.x, wi.pos.y));
					workItems.Push(wi);
				}
			}
		}
	}
	return ticker.Next();
}
Ejemplo n.º 28
0
void tst_runOneJob()
{
    GLOBAL_COUNTER = 1;

    WorkQueue queue;
    shared_ptr<WorkQueue::Job> job(new OneJob(1));

    check_true(!job->hasCompleted());
    check_equal(static_cast<OneJob *>(job.get())->runId, -1);

    queue.schedule(job);

    // Spin a while loop, waiting 1 ms at a time, to see if the job completes
    // on its own. If we're still spinning after 10000 iterations, emit a warning
    // that the thing is probably locked up
    int counter = 0;
    while (!job->hasCompleted()) {
        this_thread::sleep_for(std::chrono::milliseconds(1));
        ++counter;
        if (counter > 10000) {
            cout << __FUNCTION__ << ": has with all likelyhood timed out, assuming failure!" << endl;
            check_true(false);
        }
    }

    if (counter == 0) {
        cout << " - job seems to have completed without any delay.. This is suspicious.." << endl;
        return;
    }

    // The runId should be the one we set up above, namely 1, as this is the
    // only job executing at present.
    check_equal(static_cast<OneJob *>(job.get())->runId, 1);

    cout << __FUNCTION__ << ": ok" << endl;
}
Ejemplo n.º 29
0
void CryptoAlgorithmSHA1::digest(Vector<uint8_t>&& message, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
{
    auto digest = CryptoDigest::create(CryptoDigest::Algorithm::SHA_1);
    if (!digest) {
        exceptionCallback(OperationError);
        return;
    }

    context.ref();
    workQueue.dispatch([digest = WTFMove(digest), message = WTFMove(message), callback = WTFMove(callback), &context]() mutable {
        digest->addBytes(message.data(), message.size());
        auto result = digest->computeHash();
        context.postTask([callback = WTFMove(callback), result = WTFMove(result)](ScriptExecutionContext& context) {
            callback(result);
            context.deref();
        });
    });
}
Ejemplo n.º 30
0
void CryptoAlgorithmRSA_OAEP::platformDecrypt(std::unique_ptr<CryptoAlgorithmParameters>&& parameters, Ref<CryptoKey>&& key, Vector<uint8_t>&& cipherText, VectorCallback&& callback, ExceptionCallback&& exceptionCallback, ScriptExecutionContext& context, WorkQueue& workQueue)
{
    context.ref();
    workQueue.dispatch([parameters = WTFMove(parameters), key = WTFMove(key), cipherText = WTFMove(cipherText), callback = WTFMove(callback), exceptionCallback = WTFMove(exceptionCallback), &context]() mutable {
        auto& rsaParameters = downcast<CryptoAlgorithmRsaOaepParams>(*parameters);
        auto& rsaKey = downcast<CryptoKeyRSA>(key.get());
        auto result = decryptRSA_OAEP(rsaKey.hashAlgorithmIdentifier(), rsaParameters.labelVector(), rsaKey.platformKey(), rsaKey.keySizeInBits(), cipherText.data(), cipherText.size());
        if (result.hasException()) {
            context.postTask([exceptionCallback = WTFMove(exceptionCallback), ec = result.releaseException().code()](ScriptExecutionContext& context) {
                exceptionCallback(ec);
                context.deref();
            });
            return;
        }
        context.postTask([callback = WTFMove(callback), result = result.releaseReturnValue()](ScriptExecutionContext& context) {
            callback(result);
            context.deref();
        });
    });
}