示例#1
0
void gputask_Join()
{
	if(!g_kickedTasks.empty())
	{
		auto ptr = g_kickedTasks.front();
		g_kickedTasks.pop_front();
		ptr->m_complete();
	}
}
void CountMin::outputCountsOfWordList(std::deque<string> wordlist){
	
	while(!wordlist.empty()){
		std::string word = wordlist.front();
		int count = queryCountOfString(word);
		printf("%d,%s\n",count,word.c_str());
		wordlist.pop_front();
	}
}
示例#3
0
    void do_work (CompletionCounter)
    {
        if (m_called_stop.load () == 1)
            return;

        // We don't have any work to do at this time
        if (m_work.empty())
        {
            m_idle = true;
            m_journal.trace << "Sleeping";
            return;
        }

        if (m_work.front().names.empty())
            m_work.pop_front();

        std::string const name (m_work.front().names.back());
        HandlerType handler (m_work.front().handler);

        m_work.front().names.pop_back();

        HostAndPort const hp (parseName(name));

        if (hp.first.empty())
        {
            m_journal.error <<
                "Unable to parse '" << name << "'";

            m_io_service.post (m_strand.wrap (boost::bind (
                &NameResolverImpl::do_work, this,
                CompletionCounter(this))));

            return;
        }

        boost::asio::ip::tcp::resolver::query query (
            hp.first, hp.second);

        m_resolver.async_resolve (query, boost::bind (
            &NameResolverImpl::do_finish, this, name,
            boost::asio::placeholders::error, handler,
            boost::asio::placeholders::iterator,
            CompletionCounter(this)));
    }
void dijkstra_FIFO_thread(CSRGraph *g, int *dist, std::deque<int> &deq, int threadNum, std::mutex *dist_locks)
{
    while(!deq.empty())
    {
        queue_lock.lock();

        if(deq.empty()){
            queue_lock.unlock();
            break;
        }

        int u = deq.front();
        deq.pop_front();
	
    printf("Popped\n");
    for(int i=0; i< deq.size();i++){
	printf(" %d", deq[i]);
    }
    printf("\n");
        int udist = dist[u];
        queue_lock.unlock();

        std::vector<int> neighbors = CSRGraph_getNeighbors(g, u);
        int neighbor;
        for(neighbor=0;neighbor < neighbors.size(); neighbor++)
        {
            int v = neighbors[neighbor];
            int uvdist = CSRGraph_getDistance(g, u, v);
            int alt = udist + uvdist;

            dist_locks[v].lock();
            if(alt < dist[v])
            {
                dist[v] = alt;
                dist_locks[v].unlock();

                queue_lock.lock();                
                deq.push_back(v);
		
    printf("Pushed\n");
    for(int i=0; i< deq.size();i++){
	printf(" %d", deq[i]);
    }
    printf("\n");
                queue_lock.unlock();                    
            }
            else
            {
                dist_locks[v].unlock();
            }


        }
    }
    //printf("Thread %d ended.\n", threadNum);
}
示例#5
0
void pfPatcherWorker::ProcessFile()
{
    do {
        NetCliFileManifestEntry& entry = fQueuedFiles.front();

        // eap sucks
        plFileName clName = plString::FromWchar(entry.clientName);
        plString dlName = plString::FromWchar(entry.downloadName);

        // Check to see if ours matches
        plFileInfo mine(clName);
        if (mine.FileSize() == entry.fileSize) {
            plMD5Checksum cliMD5(clName);
            plMD5Checksum srvMD5;
            srvMD5.SetFromHexString(plString::FromWchar(entry.md5, 32).c_str());

            if (cliMD5 == srvMD5) {
                WhitelistFile(clName, false);
                fQueuedFiles.pop_front();
                continue;
            }
        }

        // It's different... but do we want it?
        if (fFileDownloadDesired) {
            if (!fFileDownloadDesired(clName)) {
                PatcherLogRed("\tDeclined '%S'", entry.clientName);
                fQueuedFiles.pop_front();
                continue;
            }
        }

        // If you got here, they're different and we want it.
        PatcherLogYellow("\tEnqueuing '%S'", entry.clientName);
        plFileSystem::CreateDir(plFileName(clName).StripFileName());

        // If someone registered for SelfPatch notifications, then we should probably
        // let them handle the gruntwork... Otherwise, go nuts!
        if (fSelfPatch) {
            if (clName == plFileSystem::GetCurrentAppPath().GetFileName()) {
                clName += ".tmp"; // don't overwrite myself!
                entry.flags |= kSelfPatch;
            }
        }

        pfPatcherStream* s = new pfPatcherStream(this, dlName, entry);
        s->Open(clName, "wb");

        hsTempMutexLock lock(fRequestMut);
        fRequests.push_back(Request(dlName, Request::kFile, s));
        fQueuedFiles.pop_front();

        if (!fRequestActive)
            IssueRequest();
    } while (!fQueuedFiles.empty());
}
示例#6
0
	void write_chunk() {
		std::size_t chunk = wait_for_empty_chunk();
		std::size_t chunk_bytes = std::min( byte_queue.size(), bytes_per_chunk );
		waveheaders[chunk].dwBufferLength = static_cast<DWORD>( chunk_bytes );
		for ( std::size_t byte = 0; byte < chunk_bytes; ++byte ) {
			wavebuffers[chunk][byte] = byte_queue.front();
			byte_queue.pop_front();
		}
		waveOutWrite( waveout, &waveheaders[chunk], sizeof( WAVEHDR ) );
	}
