-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* main multithread done * mutexes optimised, typo fixed, callback group for handling queue added * feat: reworked multi-thread logic Lock-free queue from boost library is used to store images in newly allocated memory StampedImagePtr is changed to be trivially contructable, destructable and copyable * fix: PR requested changes Minor changes implemented * fix: memory allocation Checked with address sanitizer, fixed allocations Added logs in assigning master camera idx fixed bug with assigning master camera idx when flag hardware_trigger is false * debug, fix: added debug logging added and commented performance data: CPU time and logs related to lock-free queue deleted redundunt static param from CameraNode class * feat: lock-free queue redone implemented PR requested changes deleted debug code * minor codestyle fix in lock-free queue * fix: minor codestyle in lock-free queue.h fix: queue latency changed in order to provide publishing up to 30 FPS * fix: abort() replaced with exit() fix: exit code * feat: reworked acync approach to implement reqeusted changes * fix: added separate queues fix: buffer allocation fixed, tested up to 40 fps * fix: minor fixes after rebase * fix: codestyle with pre-commit * feat: PR requested changes implemented * fix: lock-free queue bug fixed * feat: storing raw pointers in queues instead of undexes * fix: lvalue, rvalue fixed in loadFromParams static method * fix: override for destructor added
- Loading branch information
Showing
10 changed files
with
466 additions
and
137 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
*.db3 | ||
|
||
#ROS2 builds | ||
packages/build | ||
packages/install | ||
packages/log | ||
**/build | ||
**/install | ||
**/log | ||
**/Camera |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
#pragma once | ||
|
||
#include <atomic> | ||
#include <vector> | ||
|
||
namespace handy { | ||
|
||
/* | ||
Node consists of the value itself and index of the vector where it was added | ||
this index is required to solve ABA problem | ||
*/ | ||
template<typename T> | ||
struct Node { | ||
T value; | ||
// generation is changed on each assignment and then used to determine | ||
// whether this Node was changed by different thread or not | ||
std::atomic<int> generation{0}; | ||
}; | ||
|
||
template<typename T> | ||
class LockFreeQueue { | ||
public: | ||
explicit LockFreeQueue(int size) { | ||
data_ = std::vector<Node<T>>(size); | ||
for (int i = 0; i < size; ++i) { | ||
data_[i].generation.store(i); | ||
} | ||
} | ||
|
||
LockFreeQueue(LockFreeQueue&& other) = delete; | ||
LockFreeQueue(const LockFreeQueue& other) = delete; | ||
|
||
bool push(const T& value) { | ||
// while could not proccess | ||
while (true) { | ||
int snap = tail_.load(); | ||
if (snap - head_.load() == data_.size()) { | ||
// buffer is full and can't be updated | ||
// in fact, slot can be freed during verification, but we do not double-check | ||
return false; | ||
} | ||
|
||
if (data_[snap % data_.size()].generation < snap || | ||
!tail_.compare_exchange_weak(snap, snap + 1)) { | ||
// desired cell in buffer was already used by another thread | ||
// let's try again | ||
continue; | ||
} | ||
|
||
data_[snap % data_.size()].value = value; | ||
// next possible push will be at (current_tail + 1) minimum | ||
// so we add +1 | ||
data_[snap % data_.size()].generation += 1; | ||
return true; | ||
} | ||
} | ||
|
||
bool pop(T& data) { | ||
while (true) { | ||
int snap = head_.load(); | ||
if (tail_.load() - snap == 0) { | ||
// buffer is empty and can't be updated | ||
// in fact, slot can be freed during verification, but we do not double-check | ||
return false; | ||
} | ||
|
||
if (data_[snap % data_.size()].generation <= snap) { | ||
return false; | ||
} | ||
if (!head_.compare_exchange_weak(snap, snap + 1)) { | ||
// desired cell in buffer was already used by another thread | ||
// let's try again | ||
continue; | ||
} | ||
|
||
data = data_[snap % data_.size()].value; | ||
// store a value that is for sure larger that any tail, so, + size of buffer | ||
data_[snap % data_.size()].generation.store(snap + data_.size()); | ||
return true; | ||
} | ||
} | ||
|
||
private: | ||
// head ------- tail | ||
std::vector<Node<T>> data_; | ||
std::atomic<int> head_ = 0; | ||
std::atomic<int> tail_ = 0; | ||
}; | ||
} // namespace handy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.