Skip to content

Commit

Permalink
core: initialize random udp package id using nanosecond timestamp (#1270
Browse files Browse the repository at this point in the history
)
  • Loading branch information
rex-schilasky authored and FlorianReimold committed Jan 23, 2024
1 parent df44d40 commit eeffbcd
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions ecal/core/src/io/snd_raw_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
* @brief raw message buffer handling
**/

#include <chrono>
#include <mutex>
#include <thread>

#include "ecal_process.h"
Expand Down Expand Up @@ -129,8 +131,18 @@ namespace eCAL
msg_header.type = msg_type_header;
{
// create random number for message id
static unsigned long x = 123456789, y = 362436069, 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 eeffbcd

Please sign in to comment.