Skip to content

Commit

Permalink
mutex moved
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Nov 24, 2023
1 parent 1657fdc commit f003e58
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions ecal/core/src/io/udp/snd_raw_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@
namespace
{
// random number generator
std::mutex xorshf96_mtx;
unsigned long xorshf96(unsigned long& x, unsigned long& y, unsigned long& z) // period 2^96-1
{
const std::lock_guard<std::mutex> lock(xorshf96_mtx);

unsigned long t;
x ^= x << 16;
x ^= x >> 5;
Expand Down Expand Up @@ -134,12 +131,18 @@ namespace eCAL
msg_header.type = msg_type_header;
{
// create random number for message id
static unsigned long x = std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()
).count();
static unsigned long y = 362436069;
static unsigned long z = 521288629;
msg_header.id = xorshf96(x, y, z);
{
static std::mutex xorshf96_mtx;
const std::lock_guard<std::mutex> lock(xorshf96_mtx);

static unsigned long x = static_cast<unsigned long>(std::chrono::duration_cast<std::chrono::nanoseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch()).count()
);
static unsigned long y = 362436069;
static unsigned long z = 521288629;

msg_header.id = xorshf96(x, y, z);
}
}
msg_header.num = total_packet_num;
msg_header.len = int32_t(buf_len_);
Expand Down

0 comments on commit f003e58

Please sign in to comment.