当前位置: 首页>>代码示例>>C++>>正文


C++ queue::push方法代码示例

本文整理汇总了C++中std::queue::push方法的典型用法代码示例。如果您正苦于以下问题:C++ queue::push方法的具体用法?C++ queue::push怎么用?C++ queue::push使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在std::queue的用法示例。


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

示例1: while

/**
 * @brief Read a ACK message from USB
 */
void *waitForACK()
{
    uint8_t ack[10] = {0};

    while (1) {

        if (fd == -1)
            break;

        if (select(fd + 1, &set, NULL, NULL, &timeout) > 0) {
            read(fd, &ack[0], ACK_SIZE);
            ack_lock.lock();
            ack_queue.push(ack);
            ack_lock.unlock();
        }
    }
    return NULL;
}
开发者ID:Oxbern,项目名称:CCube_API,代码行数:21,代码来源:fd_test.cpp

示例2: push

            /**
             * Push an element onto the queue. If the queue has a max size, this
             * call will block if the queue is full.
             */
            void push(T value) {
                if (m_max_size) {
                    while (size() >= m_max_size) {
                        std::this_thread::sleep_for(full_queue_sleep_duration);
#ifdef OSMIUM_DEBUG_QUEUE_SIZE
                        ++m_full_counter;
#endif
                    }
                }
                std::lock_guard<std::mutex> lock(m_mutex);
                m_queue.push(std::move(value));
#ifdef OSMIUM_DEBUG_QUEUE_SIZE
                if (m_largest_size < m_queue.size()) {
                    m_largest_size = m_queue.size();
                }
#endif
                m_data_available.notify_one();
            }
开发者ID:Androidized,项目名称:osrm-backend,代码行数:22,代码来源:queue.hpp

示例3: usrpGetData

// Thread to import data from the USRP !Size of the arrays in complex -> 2*buffer_size !
void usrpGetData(uhd::rx_streamer::sptr rx_stream,uhd::usrp::multi_usrp::sptr dev, size_t buffer_size){

  // Set highest priority for this thread
  set_realtime_priority();

  // Create storage for a single buffer from USRP
  short *buff_short;
  buff_short=new short[2*buffer_size]; 

  // Initialisation  
  size_t n_rx_last;
  uhd::rx_metadata_t md;
  //int time=buffer_size/(25)-100; // microsecondes

  while (1){
    n_rx_last=0;

    // Fill buff_short
    while (n_rx_last==0) {
      n_rx_last=rx_stream->recv(&buff_short[0], buffer_size, md, 3.0);
      std::this_thread::yield(); // Avoid active waiting
    };

    // Check if no overflow
    if (n_rx_last!=buffer_size) {
      std::cerr << "I expect the buffer size to be always the same!\n";
      std::cout<<"Read only:"<<n_rx_last<<"\n";
      std::cout<<"Buffer:"<<buffer_size<<"\n";
      //exit(1); 
    };

    // Add the just received buffer to the queue
    mtxUsrp.lock();
    usrpQ.push(buff_short);
    mtxUsrp.unlock();
    // Change memory cell used
    buff_short=new short [2*buffer_size];

    // Gives the start to detection part
    sem_post( &usrpReady); 

    std::this_thread::sleep_for(std::chrono::microseconds(5));
  }//end while 1
}
开发者ID:tony2909,项目名称:green,代码行数:45,代码来源:rx_3.cpp

示例4: bbm_ane_bbmsp_contact_copy

//BBMSP_API bbmsp_result_t bbmsp_contact_copy(bbmsp_contact_t* destination, const bbmsp_contact_t* source);
FREObject bbm_ane_bbmsp_contact_copy(FREContext ctx, void* functionData, uint32_t argc, FREObject argv[]) {
    uint32_t imageID;
    contact_data_s *contactData;

    FREGetObjectAsUint32(argv[0],&imageID);

    contactData = (contact_data_s *)malloc( sizeof(contact_data_s) );
    contactData->id = imageID;
    contactData->action = COPY_CONTACT;
    contactData->id2 = rand();

    pthread_mutex_lock(&contactMutex);
    contactQueue.push(contactData);
    pthread_mutex_unlock(&contactMutex);

    FREObject result;
    FRENewObjectFromUint32(contactData->id2, &result);
    return result;
}
开发者ID:cmy82,项目名称:bb10-ane-bbm,代码行数:20,代码来源:BBMSPContactlist.cpp

示例5: main

int main()
{
    std::ifstream input(BINARY_DIR"/input.txt", std::ios::binary);
    SyncClass sc;
    for(int i = 0;i < THREADS_COUNT; i++)
        threads.create_thread(boost::bind(&SyncClass::writeMessage, &sc) );

    while(!input.eof()){
        Message msg(input);
        if(input.eof())
            break;
        boost::mutex::scoped_lock lock(queueMutex);
        msgQueue.push(msg);
    }
    sc.stopWorking();
    threads.join_all();

    return 0;
}
开发者ID:Gedeon-by,项目名称:cpp_craft_0314,代码行数:19,代码来源:binary_datafeed.cpp

示例6: push

				int push(const T &item, CThread *thr, unsigned int timeoutMsec)
				{
                    std::chrono::duration<unsigned int, std::milli> duration(timeoutMsec);

					std::unique_lock<std::mutex> lock(m_mutex);
					while(isFull())
					{
						m_condNotEmpty.wait_for(lock, duration);
						if (thr->isTerminated()) return -1;
					}
					if (thr->isTerminated()) return -1;
					
					m_rwmut.lock();
						m_que.push(item);
					m_rwmut.unlock();
					
					m_condNotFull.notify_all();
					return 0;
				}
开发者ID:SmartActiveNode2,项目名称:san2,代码行数:19,代码来源:cproducerconsumer.hpp

示例7: producer

void producer()
{
	int i = 0;
	while (1)
	{
		boost::this_thread::sleep(boost::posix_time::millisec(1000));
		boost::mutex::scoped_lock lock(m);      

		while (itemQ.size() > max_size_q)
		{
			std::cout << "Q Full.notify_one Producer Waiting" << std::endl;
			qFull.wait(lock);
			std::cout << "Producer Notified to Continue" << std::endl;
		}

		itemQ.push(++i);
		qEmpty.notify_one();
	}

}
开发者ID:slobberydeadpunk,项目名称:Elite,代码行数:20,代码来源:Main.cpp

示例8: handleAsyncResolve

	void CPluginTransportTCP::handleAsyncResolve(const boost::system::error_code & err, boost::asio::ip::tcp::resolver::iterator endpoint_iterator)
	{
		if (!err)
		{
			boost::asio::ip::tcp::endpoint endpoint = *endpoint_iterator;
			m_Socket->async_connect(endpoint, boost::bind(&CPluginTransportTCP::handleAsyncConnect, this, boost::asio::placeholders::error, ++endpoint_iterator));
		}
		else
		{
			delete m_Resolver;
			m_Resolver = NULL;
			delete m_Socket;
			m_Socket = NULL;

			//			_log.Log(LOG_ERROR, "Plugin: Connection Exception: '%s' connecting to '%s:%s'", err.message().c_str(), m_IP.c_str(), m_Port.c_str());
			ConnectedMessage*	Message = new ConnectedMessage(m_HwdID, err.value(), err.message());
			boost::lock_guard<boost::mutex> l(PluginMutex);
			PluginMessageQueue.push(Message);
		}
	}
开发者ID:ldrolez,项目名称:domoticz,代码行数:20,代码来源:PluginTransports.cpp

示例9: push

  void push(const hasher::job_t* const job) {
    while(true) {
      // get job queue size
      lock();
      size_t size = job_queue.size();
      unlock();
      if (size < max_queue_size) {

        // add job to queue now
        lock();
        job_queue.push(job);
        unlock();
        break;

      } else {
        // try again later
        sched_yield();
      }
    }
  }
开发者ID:NPS-DEEP,项目名称:hashdb,代码行数:20,代码来源:job_queue.hpp

示例10: queueAction

// Add an action to the queue
long queueAction(Action action) {
	// Timeout for a lock on queue
	::timeval i,e;
	::gettimeofday(&i,NULL);
	while(queue_lock) {
		::gettimeofday(&e,NULL);
		// 100 ms timeout
		if((e.tv_usec-i.tv_usec) > 100000) {
			return -1;
		}
	};
	// Add an action to the queue
	queue_lock = true;
	actionQueue.push(action);
	queue_lock = false;
	// Set id to id_counter
	action.id = id_counter;
	id_counter++;
	return id_counter;
}
开发者ID:cwruRobotics,项目名称:NASA-RMC-2015-16,代码行数:21,代码来源:MotorControl.cpp

示例11: audio_delivery

static int audio_delivery(sp_session *sess, const sp_audioformat *format,
                          const void *frames, int num_frames)
{
    SDL_mutexP(g_audio_mutex);

    if (num_frames == 0)
    {
        SDL_mutexV(g_audio_mutex);
        return 0;
    }

    if (g_audio_queue.size() > MAX_REQUEST_BUFFER_COUNT)
    {
        SDL_mutexV(g_audio_mutex);
        return 0;
    }

    assert(format->sample_rate == SDL_AUDIO_SAMPLE_RATE);
    assert(format->channels == SDL_AUDIO_CHANNELS);
    assert(format->sample_type == SP_SAMPLETYPE_INT16_NATIVE_ENDIAN);

    //
    // Push SDL_AUDIO_BUFFER_FRAMES to the audio layer even if `num_frames`
    // delievered by Spotify is less than this (worst case is 1 second silence
    // if num_frames = 1 since we feed SDL chunks of 1 second audio at a time).
    //
    // NOTE: Abusing the memory allocator like this should be pretty OK since
    // we're basically re-using the same chunks all over again. Yeah I'm lazy.'
    //

    {
        uint8_t* chunk = new uint8_t[SDL_AUDIO_REQUEST_SIZE];
        memset(chunk, 0, SDL_AUDIO_REQUEST_SIZE);
        memcpy(chunk, frames, num_frames * SDL_AUDIO_SAMPLE_SIZE * SDL_AUDIO_CHANNELS);
        g_audio_queue.push(chunk);
    }

    SDL_mutexV(g_audio_mutex);

    return SDL_AUDIO_BUFFER_FRAMES;
}
开发者ID:bkz,项目名称:libspotify-sdl,代码行数:41,代码来源:jukebox.cpp

