高性能流媒体服务器-nebula之数据结构(9)--双锁并发队列

本文介绍了基于Maged M. Michael和Michael L. Scott的双锁并发队列算法,实现了C++版本,并应用于流媒体服务器场景。该队列适用于单生产者/多消费者、多生产者/多消费者或多生产者/单消费者的场景,使用spinlock作为互斥锁,同时采用无锁内存池进行高效内存分配。
摘要由CSDN通过智能技术生成

这是根据 Maged M. Michael and Michael L. Scott提出的双锁并发队列算法实现的c++版本,主要应用场景为:单生产者/多消费者或多生产者/多消费者或多生产者/单消费者的情况,在实现中,我们用spinlock作为互斥锁;内存分配采用了无锁内存池进行分配。

<pre name="code" class="cpp">//
//  aqueue.h
//  nebula
//
//  Created by yi.cheng on 15/10/8.
//  Copyright © 2015 year kanshansoft. All rights reserved.
//

#ifndef aqueue_h
#define aqueue_h
#include <core/mem/lfalloctor.h>
#include <core/Errors.h>
#include <core/guard.h>
#include <utils/Log.h>
/**
Two-Lock Concurrent Queue Algorithm

structure node_t {value: data type, next: pointer to node_t}
structure queue_t {Head: pointer to node_t, Tail: pointer to node_t,
    H_lock: lock type, T_lock: lock type}

initialize(Q: pointer to queue_t)
node = new_node()		        // Allocate a free node
node->next = NULL               // Make it the only node in the linked list
Q->Head = Q->Tail = node	    // Both Head and Tai
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值