示例#7
0
ssize_t mock_getrandom(void *buffer, size_t length, unsigned int flags)
{
    boost::ignore_unused(buffer);
    boost::ignore_unused(length);
    boost::ignore_unused(flags);

    bool success = getrandom_next_result.front();
    getrandom_next_result.pop_front();
    return success ? static_cast< ssize_t >(length) : static_cast< ssize_t >(-1);
}
示例#8
0
int main(int, char**)
{
    {
        std::deque<int> c = make<std::deque<int> >(10);
        for (int i = 0; i < 10; ++i)
            assert(c[i] == i);
        for (int i = 0; i < 10; ++i)
            assert(c.at(i) == i);
        assert(c.front() == 0);
        assert(c.back() == 9);
    }
    {
        const std::deque<int> c = make<std::deque<int> >(10);
        for (int i = 0; i < 10; ++i)
            assert(c[i] == i);
        for (int i = 0; i < 10; ++i)
            assert(c.at(i) == i);
        assert(c.front() == 0);
        assert(c.back() == 9);
    }
#if TEST_STD_VER >= 11
    {
        std::deque<int, min_allocator<int>> c = make<std::deque<int, min_allocator<int>> >(10);
        for (int i = 0; i < 10; ++i)
            assert(c[i] == i);
        for (int i = 0; i < 10; ++i)
            assert(c.at(i) == i);
        assert(c.front() == 0);
        assert(c.back() == 9);
    }
    {
        const std::deque<int, min_allocator<int>> c = make<std::deque<int, min_allocator<int>> >(10);
        for (int i = 0; i < 10; ++i)
            assert(c[i] == i);
        for (int i = 0; i < 10; ++i)
            assert(c.at(i) == i);
        assert(c.front() == 0);
        assert(c.back() == 9);
    }
#endif

  return 0;
}
示例#9
0
		iterator insert_simple(iterator itr,const T& _val){
			Datum* pos=Ptrs.front();
			Ptrs.pop_front();
			pos->t=_val;
			pos->front=itr.dat;
			pos->back=itr.dat->back;
			pos->back->front=pos;
			pos->front->back=pos;
			return iterator(pos);
		}
