Skip to content

Commit

Permalink
Return thread handles from new runThreads
Browse files Browse the repository at this point in the history
Re-implement the logic of `run` as a function that returns the handles
which can then be joined by the caller.
Most usage sites require a bit of thought with respect to the
order of operations, so `GossipService.run` remains as a wrapper
around the new logic.
This also makes it take a `message_allocator`.
  • Loading branch information
InKryption committed May 31, 2024
1 parent 0fdd396 commit 570ee93
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 77 deletions.
11 changes: 10 additions & 1 deletion src/cmd/cmd.zig
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ fn gossip() !void {
&.{},
);
defer gossip_service.deinit();

try runGossipWithConfigValues(&gossip_service);
}

Expand Down Expand Up @@ -571,8 +572,16 @@ fn initRepair(
}

fn runGossipWithConfigValues(gossip_service: *GossipService) !void {
// TODO: use better allocator, unless GPA becomes more performant.
var gp_message_allocator: std.heap.GeneralPurposeAllocator(.{}) = .{};
defer _ = gp_message_allocator.deinit();

const gossip_config = config.current.gossip;
return gossip_service.run(gossip_config.spy_node, gossip_config.dump);
return gossip_service.run(.{
.message_allocator = gp_message_allocator.allocator(),
.spy_node = gossip_config.spy_node,
.dump = gossip_config.dump,
});
}

/// determine our shred version and ip. in the solana-labs client, the shred version
Expand Down
8 changes: 7 additions & 1 deletion src/gossip/fuzz.zig
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,13 @@ pub fn run() !void {
.noop,
);

var fuzz_handle = try std.Thread.spawn(.{}, GossipService.run, .{ &gossip_service_fuzzer, true, false });
const fuzz_handle = try std.Thread.spawn(.{}, GossipService.run, .{
&gossip_service_fuzzer, .{
.message_allocator = allocator,
.spy_node = true,
.dump = false,
},
});

const SLEEP_TIME = 0;
// const SLEEP_TIME = std.time.ns_per_ms * 10;
Expand Down
Loading

0 comments on commit 570ee93

Please sign in to comment.