Skip to content

Commit 2aebc91

Browse files
committed
worker: add thread-local instance of Random
1 parent bf460f7 commit 2aebc91

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

core/worker.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
#include "opts.h"
5050
#include "packet.h"
5151
#include "scheduler.h"
52+
#include "utils/random.h"
5253
#include "utils/time.h"
5354

5455
using bess::Scheduler;
@@ -265,6 +266,7 @@ int Worker::BlockWorker() {
265266
/* The entry point of worker threads */
266267
void *Worker::Run(void *_arg) {
267268
struct thread_arg<Task> *arg = (struct thread_arg<Task> *)_arg;
269+
rand_ = new Random();
268270

269271
cpu_set_t set;
270272

@@ -308,6 +310,7 @@ void *Worker::Run(void *_arg) {
308310
<< ")";
309311

310312
delete scheduler_;
313+
delete rand_;
311314

312315
return nullptr;
313316
}

core/worker.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include "pktbatch.h"
4343
#include "traffic_class.h"
4444
#include "utils/common.h"
45+
#include "utils/random.h"
4546

4647
// XXX
4748
typedef uint16_t gate_idx_t;
@@ -124,6 +125,8 @@ class Worker {
124125

125126
bess::PacketBatch **splits() { return splits_; }
126127

128+
Random *rand() const { return rand_; }
129+
127130
private:
128131
volatile worker_status_t status_;
129132

@@ -145,6 +148,8 @@ class Worker {
145148
* Modules should use get_igate() for access */
146149
gate_idx_t current_igate_;
147150

151+
Random *rand_;
152+
148153
// For each possible output gate contains a pointer to a batch, or nullptr,
149154
// if no batch has been associated with the output gate yet.
150155
//

0 commit comments

Comments
 (0)