deque<int> CountMin::returnCountsOfWordList(std::deque<string> wordlist){
	deque<int> counts;
	while(!wordlist.empty()){
		std::string word = wordlist.front();
		int count = queryCountOfString(word);
		counts.push_back(count);
		wordlist.pop_front();
	}
	return counts;
}
示例#11
0
	void PopFrontFrame()
	{
		ENSURE(!m_Frames.empty());
		SFrame& frame = m_Frames.front();
		for (size_t i = 0; i < frame.events.size(); ++i)
			if (frame.events[i].isEnter)
				for (size_t j = 0; j < m_QueryTypes.size(); ++j)
					m_QueryTypes[j].freeQueries.push_back(frame.events[i].queries[j]);
		m_Frames.pop_front();
	}
示例#12
0
    Hash next(size_t depth) {
        if (queue.size() > 0) {
            Hash h = queue.front();
            queue.pop_front();

            return h;
        } else {
            return emptyroots.empty_root(depth);
        }
    }
示例#13
0
	bool record_seed(Uint64 new_seed) {
		if (!unordered_history.insert(new_seed).second) return false;
		current_seed = new_seed;
		history.push_back(current_seed);
		if (history.size() > history_limit) {
			unordered_history.erase(history.front());
			history.pop_front();
		}
		return true;
	}
示例#14
0
			uint64_t tryDequeFront(std::vector<value_type> & V, uint64_t max)
			{
				libmaus2::parallel::ScopePosixSpinLock llock(lock);
				while ( max-- && Q.size() )
				{
					V.push_back(Q.front());
					Q.pop_front();
				}
				return V.size();			
			}
deque<int> returnActualCountsOfWordList(std::deque<string> wordlist,map<std::string , int> actual_counts){
	deque<int> counts;
	while(!wordlist.empty()){
		std::string word = wordlist.front();
		int count = actual_counts[word];
		counts.push_back(count);
		wordlist.pop_front();
	}
	return counts;
}
示例#16
0
    task_type try_pop_task() {
        task_type ret;
        boost::lock_guard<boost::mutex> lock(tasks_mutex_);
        if (!tasks_.empty()) {
            ret = tasks_.front();
            tasks_.pop_front();
        }

        return ret;
    }
示例#17
0
            /**
             * Wait until the next item becomes available and make it
             * available through value.
             */
            void wait_and_pop(T& value) {
                std::unique_lock<std::mutex> lock(m_mutex);

                m_data_available.wait(lock, [this] {
                    return !empty_intern();
                });
                value=std::move(m_queue.front());
                m_queue.pop_front();
                ++m_offset;
            }
示例#18
0
  double next(double num) {
    sum_ += num;
    window_.push_back(num);
    if (window_.size() > period_) {
      sum_ -= window_.front();
      window_.pop_front();
    }

    return sum_ / window_.size();
  }
示例#19
0
  vcl_size_t cuthill_mckee_on_strongly_connected_component(std::vector< std::map<IndexT, ValueT> > const & matrix,
                                                           std::deque<IndexT> & node_assignment_queue,
                                                           std::vector<bool>  & dof_assigned_to_node,
                                                           std::vector<IndexT> & permutation,
                                                           vcl_size_t current_dof)
  {
    typedef std::pair<IndexT, IndexT> NodeIdDegreePair; //first member is the node ID, second member is the node degree

    std::vector< NodeIdDegreePair > local_neighbor_nodes(matrix.size());

    while (!node_assignment_queue.empty())
    {
      // Grab first node from queue
      vcl_size_t node_id = static_cast<vcl_size_t>(node_assignment_queue.front());
      node_assignment_queue.pop_front();

      // Assign dof if a new dof hasn't been assigned yet
      if (!dof_assigned_to_node[node_id])
      {
        permutation[node_id] = static_cast<IndexT>(current_dof);  //TODO: Invert this!
        ++current_dof;
        dof_assigned_to_node[node_id] = true;

        //
        // Get all neighbors of that node:
        //
        vcl_size_t num_neighbors = 0;
        for (typename std::map<IndexT, ValueT>::const_iterator neighbor_it  = matrix[node_id].begin();
             neighbor_it != matrix[node_id].end();
             ++neighbor_it)
        {
          vcl_size_t neighbor_node_index = static_cast<vcl_size_t>(neighbor_it->first);
          if (!dof_assigned_to_node[neighbor_node_index])
          {
            local_neighbor_nodes[num_neighbors] = NodeIdDegreePair(neighbor_it->first, static_cast<IndexT>(matrix[neighbor_node_index].size()));
            ++num_neighbors;
          }
        }

        // Sort neighbors by increasing node degree
        std::sort(local_neighbor_nodes.begin(),
                  local_neighbor_nodes.begin() + static_cast<typename std::vector< NodeIdDegreePair >::difference_type>(num_neighbors),
                  detail::cuthill_mckee_comp_func_pair<IndexT>);

        // Push neighbors to queue
        for (vcl_size_t i=0; i<num_neighbors; ++i)
          node_assignment_queue.push_back(local_neighbor_nodes[i].first);

      } // if node doesn't have a new dof yet

    } // while nodes in queue

    return current_dof;

  }
