When a single sender thread sends data and a single receiver thread receives that data, you can use this class to transfer data in a lock-free manner.
More...
#include "nn/nlib/LockFree.h"
|
| LockFreePipe () noexcept |
| Instantiates the object with default parameters (default constructor).
|
|
size_t | GetBufferSize () noexcept |
| Returns the buffer size. This is thread-safe.
|
|
errno_t | Read (void *dest, size_t nbytes) noexcept |
| Reads data from a pipe. This is thread-safe. More...
|
|
errno_t | Write (const void *src, size_t nbytes) noexcept |
| Writes data to a pipe. This is thread-safe. More...
|
|
template<size_t N>
class nn::nlib::LockFreePipe< N >
When a single sender thread sends data and a single receiver thread receives that data, you can use this class to transfer data in a lock-free manner.
- Template Parameters
-
N | The size of the buffer. This value must be a power of two. |
- Description
- Note that data is copied via a buffer. This class is suited for transferring data of a medium or small size. By using two
LockFreePipe
, you can send and receive data each other between two threads.
- Sample code
LockFreePipe<1024> pipe;
.....
{
.....
uint8_t command[16];
.....
while (pipe.Write(command, sizeof(command)) != 0) {
}
.....
}
{
.....
uint8_t command[16];
while (pipe.Read(command, sizeof(command)) != 0) {
}
.....
}
Definition at line 349 of file LockFree.h.
§ Read()
Reads data from a pipe. This is thread-safe.
- Parameters
-
[out] | dest | The region that stores read data. |
[in] | nbytes | The number of bytes to be read. |
- Return values
-
0 | Success. |
EAGAIN | The buffer contains data of less than nbytes bytes. |
Definition at line 358 of file LockFree.h.
§ Write()
Writes data to a pipe. This is thread-safe.
- Parameters
-
[in] | src | The region that stores data to be written. |
[in] | nbytes | The number of bytes to be written. |
- Return values
-
0 | Success. |
EAGAIN | The amount of free space in the buffer is less than nbytes bytes. |
Definition at line 389 of file LockFree.h.
The documentation for this class was generated from the following files: