Skip to content

Commit 0973284

Browse files
committed
Updated README and co in preparation of merging readerwritercircularbuffer.h to master
1 parent a384375 commit 0973284

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ add_library(${PROJECT_NAME} INTERFACE)
77

88
target_include_directories(readerwriterqueue INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})
99

10-
install(FILES atomicops.h readerwriterqueue.h LICENSE.md
10+
install(FILES atomicops.h readerwriterqueue.h readerwritercircularbuffer.h LICENSE.md
1111
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME})

LICENSE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
This license applies to all the code in this repository except that written by third
22
parties, namely the files in benchmarks/ext, which have their own licenses, and Jeff
3-
Preshing's semaphore implementation (used in the blocking queue) which has a zlib
3+
Preshing's semaphore implementation (used in the blocking queues) which has a zlib
44
license (embedded in atomicops.h).
55

66
Simplified BSD License:
77

8-
Copyright (c) 2013-2015, Cameron Desrochers
8+
Copyright (c) 2013-2021, Cameron Desrochers
99
All rights reserved.
1010

1111
Redistribution and use in source and binary forms, with or without modification,

README.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ you could use this queue completely from a single thread if you wish (but that w
77

88
Note: If you need a general-purpose multi-producer, multi-consumer lock free queue, I have [one of those too][mpmc].
99

10+
This repository also includes a [circular-buffer SPSC queue][circular] which supports blocking on enqueue as well as dequeue.
11+
1012

1113
## Features
1214

@@ -25,7 +27,7 @@ Note: If you need a general-purpose multi-producer, multi-consumer lock free que
2527

2628
## Use
2729

28-
Simply drop the readerwriterqueue.h and atomicops.h files into your source code and include them :-)
30+
Simply drop the readerwriterqueue.h (or readerwritercircularbuffer.h) and atomicops.h files into your source code and include them :-)
2931
A modern compiler is required (MSVC2010+, GCC 4.7+, ICC 13+, or any C++11 compliant compiler should work).
3032

3133
Note: If you're using GCC, you really do need GCC 4.7 or above -- [4.6 has a bug][gcc46bug] that prevents the atomic fence primitives
@@ -94,6 +96,25 @@ means care must be taken to only call `wait_dequeue` if you're sure another elem
9496
will come along eventually, or if the queue has a static lifetime. This is because
9597
destroying the queue while a thread is waiting on it will invoke undefined behaviour.
9698

99+
The blocking circular buffer has a fixed number of slots, but is otherwise quite similar to
100+
use:
101+
102+
```cpp
103+
BlockingReaderWriterCircularBuffer<int> q(1024); // pass initial capacity
104+
105+
q.try_enqueue(1);
106+
int number;
107+
q.try_dequeue(number);
108+
assert(number == 1);
109+
110+
q.wait_enqueue(123);
111+
q.wait_dequeue(number);
112+
assert(number == 123);
113+
114+
q.wait_dequeue_timed(number, std::chrono::milliseconds(10));
115+
```
116+
117+
97118
## CMake installation
98119
As an alternative to including the source files in your project directly,
99120
you can use CMake to install the library in your system's include directory:
@@ -118,14 +139,6 @@ includes all modern processors (e.g. x86/x86-64, ARM, and PowerPC). *Not* for us
118139
Note that it's only been tested on x86(-64); if someone has access to other processors I'd love to run some tests on
119140
anything that's not x86-based.
120141
121-
Finally, I am not an expert. This is my first foray into lock-free programming, and though I'm confident in the code,
122-
it's possible that there are bugs despite the effort I put into designing and testing this data structure.
123-
124-
Use this code at your own risk; in particular, lock-free programming is a patent minefield, and this code may very
125-
well violate a pending patent (I haven't looked). It's worth noting that I came up with this algorithm and
126-
implementation from scratch, independent of any existing lock-free queues.
127-
128-
129142
## More info
130143
131144
See the [LICENSE.md][license] file for the license (simplified BSD).
@@ -139,3 +152,4 @@ about lock-free programming.
139152
[benchmarks]: http://moodycamel.com/blog/2013/a-fast-lock-free-queue-for-c++#benchmarks
140153
[gcc46bug]: http://stackoverflow.com/questions/16429669/stdatomic-thread-fence-has-undefined-reference
141154
[mpmc]: https://github.com/cameron314/concurrentqueue
155+
[circular]: readerwritercircularbuffer.h

0 commit comments

Comments
 (0)