示例#20
0
文件: d.cpp 项目: treewolf/homeworks
/**	sorts a priority list by filter*/
void priority_sort(std::string filter){
	if(priority.size() == 1){
		ready.push(priority.front());
		priority.pop_front();
	}
	else{
		//if priority is bigger than 1, then need to sort
		int s = priority.size();
		struct Qu t[s];
		int i = 0;
		while(!priority.empty()){
			t[i] = priority.front();
			++i;
			priority.pop_front();
		}
		//sort in array, then add back to prioroity
		int j;
		for(j=0; j<s; ++j){
			int k;
			for(k=1; k<s; ++k){
				if(filter.compare("priority") == 0){
					if(t[j].priority>t[k].priority && j<k){
						struct Qu u = t[j];
						t[j] = t[k];
						t[k] = u;
					} }
				else if(filter.compare("sjf") == 0){
					if(t[j].cpu_burst>t[k].cpu_burst && j<k){
						struct Qu u = t[j];
						t[j] = t[k];
						t[k] = u;
					}
					else if(t[j].cpu_burst==t[k].cpu_burst && j<k){
						if(t[j].arrival_time > t[k].arrival_time){
							struct Qu u = t[j];
							t[j] = t[k];
							t[k] = u;
						} } }
				} }
		for(j=0; j<s; ++j) ready.push(t[j]);
	}
}
示例#21
0
void write_sim_to_file()
{
	std::ofstream toFile1("fractures.txt", std::ios::trunc);
	std::ofstream toFile2("removed.txt", std::ios::trunc);

	toFile1 << growth.size() << "\n";
	toFile2 << removed.size() << "\n";

	toFile1 << "Invasion for: anisotropy= " << anisotropy << "\n";
	toFile2 << "Bonds removed for: anisotropy= " << anisotropy << "\n";

	toFile1.precision(17);
	toFile2.precision(17);

	str_and_Bond current_Line;
	while (!growth.empty())
	{
		current_Line = growth.front();
		growth.pop_front();
		toFile1 <<  current_Line  .first << "\t";
		toFile1 <<  current_Line.second.first.first << "\t";
		toFile1 <<  current_Line.second.first.second << "\t";
		toFile1 <<  current_Line.second.second.first << "\t";
		toFile1 <<  current_Line.second.second.second << "\n";
	}


	while (!removed.empty())
	{
		current_Line = removed.front();
		removed.pop_front();
		toFile2 <<  current_Line.first << "\t";
		toFile2 <<  current_Line.second.first.first << "\t";
		toFile2 <<  current_Line.second.first.second << "\t";
		toFile2 <<  current_Line.second.second.first << "\t";
		toFile2 <<  current_Line.second.second.second << "\n";
	}

	toFile1.close();
	toFile2.close();

}
示例#22
0
	void Execute()
	{
		const u8* mark = alloc.Mark();
		while(!events.empty())
		{
			Event& e = events.front();
			e.fn(e.object, *this);
			events.pop_front();
		}
		alloc.Unwind(mark);
	}
