From fb469842598da834a33f2d5fee223d07dab53dad Mon Sep 17 00:00:00 2001
From: wangzhengquan <wangzhengquan85@126.com>
Date: 星期四, 16 七月 2020 12:12:20 +0800
Subject: [PATCH] update
---
queue/include/array_lock_free_queue.h | 4 ++--
queue/libshm_queue.a | 0
test/test_lockfree_queue | 0
test/test_timeout | 0
test/multiple_queue_consumer | 0
test/test_lockfree_queue.c | 18 ++++++++++++++++++
test/multiple_queue_productor | 0
queue/socket.cb | 0
test/test_queue | 0
test/Makefile | 2 +-
test/test_lostdata | 0
test/single_consumer | 0
queue/include/shm_allocator.h | 12 ++++++++----
test/single_productor | 0
queue/include/lock_free_queue.h | 13 +++++--------
15 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/queue/include/array_lock_free_queue.h b/queue/include/array_lock_free_queue.h
index 0ba35ae..24a4ec6 100644
--- a/queue/include/array_lock_free_queue.h
+++ b/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);
}
diff --git a/queue/include/lock_free_queue.h b/queue/include/lock_free_queue.h
index ca8adb4..566c7ed 100644
--- a/queue/include/lock_free_queue.h
+++ b/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
diff --git a/queue/include/shm_allocator.h b/queue/include/shm_allocator.h
index 700f786..6d9dcc6 100644
--- a/queue/include/shm_allocator.h
+++ b/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);
}
};
diff --git a/queue/libshm_queue.a b/queue/libshm_queue.a
index 4e74e18..3fe8324 100644
--- a/queue/libshm_queue.a
+++ b/queue/libshm_queue.a
Binary files differ
diff --git a/queue/socket.c b/queue/socket.cb
similarity index 100%
rename from queue/socket.c
rename to queue/socket.cb
diff --git a/test/Makefile b/test/Makefile
index 6b4c25c..b48f536 100755
--- a/test/Makefile
+++ b/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)
diff --git a/test/multiple_queue_consumer b/test/multiple_queue_consumer
new file mode 100755
index 0000000..aa870b4
--- /dev/null
+++ b/test/multiple_queue_consumer
Binary files differ
diff --git a/test/multiple_queue_productor b/test/multiple_queue_productor
new file mode 100755
index 0000000..9d4855c
--- /dev/null
+++ b/test/multiple_queue_productor
Binary files differ
diff --git a/test/single_consumer b/test/single_consumer
new file mode 100755
index 0000000..d99582b
--- /dev/null
+++ b/test/single_consumer
Binary files differ
diff --git a/test/single_productor b/test/single_productor
new file mode 100755
index 0000000..fb7dc24
--- /dev/null
+++ b/test/single_productor
Binary files differ
diff --git a/test/test_lockfree_queue b/test/test_lockfree_queue
new file mode 100755
index 0000000..1e4e62f
--- /dev/null
+++ b/test/test_lockfree_queue
Binary files differ
diff --git a/test/test_lockfree_queue.c b/test/test_lockfree_queue.c
new file mode 100644
index 0000000..81beff6
--- /dev/null
+++ b/test/test_lockfree_queue.c
@@ -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();
+}
diff --git a/test/test_lostdata b/test/test_lostdata
new file mode 100755
index 0000000..c16a113
--- /dev/null
+++ b/test/test_lostdata
Binary files differ
diff --git a/test/test_queue b/test/test_queue
new file mode 100755
index 0000000..13e6b2a
--- /dev/null
+++ b/test/test_queue
Binary files differ
diff --git a/test/test_timeout b/test/test_timeout
new file mode 100755
index 0000000..d354f12
--- /dev/null
+++ b/test/test_timeout
Binary files differ
--
Gitblit v1.8.0