示例12: Midpoint

void SteerLib::GJK_EPA::UpdateEars(std::queue<Util::Vector>& ears, std::vector<struct edges> edges, std::vector<Util::Vector> shape)
{
	for (int i = 0; i < shape.size(); i++) {
		Util::Vector curr = shape[i];
		Util::Vector n1, n2, testpoint;

		for (int j = 0; j < edges.size(); j++) {
			if (edges[j].point == curr) {
				n1 = edges[j].neighbor1;
				n2 = edges[j].neighbor2;

				break;
			}
		}

		// Get midpoint of the two neighbors
		testpoint = Midpoint(n1, n2);

		// Test the midpoint 
		// If it lies within the polygon, it's good
		bool result = false;
		int k, j;
		for (k = 0, j = shape.size() - 1; k < shape.size(); j = k++) {
			if ((shape[k].z > testpoint.z) != (shape[j].z > testpoint.z) && (testpoint.x < (shape[j].x - shape[k].x) * (testpoint.z - shape[k].z) / (shape[j].z - shape[k].z) + shape[k].x)) {
				result = !result;
			}
		}

		// TODO ONLY IF THEY'RE GONNA HAVE OTHER TEST CASES
		// Need to do check if point is on an edge

		// If midpoint is a point on shape, it's not an ear
		if (std::find(shape.begin(), shape.end(), testpoint) != shape.end())
			result = false;

		if (result) {
			if(!EarCheck(ears, shape[i]))
				ears.push(shape[i]);
		}
	}
}
开发者ID:CG-F15-26-Rutgers,项目名称:SteerLiteFinal,代码行数:41,代码来源:GJK_EPA.cpp

示例13: split

void DataLibrary::split(std::string& s, std::string c,std::queue<std::string>& v) 
{
	/*std::string::size_type i = 0;
	std::string::size_type j = s.find(c);

	while (j != std::string::npos) 
	{
		v.push(s.substr(i, j-i));
		i = ++j;
		j = s.find(c, j);

		if (j == std::string::npos)
			v.push(s.substr(i, s.length( )));
	}*/
	std::vector<std::string> a;
	boost::algorithm::split(a,s, boost::is_any_of(c));
	for(std::vector<std::string>::iterator it=a.begin();it!=a.end();it++)
	{
		v.push((*it));
	}
}
开发者ID:parhelia512,项目名称:fdux-slg-game,代码行数:21,代码来源:DataLibrary.cpp

示例14: transfer

void BlockDevRequest::transfer ( const BlockDevOp op, const uint32_t dramaddr, const uint32_t offset, const uint32_t size, const uint32_t tag )
{
  if (0) fprintf(stderr, "BlockDevRequest::transfer op=%x dramaddr=%x offset=%x size=%x tag=%x\n", op, dramaddr, offset, size, tag);
  if (fpgaDev->mainMemBuf) {
    if (op == BlockDevRead) {
      int numBytes = pread(driveFd, fpgaDev->mainMemBuf + dramaddr, size, offset);
      if (numBytes != (long)size)
	fprintf(stderr, "Read error size=%d numBytes=%d errno=%d:%s\n", size, numBytes, errno, strerror(errno));
    } else {
      int numBytes = pwrite(driveFd, fpgaDev->mainMemBuf + dramaddr, size, offset);
      if (numBytes != (long)size)
	fprintf(stderr, "Read error size=%d numBytes=%d errno=%d:%s\n", size, numBytes, errno, strerror(errno));
    }
  }
  {
      std::lock_guard<std::mutex> lock(rqmutex);
      responseQueue.push(tag);
      sem_post(&worker_sem);
  }

}
开发者ID:acw1251,项目名称:connectal,代码行数:21,代码来源:fpgadev.cpp

示例15: match_callback

 void match_callback(const cyphy_vslam_msgs::MatchConstPtr &msg)
 {
     image_cache::GetImage srv;
     srv.request.from = msg->fromImgSeq;
     srv.request.to.clear();
     for(unsigned int i=0; i < msg->toImgSeq.size(); i++)
     { 
         m_proposed_++;
         ROS_INFO("Verifying FAB-MAP match %d to %d (republished index) ...",msg->fromImgSeq,msg->toImgSeq[i]);
         if( (msg->fromImgSeq-msg->toImgSeq[i]) < window_frame_size_)
         {
             ROS_INFO("Failed, match is within local window");
             continue;
         }
         srv.request.to.push_back(msg->toImgSeq[i]);
     }
     srv.request.rectified = 1;
     boost::mutex::scoped_lock lock(m_mutex_);  // Don't touch the service when I'm adding to it
     if(!srv.request.to.empty())
         srv_queue_.push(srv);
 }
开发者ID:yimingyanged,项目名称:youbot,代码行数:21,代码来源:geometric_verification.cpp


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