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

C++ lockfree::queue类代码示例

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

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



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

示例1: consumer

void consumer(void)
{
    int value;
    while (!done) {
        while (queue.pop(value))
            ++consumer_count;
    }

    while (queue.pop(value))
        ++consumer_count;
}
开发者ID:softarts,项目名称:test,代码行数:11,代码来源:boostthread.cpp


示例2: ProcessRequestStatistics

static void ProcessRequestStatistics (TRI_request_statistics_t* statistics) {
  {
    MUTEX_LOCKER(RequestDataLock);

    TRI_TotalRequestsStatistics.incCounter();

    if (statistics->_async) {
      TRI_AsyncRequestsStatistics.incCounter();
    }

    TRI_MethodRequestsStatistics[(int) statistics->_requestType].incCounter();

    // check that the request was completely received and transmitted
    if (statistics->_readStart != 0.0 && statistics->_writeEnd != 0.0) {
      double totalTime = statistics->_writeEnd - statistics->_readStart;
      TRI_TotalTimeDistributionStatistics->addFigure(totalTime);

      double requestTime = statistics->_requestEnd - statistics->_requestStart;
      TRI_RequestTimeDistributionStatistics->addFigure(requestTime);

      double queueTime = 0.0;

      if (statistics->_queueStart != 0.0 && statistics->_queueEnd != 0.0) {
        queueTime = statistics->_queueEnd - statistics->_queueStart;
        TRI_QueueTimeDistributionStatistics->addFigure(queueTime);
      }

      double ioTime = totalTime - requestTime - queueTime;

      if (ioTime >= 0.0) {
        TRI_IoTimeDistributionStatistics->addFigure(ioTime);
      }

      TRI_BytesSentDistributionStatistics->addFigure(statistics->_sentBytes);
      TRI_BytesReceivedDistributionStatistics->addFigure(statistics->_receivedBytes);
    }
  }

  // clear statistics
  statistics->reset(); 

  // put statistics item back onto the freelist
#ifdef TRI_ENABLE_MAINTAINER_MODE
  bool ok = RequestFreeList.push(statistics);
  TRI_ASSERT(ok);
#else
  RequestFreeList.push(statistics);
#endif
}
开发者ID:CedarLogic,项目名称:arangodb,代码行数:49,代码来源:statistics.cpp


示例3: worker_thread

    /* 
     * The worker_thread blocks in this loop. 
     * As a member function, it must be binded with this ptr.
     */
    void worker_thread() {

        for (;;) {
            boost::mutex::scoped_lock lock(this->tp_mutex);
            cv.wait(lock);
            if (work_queue.empty())
                continue;
            work_t w;
            if (work_queue.pop(w))
                w->run();
            else
                thread_run_error();
        }

    }
开发者ID:SevenHe,项目名称:Linux,代码行数:19,代码来源:ftp_class.hpp


示例4: main

int main(int argc, char* argv[])
{
    using namespace std;
    cout << "boost::lockfree::queue is ";
    if (!queue.is_lock_free())
        cout << "not ";
    cout << "lockfree" << endl;
    
    boost::chrono::steady_clock::time_point start = boost::chrono::steady_clock::now();
    
    

    boost::thread_group producer_threads, consumer_threads;

    for (int i = 0; i != producer_thread_count; ++i)
        producer_threads.create_thread(producer);

    for (int i = 0; i != consumer_thread_count; ++i)
        consumer_threads.create_thread(consumer);

    producer_threads.join_all();
    done = true;

    consumer_threads.join_all();
    boost::chrono::duration<double> sec = boost::chrono::steady_clock::now() - start;
    cout << "f() took " << sec.count() << " seconds\n";

    cout << "produced " << producer_count << " objects." << endl;
    cout << "consumed " << consumer_count << " objects." << endl;
}
开发者ID:softarts,项目名称:test,代码行数:30,代码来源:boostthread.cpp


示例5: push_work

 /* Push a work, it will run automatically. */
 bool push_work(work_t w) {
     if (w->c && work_queue.push(w)) {
         cv.notify_one();
         return true;
     }
     return false;
 }
开发者ID:SevenHe,项目名称:Linux,代码行数:8,代码来源:ftp_class.hpp


示例6: get_withoutWaiting

  // Must NOT be called without first calling wait()
  T get_withoutWaiting(){
    T ret = 0;
    
    R_ASSERT(queue.pop(ret));

    return ret;
  }
开发者ID:dieface,项目名称:radium-1,代码行数:8,代码来源:Queue.hpp


