`
byytj
  • 浏览: 48746 次
  • 来自: ...
文章分类
社区版块
存档分类
最新评论

queue sample

阅读更多

http://www.iteye.com/topic/477412

 

#include "StdAfx.h"
#include "TaskQueue.h"

#include <process.h>
#include <boost/thread/shared_mutex.hpp>
#include <boost/thread.hpp>


using namespace std;


typedef boost::shared_mutex rwmutex;
typedef boost::shared_lock<rwmutex> readLock;
typedef boost::unique_lock<rwmutex> writeLock;
rwmutex _rwmutex;

static TaskQueue* taskQueueInstance;

TaskQueue::TaskQueue()
{
}

TaskQueue::~TaskQueue(void)
{
}

TaskQueue* TaskQueue::GetInstance()
{
 if(taskQueueInstance == NULL)
 {
  taskQueueInstance = new TaskQueue();
 }

 return taskQueueInstance;
}

int TaskQueue::GetSize()
{
 try
 {
  int size = TQ.size();
  return size;
 }
 catch (const std::exception& ex)
 {
  fprintf(stderr, "reason: %s\n", ex.what());
  return 0;
 }
}

void TaskQueue::GetQueue(queue<taskInfo>& queueTaskInfo)
{
 writeLock lk(_rwmutex);
 try
 {
  queueTaskInfo = TQ;
  lk.unlock();
 }
 catch (const std::exception& ex)
 {
  fprintf(stderr, "reason: %s\n", ex.what());
 }
}

void TaskQueue::Push(taskInfo ti)
{
 writeLock lk(_rwmutex);
 try
 {
  TQ.push(ti);
  lk.unlock();
 }
 catch (const std::exception& ex)
 {
  fprintf(stderr, "reason: %s\n", ex.what());
 }
}

void TaskQueue::Front(taskInfo& ti)
{
 if(TQ.size()>0)
 {
  writeLock lk(_rwmutex);
  ti = TQ.front();
  lk.unlock();
 }
}

void TaskQueue::Back()
{
 if(TQ.size()>0)
 {
  writeLock lk(_rwmutex);
  TQ.back();
  lk.unlock();
 }
}

void TaskQueue::Pop()
{
 if(TQ.size()>0)
 {
  writeLock lk(_rwmutex);
  TQ.pop();
  lk.unlock();
 }
}

void TaskQueue::Empty()
{
 writeLock lk(_rwmutex);
 while(!TQ.empty())
 {
  TQ.pop();
 }
 lk.unlock();
}

 

 

#pragma once
#include "DataModel.h"
#include <queue>

class TaskQueue
{
public:
 static TaskQueue* TaskQueue::GetInstance();

 queue<taskInfo> TQ;
 int TaskQueue::GetSize();
 void TaskQueue::GetQueue(queue<taskInfo>& queueTaskInfo);
 void TaskQueue::Push(taskInfo ti);
 void TaskQueue::Front(taskInfo& ti);
 void TaskQueue::Pop();
 void TaskQueue::Back();
 void TaskQueue::Empty();
public:
 TaskQueue();
 ~TaskQueue(void);
};

分享到:
评论

相关推荐

    windows-driver-kit-81-cpp

    2018\09\10 周一 17:27 &lt;DIR&gt; Cancel-Safe IRP Queue Sample 2018\09\10 周一 17:27 &lt;DIR&gt; CancelSafe File System Minifilter Driver 2018\09\10 周一 17:27 &lt;DIR&gt; CDFS File System Driver 2018\09\10 周一 17:27 ...

    Sample-Queue:用于在azure服务总线上发送和接收异步消息的示例代码

    样本队列 在azure服务总线上发送和接收异步消息的示例代码。

    python-redis-queue-sample:python redis任务队列demo, 自备

    任务队列 环境准备 Python Redis ...RQ ...Redis Server # docker pull redis:latest # docker run -d -p 6379:6379 -t redis:latest RqWorker 启动rqworker,等待任务 ...from rq import Queue from rq.j

    object-queue:测试项目

    this x 3,465 ops/sec ±2.66% (90 runs sampled) fifo x 142,633 ops/sec ±0.84% (97 runs sampled) Fastest is fifo 如你所见,这段代码没用,所以使用 先进先出 使用对象实现的 Javascript FIFO 队列 用法很...

    ORACLE消息队列样例

    oracle AQ的样例程序。 init子目录 -create_admin.sql -create_privilege.sql -create_queue. -create_user.sql -install.bat plsql子目录 -sample.sql

    redis-message-queue

    如何用消息队列分离功能一般在设计微服务时,会将功能进行一些拆分到独立的服务中。...该项目(sample)采用 redis 当着消息队列,分别起了3个服务。consumer.js 消息的消费者服务(收到消息后发送邮件)producer.js

    celery_sample:芹菜练习

    初始设定 雷迪斯 sh redis/run.sh Python pipenv install pipenv shell 运行客户端 ...#sample celery -A task worker -l info -Q email_task_queue_name -c 1 -n worker-1 --prefetch-multiplier=1

    my-csharp-sample

    System.Collections 下 ArrayList、Hashtable、Queue、SortedList、Stack 操作的例子 A0001_Partial partial 关键字的使用例子 A0002_Assert Debug.Assert 实现 断言 处理的使用例子 A0003_TraceLog Trace 方法 实现...

    spring-websocket-chat-sample

    // config.enableStompBrokerRelay("/topic/", "/queue/"); config.enableSimpleBroker("/topic/", "/queue/"); 至: config.enableStompBrokerRelay("/topic/", "/queue/"); // config.enableSimpleBroker("/...

    rabbitmq_sample_app:这是带有rabbitmq和swiftmailer的示例应用程序

    如果当前时间在定义的暂停时间中,则将相应的SMS类型消息推送到新的自定义队列名称“ sms_queue” process_sms_queue.php-此文件处理名为“ sms_queue”的定制定义队列中的消息。 该文件将在暂停时间的定义时间...

    MQ服务消息队列介绍

    3)在QM_JACK下创建名为"QUEUE_RECV"和"QUEUE_REPLY"的本地队列(客户可以根据自己的需求随意更改本地队列的名字和数量,这里创建这两个本地队列只是为之后的MQ_Tuxedo项目作准备): 设置队列名后其他属性全为...

    串口通讯控件

    - BaseTerm sample queue status dialog made non-modal and auto-refreshing. - Other minor presentational improvements to BaseTerm sample. - Corrected bugs which caused occasional crashes on port ...

    C# wpf 多线程

    The CSWPFThreading sample project illustrates two WPF threading models. The first one divides a long-running process into many snippets of workitems. Then the dispather of WPF will pick up the work...

    C#中遍历各类数据集合的方法

    C#中遍历各类数据集合的方法总结:  1.枚举类型 //遍历枚举类型Sample的各个枚举名称 ...遍历ArrayList(Queue、Stack)  这里以string为例,当然ArrayList中的元素可以是任何数据类型,遍历时须确认Ar

    C#中遍历各类数据集合的方法总结

    C#中遍历各类数据集合的方法,这里自己做下总结: 1.枚举类型 代码如下: //遍历枚举类型Sample的各个...遍历ArrayList(Queue、Stack) 这里以string为例,当然ArrayList中的元素可以是任何数据类型,遍历时须确认ArrayL

    activemq简单实例

    activemq简单实例 运行后可以在页面查看相关信息 http://127.0.0.1:8161/admin/queueConsumers.jsp?JMSDestination=sample.queue

    队列与堆栈在Delphi中的使用

    队列与堆栈在Delphi中的使用示例,供初学者参考!-Queue and stack in Delphi, the use of reference sample for beginners.

    stomp-copy:从 STOMP 队列中读取消息并将消息写入 CouchDB 数据库的小程序

    复制 一个从 STOMP 队列读取并将消息写入 CouchDB 数据库的小程序。 在本地运行 node index.js &lt;host&gt; ...将文件manifest-sample.yml复制到文件manifest.yml并将host属性更改为在您的 Cloud Foundry 实例中唯一的主

    grpc-kit-service

    Amlaki-房屋服务如何开始复制config / default-sample.json并将其重命名为default.json在开发模式下运行gin -i --notifications run start招摇swag init兔子MQ发布消息首先创建发布者(在包的初始化上) rabbitmq....

    botbot-bot:BotBot.me的IRC机器人

    botbot.me中使用的bot是Go(1.2+)程序。 安装: ...外部资源: 具有在schema.sql定义的架构的Postgres数据库。 一个Redis数据库,用作插件和bot之间的消息总线。 从botbot_sample.dump加载样本数据...QUEUE_URL=red

Global site tag (gtag.js) - Google Analytics