File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -439,11 +439,24 @@ const mach_task = if (builtin.target.isDarwin()) struct {
439439 }
440440 }
441441
442- pub fn getThreads (task : MachTask ) MachError ! []ThreadId {
442+ const ThreadList = struct {
443+ buf : []ThreadId ,
444+
445+ pub fn deinit (list : ThreadList ) void {
446+ const self_task = machTaskForSelf ();
447+ _ = std .c .vm_deallocate (
448+ self_task .port ,
449+ @ptrToInt (list .buf .ptr ),
450+ @intCast (std .c .vm_size_t , list .buf .len * @sizeOf (std .c .mach_port_t )),
451+ );
452+ }
453+ };
454+
455+ pub fn getThreads (task : MachTask ) MachError ! ThreadList {
443456 var thread_list : std.c.mach_port_array_t = undefined ;
444457 var thread_count : std.c.mach_msg_type_number_t = undefined ;
445458 switch (std .c .getKernError (std .c .task_threads (task .port , & thread_list , & thread_count ))) {
446- .SUCCESS = > return @ptrCast ([* ]ThreadId , thread_list )[0.. thread_count ],
459+ .SUCCESS = > return ThreadList { . buf = @ptrCast ([* ]ThreadId , thread_list )[0.. thread_count ] } ,
447460 else = > | err | {
448461 log .err ("task_threads kernel call failed with error code: {s}" , .{@tagName (err )});
449462 return error .Unexpected ;
You can’t perform that action at this time.
0 commit comments