diff options
author | Marcus Müller <marcus@hostalia.de> | 2018-10-01 13:12:09 +0200 |
---|---|---|
committer | Andrej Rode <mail@andrejro.de> | 2018-11-22 23:57:28 +0100 |
commit | 94af848ebe70450a655685d74a75b1977fa120c9 (patch) | |
tree | f2f0eb7404de6eb06f41a29036f9cd9b6a11b4c0 /gr-trellis/lib | |
parent | a0d6ebe944a2814578280a32869ecca5da57fd49 (diff) |
Invisible API change: Replace rand() with xoroshiro128+ for thread safety
Since this changes the interleaver, this is a compatibility-breaking
change. This can thus only happen in a minor release (i.e. 3.8).
Diffstat (limited to 'gr-trellis/lib')
-rw-r--r-- | gr-trellis/lib/interleaver.cc | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/gr-trellis/lib/interleaver.cc b/gr-trellis/lib/interleaver.cc index 9653ee1b76..eb7998b8ce 100644 --- a/gr-trellis/lib/interleaver.cc +++ b/gr-trellis/lib/interleaver.cc @@ -29,6 +29,7 @@ #include <cmath> #include <gnuradio/trellis/quicksort_index.h> #include <gnuradio/trellis/interleaver.h> +#include <gnuradio/xoroshiro128p.h> namespace gr { namespace trellis { @@ -107,18 +108,29 @@ namespace gr { d_INTER.resize(d_K); d_DEINTER.resize(d_K); - if(seed>=0) - srand((unsigned int)seed); + uint64_t rng_state[2]; + xoroshiro128p_seed(rng_state, seed); std::vector<int> tmp(d_K); + unsigned char *bytes = reinterpret_cast<unsigned char*>(&tmp[0]); + + for(unsigned int i = 0; i < d_K; i += 8) { + *(reinterpret_cast<uint64_t*>(bytes + i)) = xoroshiro128p_next(rng_state); + } + if(d_K % 8) { + uint64_t randval = xoroshiro128p_next(rng_state); + unsigned char *valptr = reinterpret_cast<unsigned char*>(&randval); + for(unsigned int idx = (d_K / 8)*8; idx < d_K; ++idx) { + bytes[idx] = *valptr++; + } + } for(int i=0;i<d_K;i++) { - d_INTER[i]=i; - tmp[i] = rand(); + d_INTER[i]=i; } quicksort_index <int> (tmp,d_INTER,0,d_K-1); // generate DEINTER table for(int i=0;i<d_K;i++) { - d_DEINTER[d_INTER[i]]=i; + d_DEINTER[d_INTER[i]]=i; } } |