wangzhengquan
2020-07-16 fb469842598da834a33f2d5fee223d07dab53dad
update
9个文件已添加
1 文件已重命名
5个文件已修改
49 ■■■■■ 已修改文件
queue/include/array_lock_free_queue.h 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
queue/include/lock_free_queue.h 13 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
queue/include/shm_allocator.h 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
queue/libshm_queue.a 补丁 | 查看 | 原始文档 | blame | 历史
queue/socket.cb 补丁 | 查看 | 原始文档 | blame | 历史
test/Makefile 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/multiple_queue_consumer 补丁 | 查看 | 原始文档 | blame | 历史
test/multiple_queue_productor 补丁 | 查看 | 原始文档 | blame | 历史
test/single_consumer 补丁 | 查看 | 原始文档 | blame | 历史
test/single_productor 补丁 | 查看 | 原始文档 | blame | 历史
test/test_lockfree_queue 补丁 | 查看 | 原始文档 | blame | 历史
test/test_lockfree_queue.c 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
test/test_lostdata 补丁 | 查看 | 原始文档 | blame | 历史
test/test_queue 补丁 | 查看 | 原始文档 | blame | 历史
test/test_timeout 补丁 | 查看 | 原始文档 | blame | 历史
queue/include/array_lock_free_queue.h
@@ -94,7 +94,7 @@
    ,m_count(0)           //
#endif
{
    m_theQueue = (ELEM_T*)Allocator::malloc(Q_SIZE * sizeof(ELEM_T));
    m_theQueue = (ELEM_T*)Allocator::allocate(Q_SIZE * sizeof(ELEM_T));
}
@@ -102,7 +102,7 @@
ArrayLockFreeQueue<ELEM_T, Allocator>::~ArrayLockFreeQueue()
{
    // std::cout << "destroy ArrayLockFreeQueue\n";
    Allocator::free(m_theQueue);
    Allocator::deallocate(m_theQueue);
    
}
queue/include/lock_free_queue.h
@@ -73,20 +73,17 @@
class LockFreeQueue
{
    template < typename ELEM_T_ >
    friend class SHMQueue;
private:
    int slots;
    int items;
protected:
     LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE);
public:
    LockFreeQueue(size_t qsize = LOCK_FREE_Q_DEFAULT_SIZE);
    
    /// @brief destructor of the class. 
    /// Note it is not virtual since it is not expected to inherit from this
    /// template
    ~LockFreeQueue();
public:
    std::atomic_uint reference;    
    /// @brief constructor of the class
   
@@ -337,7 +334,7 @@
    typename Allocator,
    template <typename T, typename AT> class Q_TYPE>
void * LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::operator new(size_t size){
        return Allocator::malloc(size);
        return Allocator::allocate(size);
}
template <
@@ -345,7 +342,7 @@
    typename Allocator,
    template <typename T, typename AT> class Q_TYPE>
void LockFreeQueue<ELEM_T, Allocator, Q_TYPE>::operator delete(void *p) {
    return Allocator::free(p);
    return Allocator::deallocate(p);
}
// include implementation files
queue/include/shm_allocator.h
@@ -65,11 +65,13 @@
class SHM_Allocator {
  public:
    static void *malloc (size_t size) {
    static void *allocate (size_t size) {
       printf("shm_allocator malloc\n");
      return mm_malloc(size);
    }
    static void free (void *ptr) {
    static void deallocate (void *ptr) {
      printf("shm_allocator free\n");
      return mm_free(ptr);
    }
};
@@ -77,11 +79,13 @@
class DM_Allocator {
  public:
    static void *malloc (size_t size) {
    static void *allocate (size_t size) {
      printf("dm_allocator malloc\n");
      return malloc(size);
    }
    static void free (void *ptr) {
    static void deallocate (void *ptr) {
      printf("dm_allocator free\n");
      return free(ptr);
    }
};
queue/libshm_queue.a
Binary files differ
queue/socket.cb
test/Makefile
@@ -14,7 +14,7 @@
include $(ROOT)/Make.defines.$(PLATFORM)
 
PROGS =    test_queue single_productor single_consumer multiple_queue_productor multiple_queue_consumer test_timeout test_lostdata
PROGS =    test_queue single_productor single_consumer multiple_queue_productor multiple_queue_consumer test_timeout test_lostdata test_lockfree_queue
build: $(PROGS)
test/multiple_queue_consumer
Binary files differ
test/multiple_queue_productor
Binary files differ
test/single_consumer
Binary files differ
test/single_productor
Binary files differ
test/test_lockfree_queue
Binary files differ
test/test_lockfree_queue.c
New file
@@ -0,0 +1,18 @@
#include "test.h"
#include "shm_allocator.h"
void test() {
        LockFreeQueue<int, DM_Allocator> *queue = new LockFreeQueue<int, DM_Allocator>(16);
        queue->push(12);
        int a;
        queue->pop(a);
        printf("%d\n", a);
        delete queue;
}
int main() {
    test();
    std::cin.get();
}
test/test_lostdata
Binary files differ
test/test_queue
Binary files differ
test/test_timeout
Binary files differ