1
0
mirror of https://github.com/Zygo/bees.git synced 2025-06-15 17:26:15 +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>
This commit is contained in:
Zygo Blaxell
2021-12-13 23:56:44 -05:00
parent d1015b683f
commit a59d89ea81
2 changed files with 38 additions and 2 deletions

View File

@ -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_