示例7: tryPut

  // returns false if queue was full
  bool tryPut(T t){
    if (queue.bounded_push(t)) {
      ready.signal();
      return true;
    }

    return false;
  }
开发者ID:dieface,项目名称:radium-1,代码行数:9,代码来源:Queue.hpp


示例8: producer

void producer(void)
{
    for (int i = 0; i != iterations; ++i) {
        int value = ++producer_count;
        while (!queue.push(value))
            ;
    }
}
开发者ID:softarts,项目名称:test,代码行数:8,代码来源:boostthread.cpp


示例9: consumer

void consumer(void)
{
    int value;
    //当没有生产完毕,则边消费边生产
    while(!done)
    {
        while(queue.pop(value))
        {
            cout<<"-"<<endl;
            ++c_count;
        }
    }
    //如果生产完毕则消费
    while(queue.pop(value))
    {
        ++c_count;
    }
}
开发者ID:chijinxina,项目名称:Boost-Learning,代码行数:18,代码来源:lockfree_queue.cpp


示例10: producer

void producer(void)
{
    for(int i=0; i < iterations; ++i)
    {
        //原子计数---多线程不存在计数不上的情况
        int value = ++p_count;
        cout<<"+"<<endl;   //观察生产类型: 纯生产还是同时有消费者的情况
        while(!queue.push(value));
    }
}
开发者ID:chijinxina,项目名称:Boost-Learning,代码行数:10,代码来源:lockfree_queue.cpp


示例11: TRI_ReleaseConnectionStatistics

void TRI_ReleaseConnectionStatistics (TRI_connection_statistics_t* statistics) {
  if (statistics == nullptr) {
    return;
  }
  
  {
    MUTEX_LOCKER(ConnectionDataLock);

    if (statistics->_http) {
      if (statistics->_connStart != 0.0) {
        if (statistics->_connEnd == 0.0) {
          TRI_HttpConnectionsStatistics.incCounter();
        }
        else {
          TRI_HttpConnectionsStatistics.decCounter();

          double totalTime = statistics->_connEnd - statistics->_connStart;
          TRI_ConnectionTimeDistributionStatistics->addFigure(totalTime);
        }
      }
    }
  }

  // clear statistics
  statistics->reset();

  // put statistics item back onto the freelist
#ifdef TRI_ENABLE_MAINTAINER_MODE  
  bool ok = ConnectionFreeList.push(statistics);
  TRI_ASSERT(ok);
#else
  ConnectionFreeList.push(statistics);
#endif
}
开发者ID:CedarLogic,项目名称:arangodb,代码行数:34,代码来源:statistics.cpp


示例12: MotorOn

bool ElmoDriver::MotorOn()
{
	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'M';
	message.DATA[1] = 'O';

	//for(int i=2; i<8; i++)
	//	message.DATA[i] = (i == 4 ? 1 : 0);

	message.DATA[2] = 0;
	message.DATA[3] = 0;

	message.DATA[4] = 1;
	message.DATA[5] = 0;
	message.DATA[6] = 0;
	message.DATA[7] = 0;


	return CAN_Write_Queue.push(message);
	
}
开发者ID:geniuskpj,项目名称:usrc,代码行数:25,代码来源:ElmoDriver.cpp


示例13: iPA

bool ElmoDriver::iPA(float degree)
{
	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

    int temp = (int) (2000.0*degree/180.0*gear_m);
	//cout << "angle = " << temp << endl; 
	BYTE value[4];

	memcpy(value, &temp, sizeof(int));

	message.DATA[0] = 'O';
	message.DATA[1] = 'V';

	message.DATA[2] = 0x13;
	message.DATA[3] = 0;

	for(int i=0; i<4; i++)
		message.DATA[4+i] = value[i];

	return CAN_Write_Queue.push(message);
 
}
开发者ID:geniuskpj,项目名称:usrc,代码行数:25,代码来源:ElmoDriver.cpp


示例14: SetIPMode

bool ElmoDriver::SetIPMode()
{
	static TPCANMsg message;
	
	message.ID = 6*128+id;
	message.LEN = 8;

	message.DATA[0] = 'O';
	message.DATA[1] = 'F';
	message.DATA[2] = 0x07;

	for(int i=3; i<8; i++)
		message.DATA[i] = (i == 4 ? 0x07 : 0);
	/*
	CAN_Write_Queue.push(message);

	message.DATA[0] = 'O';
	message.DATA[1] = 'V';
	message.DATA[2] = 0x17;

	for(int i=3; i<8; i++)
		message.DATA[i] = (i == 4 ? 0x0A : 0);
	*/
	return CAN_Write_Queue.push(message); 
}
开发者ID:geniuskpj,项目名称:usrc,代码行数:25,代码来源:ElmoDriver.cpp