示例#23
0
            /**
             * Get next item if it is available and return true. Or
             * return false otherwise.
             */
            bool try_pop(T& value) {
                std::lock_guard<std::mutex> lock(m_mutex);

                if (empty_intern()) {
                    return false;
                }
                value=std::move(m_queue.front());
                m_queue.pop_front();
                ++m_offset;
                return true;
            }
示例#24
0
 void RandomSelect(const MassIndex& stt, const MassIndex& end) {
     results.push_back(stt);
     while (!xs.empty() || !ys.empty()) {
         MassIndex mass;
         mass.x = stt.x;
         mass.y = stt.y;
         if (!results.empty()) {
             mass.x = !xs.empty() ? xs.front() : end.x;
             mass.y = !ys.empty() ? ys.front() : end.y;
         }
         if (ys.empty() || (!xs.empty() && (rand() % 2 == 0))) {
             mass.x += 1;
             xs.pop_front();
         } else {
             mass.y += 1;
             ys.pop_front();
         }
         results.push_back(mass);
     }
 }
示例#25
0
 Task popTask()
 {
     boost::unique_lock<boost::mutex> tasksLock(m_tasksMutex);
     while(m_tasks.empty() && !m_threadExit)
         m_tasksChangedCondition.wait(tasksLock);
     if(m_tasks.empty())
         return 0;
     Task t = m_tasks.front();
     m_tasks.pop_front();
     return t;
 }
示例#26
0
	const MutationCandidate<value_t> & getMutationCandidate() {
		if(mutationCandidates.empty()) {
			throw std::logic_error("No mutation candidates available.");
		}
		uint32_t & mutationCount = mutationCandidates.front().mutationCount;
		++mutationCount;

		// Find the first element with a value not less the new mutationCount
		auto firstElem = std::lower_bound(mutationCandidates.begin(),
										  mutationCandidates.end(),
										  mutationCount,
										  mutationCountLess);
		if(firstElem == mutationCandidates.begin()) {
			// If the only entry is the first one itself, nothing has to be done
			return mutationCandidates.front();
		}
		auto swapPosition = std::prev(firstElem);
		std::iter_swap(swapPosition, mutationCandidates.begin());
		return *swapPosition;
	}
// Copies a list of descriptors into a matrix of descriptor rows.
void listToMatrix(const std::deque<Descriptor>& list, cv::Mat& matrix) {
  int num_descriptors = list.size();
  CHECK(!list.empty());
  int num_dimensions = list.front().data.size();
  matrix.create(num_descriptors, num_dimensions, cv::DataType<float>::type);

  for (int i = 0; i < num_descriptors; i += 1) {
    cv::Mat row = matrix.row(i);
    std::copy(list[i].data.begin(), list[i].data.end(), row.begin<float>());
  }
}
示例#28
0
    task_type pop_task() {
        boost::unique_lock<boost::mutex> lock(tasks_mutex_);
        while (tasks_.empty()) {
            cond_.wait(lock);
        }

        task_type ret = tasks_.front();
        tasks_.pop_front();

        return ret;
    }
示例#29
0
  bool nextLocation(void)
  {
    if (mWalkList.empty())  // 더 이상 목표 지점이 없으면 false 리턴
      return false;
    mDestination = mWalkList.front(); // 큐의 가장 앞에서 꺼내기
    mWalkList.pop_front(); // 가장 앞 포인트를 제거
    mDirection = mDestination - mProfessorNode->getPosition( ); // 방향 계산
    mDistance = mDirection.normalise( ); // 거리 계산

    return true;
  }
示例#30
0
CCopasiMessage CCopasiMessage::getFirstMessage()
{
  if (mMessageDeque.empty())
    CCopasiMessage(CCopasiMessage::RAW,
                   MCCopasiMessage + 1);

  CCopasiMessage Message(mMessageDeque.front());
  mMessageDeque.pop_front();

  return Message;
}