1
0
Mirror von https://github.com/tkuschel/bees.git synchronisiert 2026-06-19 06:57:54 +02:00

bytevector: add some fugly mutexes

We are using ByteVectors from multiple threads in some cases.  Mostly
these are the status and progress threads which read the ByteVector
object references embedded in BEESNOTE macros.

Since it's not clear what the data race implications are, protect
the shared_ptr in ByteVector with a mutex for now.

Signed-off-by: Zygo Blaxell <bees@furryterror.org>
Dieser Commit ist enthalten in:
Zygo Blaxell
2021-12-13 23:56:44 -05:00
Ursprung d1015b683f
Commit a59d89ea81
2 geänderte Dateien mit 38 neuen und 2 gelöschten Zeilen
+5 -2
Datei anzeigen
@@ -2,6 +2,7 @@
#define _CRUCIBLE_BYTEVECTOR_H_
#include <memory>
#include <mutex>
#include <ostream>
#include <cstdint>
@@ -21,6 +22,8 @@ namespace crucible {
using iterator = value_type*;
ByteVector() = default;
ByteVector(const ByteVector &that);
ByteVector& operator=(const ByteVector &that);
ByteVector(size_t size);
ByteVector(const ByteVector &that, size_t start, size_t length);
ByteVector(iterator begin, iterator end, size_t min_size = 0);
@@ -49,6 +52,8 @@ namespace crucible {
private:
Pointer m_ptr;
size_t m_size = 0;
mutable mutex m_mutex;
friend ostream & operator<<(ostream &os, const ByteVector &bv);
};
template <class T>
@@ -66,8 +71,6 @@ namespace crucible {
{
return reinterpret_cast<T*>(data());
}
ostream & operator<<(ostream &os, const ByteVector &bv);
}
#endif // _CRUCIBLE_BYTEVECTOR_H_