示例15: GetCurrent

bool ElmoDriver::GetCurrent()
{

    static TPCANMsg message;
    message.ID = 6*128+id;
    message.LEN = 4;
    message.DATA[0] = 'I';
    message.DATA[1] = 'Q';
    message.DATA[2] = 0;
    message.DATA[3] = 0;
    return CAN_Write_Queue.push(message);
/*
    int temppos = 0x00;
if (data1[0]=='I' && data1[1]=='Q')
    {
    temppos |= (data1[7] << 24);
    temppos |= (data1[6] << 16);
    temppos |= (data1[5] << 8);
    temppos |= (data1[4]);
    val= *(float *)&temppos;
    return 1;
    }
    val=temppos;
    return 0;
*/
}
开发者ID:geniuskpj,项目名称:usrc,代码行数:26,代码来源:ElmoDriver.cpp


示例16: DC

bool ElmoDriver::DC(float dcc, bool set)
{
	static TPCANMsg message;

	message.ID = 6*128+id;
    if (set == true)
    {
        message.LEN = 8;
        int temp = (int) (dcc*gear_m);
        BYTE value[4];
        memcpy(value, &temp, sizeof(int));
        for(int i=0; i<4; i++)
        message.DATA[4+i] = value[i];
    }
    else
    {
        message.LEN = 4;
    }




    message.DATA[0] = 'D';
    message.DATA[1] = 'C';

    message.DATA[2] = 0;
    message.DATA[3] = 0;



	return CAN_Write_Queue.push(message);
 
}
开发者ID:geniuskpj,项目名称:usrc,代码行数:33,代码来源:ElmoDriver.cpp


示例17: PA

bool ElmoDriver::PA(int count)
{
//	float deg = (float) degree;
//	return PA(deg);

	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	int temp = count;
	//cout << "angle = " << temp << endl; 
	BYTE value[4];

	memcpy(value, &temp, sizeof(int));

	message.DATA[0] = 'P';
	message.DATA[1] = 'A';

	message.DATA[2] = 0;
	message.DATA[3] = 0;

	for(int i=0; i<4; i++)
		message.DATA[4+i] = value[i];

	return CAN_Write_Queue.push(message);
}
开发者ID:geniuskpj,项目名称:usrc,代码行数:27,代码来源:ElmoDriver.cpp


示例18: TCEqualMinusOne

bool ElmoDriver::TCEqualMinusOne()
{

	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	float temp = -0.5;

	BYTE current[4];

	memcpy(current, &temp, sizeof(float));

	message.DATA[0] = 'T';
	message.DATA[1] = 'C';
	message.DATA[2] = 0x0;
	message.DATA[3] = 128;

	//for(int i=0; i<3; i++)
	//	message.DATA[4+i] = current[i];

	message.DATA[4] = current[0];
	message.DATA[5] = current[1];
	message.DATA[6] = current[2];
	message.DATA[7] = current[3];

	return CAN_Write_Queue.push(message);

}
开发者ID:geniuskpj,项目名称:usrc,代码行数:30,代码来源:ElmoDriver.cpp


示例19: TCEqualZero

bool ElmoDriver::TCEqualZero()
{

	static TPCANMsg message;

	message.ID = 6*128+id;
	message.LEN = 8;

	float temp = 0.0;

	BYTE current[4];

	memcpy(current, &temp, sizeof(float));

	message.DATA[0] = 'T';
	message.DATA[1] = 'C';
	message.DATA[2] = 0x0;
	message.DATA[3] = 128;

	for(int i=0; i<3; i++)
		message.DATA[4+i] = current[i];

	return CAN_Write_Queue.push(message);

}
开发者ID:geniuskpj,项目名称:usrc,代码行数:25,代码来源:ElmoDriver.cpp


示例20: clear

 void clear()
 {
     void * p;
     while ( stack_.unsynchronized_pop(p) )
     {
         znn_free(p);
     }
 }
开发者ID:Nuzhny007,项目名称:znn-release,代码行数:8,代码来源:lockfree_cube_pool.hpp



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C++ concepts::std_real_concept类代码示例发布时间:2022-05-31
下一篇:
C++ interprocess::file_lock类代码示例发布时间: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