DoxigAlpha

updateTimeReportGeneric

Function parameters

Parameters

#
ws:*WebServer
step:*Build.Step
ns_total:u64

Type definitions in this namespace

Types

#

Thread-safe.

Functions

#
notifyUpdate
Thread-safe.

Source

Implementation

#
pub fn updateTimeReportGeneric(ws: *WebServer, step: *Build.Step, ns_total: u64) void {
    const gpa = ws.gpa;

    const step_idx: u32 = for (ws.all_steps, 0..) |s, i| {
        if (s == step) break @intCast(i);
    } else unreachable;

    const old_buf = old: {
        ws.time_report_mutex.lock();
        defer ws.time_report_mutex.unlock();
        const old = ws.time_report_msgs[step_idx];
        ws.time_report_msgs[step_idx] = &.{};
        break :old old;
    };
    const buf = gpa.realloc(old_buf, @sizeOf(abi.time_report.GenericResult)) catch @panic("out of memory");
    const out: *align(1) abi.time_report.GenericResult = @ptrCast(buf);
    out.* = .{
        .step_idx = step_idx,
        .ns_total = ns_total,
    };
    {
        ws.time_report_mutex.lock();
        defer ws.time_report_mutex.unlock();
        assert(ws.time_report_msgs[step_idx].len == 0);
        ws.time_report_msgs[step_idx] = buf;
        ws.time_report_update_times[step_idx] = ws.now();
    }
    ws.notifyUpdate();
}