13
0

Fix rt-safe PRNG (seed once, not every call)

This commit is contained in:
Robin Gareus 2021-08-15 15:24:23 +02:00
parent 76a01bab63
commit e4d1d82ea7
Signed by: rgareus
GPG Key ID: A090BCE02CF57F04
2 changed files with 6 additions and 5 deletions

View File

@ -27,6 +27,7 @@
#include <glibmm/threads.h>
#include "pbd/pcg_rand.h"
#include "pbd/stateful.h"
#include "pbd/ringbuffer.h"
@ -245,6 +246,8 @@ class LIBARDOUR_API TriggerBox : public Processor
Glib::Threads::RWLock trigger_lock; /* protects all_triggers */
Triggers all_triggers;
PBD::PCGRand _pcg;
/* These three are accessed (read/write) only from process() context */
void drop_triggers ();

View File

@ -8,7 +8,6 @@
#include "pbd/basename.h"
#include "pbd/compose.h"
#include "pbd/failed_constructor.h"
#include "pbd/pcg_rand.h"
#include "temporal/tempo.h"
@ -990,8 +989,7 @@ TriggerBox::set_next_trigger (size_t current)
}
int which_follow_action;
PCGRand pcg;
int r = pcg.rand (0, 101);
int r = _pcg.rand (0, 101);
if (r <= all_triggers[current]->follow_action_probability()) {
which_follow_action = 0;
@ -1079,7 +1077,7 @@ TriggerBox::set_next_trigger (size_t current)
case Trigger::AnyTrigger:
while (true) {
n = pcg.rand (0, all_triggers.size() + 1);
n = _pcg.rand (0, all_triggers.size() + 1);
if (!all_triggers[n]->region()) {
continue;
}
@ -1093,7 +1091,7 @@ TriggerBox::set_next_trigger (size_t current)
case Trigger::OtherTrigger:
while (true) {
n = pcg.rand (0, all_triggers.size() + 1);
n = _pcg.rand (0, all_triggers.size() + 1);
if ((size_t) n == current) {
continue;
}