Skip to content

Commit 5d5bc01

Browse files
committed
Dedicated array to store threads per vendor ...
1 parent 2e422c8 commit 5d5bc01

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

src/bridge/grpc_collector_bridge.cc

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -224,23 +224,33 @@ extern "C" {
224224
std::exit(EXIT_FAILURE);
225225
}
226226

227-
// Use a vector to store the worker threads
228-
std::vector<pthread_t> workers(MAX_WORKERS);
227+
// Use arrays to store the worker threads per vendor
228+
pthread_t cisco_workers[MAX_WORKERS] = {0};
229+
pthread_t juniper_workers[MAX_WORKERS] = {0};
230+
pthread_t huawei_workers[MAX_WORKERS] = {0};
229231

230232
// Cisco
231-
LoadThreads(workers.data(), "ipv4_socket_cisco", "replies_cisco",
233+
LoadThreads(cisco_workers, "ipv4_socket_cisco", "replies_cisco",
232234
"cisco_workers");
233235

234236
// Juniper
235-
LoadThreads(workers.data(), "ipv4_socket_juniper", "replies_juniper",
237+
LoadThreads(juniper_workers, "ipv4_socket_juniper", "replies_juniper",
236238
"juniper_workers");
237239

238240
// Huawei
239-
LoadThreads(workers.data(), "ipv4_socket_huawei", "replies_huawei",
241+
LoadThreads(huawei_workers, "ipv4_socket_huawei", "replies_huawei",
240242
"huawei_workers");
241243

242-
for (size_t w = 0; w < MAX_WORKERS; w++) {
243-
pthread_detach(workers[w]);
244+
for (size_t w = 0; w < MAX_WORKERS && cisco_workers[w] != 0; w++) {
245+
pthread_detach(cisco_workers[w]);
246+
}
247+
248+
for (size_t w = 0; w < MAX_WORKERS && juniper_workers[w] != 0; w++) {
249+
pthread_detach(juniper_workers[w]);
250+
}
251+
252+
for (size_t w = 0; w < MAX_WORKERS && huawei_workers[w] != 0; w++) {
253+
pthread_detach(huawei_workers[w]);
244254
}
245255
}
246256

@@ -357,8 +367,7 @@ extern "C" {
357367
"and 5. (default = 1)", workers_str);
358368
std::exit(EXIT_FAILURE);
359369
}
360-
size_t w;
361-
for (w = 0; w < workers; w++) {
370+
for (size_t w = 0; w < workers; w++) {
362371
int res = pthread_create(&workers_vec[w], NULL, VendorThread,
363372
(void *)ipv4_socket_str);
364373
if (res != 0) {

src/bridge/grpc_collector_bridge.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#ifdef __cplusplus
1717
extern "C" {
1818
#endif
19-
#define MAX_WORKERS 15
19+
#define MAX_WORKERS 5
2020

2121
typedef struct {
2222
/* main */

0 commit comments

Comments
 (0)