From bc2d5855b90846fb189e688b973d30054cc3c527 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Mon, 25 Oct 2021 20:36:27 -0500 Subject: [PATCH] cleanup and changes --- src/app/debug_log.onyx | 8 +++++ src/app/work_units.onyx | 47 +++++++++++++++---------- src/features/hex_editor/hex_viewer.onyx | 17 ++++----- src/features/wasm/wasm.onyx | 5 ++- src/ui/menubar.onyx | 9 +++-- 5 files changed, 54 insertions(+), 32 deletions(-) diff --git a/src/app/debug_log.onyx b/src/app/debug_log.onyx index fa054ec..f703cef 100644 --- a/src/app/debug_log.onyx +++ b/src/app/debug_log.onyx @@ -135,6 +135,14 @@ draw_debug_log :: (window_rectangle: ui.Rectangle, site := #callsite) { r.x0 += (200.0f / ~~workers_used.count); r.x1 = r.x0 + (200.0f / ~~workers_used.count); } + + r.x0 = clear_button_rect.x0; + r.x1 = clear_button_rect.x1; + r.y0 += 50; + r.y1 += 25; + + buf: [128] u8; + ui.draw_text(r, conv.str_format(buf, "H: {}\n", alloc.heap.get_watermark())); } #private_file log_buffer : struct { diff --git a/src/app/work_units.onyx b/src/app/work_units.onyx index 8730559..0f3c2c0 100644 --- a/src/app/work_units.onyx +++ b/src/app/work_units.onyx @@ -46,22 +46,6 @@ work_unit_submit :: (data: rawptr, func: (rawptr) -> Work_Unit_Status) { sync.mutex_unlock(^work_unit_mutex); } -work_unit_insert :: (w: ^Work_Unit) { - sync.mutex_lock(^work_unit_mutex); - - if first_work_unit == null { - first_work_unit = w; - } else { - work_unit := first_work_unit; - while work_unit.next != null do work_unit = work_unit.next; - - work_unit.next = w; - } - - sync.semaphore_post(^work_unit_signal, 1); - sync.mutex_unlock(^work_unit_mutex); -} - workers_being_used :: () -> [WORKER_COUNT] bool { used: [WORKER_COUNT] bool; for i: WORKER_COUNT { @@ -88,12 +72,34 @@ worker_threads : [WORKER_COUNT] thread.Thread; work_unit_buffer : [] Work_Unit; work_unit_pool : alloc.pool.PoolAllocator(Work_Unit); -next_work_unit_id : i32; +next_work_unit_id := 0; first_work_unit : ^Work_Unit; work_unit_mutex : sync.Mutex; work_unit_signal : sync.Semaphore; +work_unit_insert :: (w: ^Work_Unit) { + sync.mutex_lock(^work_unit_mutex); + + if first_work_unit == null { + first_work_unit = w; + } else { + work_unit := first_work_unit; + while work_unit.next != null do work_unit = work_unit.next; + + work_unit.next = w; + } + + sync.semaphore_post(^work_unit_signal, 1); + sync.mutex_unlock(^work_unit_mutex); +} + +work_unit_done :: (w: ^Work_Unit) { + sync.mutex_lock(^work_unit_mutex); + alloc.pool.pool_free(^work_unit_pool, w); + sync.mutex_unlock(^work_unit_mutex); +} + work_unit_processor :: (thread_data: ^Worker_Data) { while true { sync.semaphore_wait(^work_unit_signal); @@ -111,6 +117,11 @@ work_unit_processor :: (thread_data: ^Worker_Data) { switch result { case .Failed { debug_log(.Error, "Work unit {} failed.", next_work_unit_id); + fallthrough; + } + + case .Success { + work_unit_done(work_unit); } case .Not_Done { @@ -122,4 +133,4 @@ work_unit_processor :: (thread_data: ^Worker_Data) { } } -} \ No newline at end of file +} diff --git a/src/features/hex_editor/hex_viewer.onyx b/src/features/hex_editor/hex_viewer.onyx index 523cd08..5b844f9 100644 --- a/src/features/hex_editor/hex_viewer.onyx +++ b/src/features/hex_editor/hex_viewer.onyx @@ -1,16 +1,16 @@ package feature.hex_viewer #private_file { - app :: package app + app :: package app editor :: package editor - ui :: package ui + ui :: package ui config :: package config -} -use package core -use package debug { debug_log } + use package core + use package debug { debug_log } +} -window_id :: "hex_viewer" +window_id :: "hex_viewer" window_name :: "Hex Viewer" Hex_Viewer_State :: struct { @@ -44,6 +44,7 @@ window_draw :: (use viewer_state: ^Hex_Viewer_State, win: ^app.Application_Windo win.window_state.max_size.x = (10 + 1 + 3 * 16 + 2 + 16) * em_height; if !app.state.has_active_file { + text_theme.font_size = 5.0f; ui.draw_text(r, "No loaded file.", theme=^text_theme); return; } @@ -146,11 +147,11 @@ window_draw :: (use viewer_state: ^Hex_Viewer_State, win: ^app.Application_Windo } open_window :: () { - app.open_window(window_id, window_name, .{ 0, 0 }, window_draw, .{ 1300, 650 }, draw_data=^global_viewer_state); + app.open_window(window_id, window_name, .zero, window_draw, .{1300,650}, draw_data=^global_viewer_state); app.move_window_to_top(window_id); app.focus_window(window_id); - app.open_window("dummy", "DUMMY TESTING", .{ 0, 0 }, + app.open_window("dummy", "DUMMY TESTING", .zero, (_, win) => { (package editor).editor_window_draw(hex_window, win); }); } diff --git a/src/features/wasm/wasm.onyx b/src/features/wasm/wasm.onyx index 88f0195..ade7ef6 100644 --- a/src/features/wasm/wasm.onyx +++ b/src/features/wasm/wasm.onyx @@ -97,7 +97,7 @@ process_file :: (_) => { file_data := app.state.file.data; debug_log(.Info, "Wasm feature noticed file dropped with size {}", file_data.count); - if !string.starts_with(file_data, u8.[ 0, #char "a", #char "s", #char "m" ]) do return app.Work_Unit_Status.Failed; + if !string.starts_with(file_data, u8.[ 0, #char "a", #char "s", #char "m" ]) do return .Failed; debug_log(.Info, "THIS IS PROBABLY A WASM BINARY. ANALYZING!!!"); @@ -112,10 +112,9 @@ process_file :: (_) => { wasm_analyzed = true; - return app.Work_Unit_Status.Success; + return .Success; } file_loaded :: () { app.work_unit_submit(null, process_file); - // thread.spawn(^wasm_processing_thread, null, process_file); } diff --git a/src/ui/menubar.onyx b/src/ui/menubar.onyx index 8a259b5..638c884 100644 --- a/src/ui/menubar.onyx +++ b/src/ui/menubar.onyx @@ -30,10 +30,13 @@ menubar :: (r: Rectangle, @Temporary search_buffer: ^String_Buffer, options: [] button_rect : Rectangle; - for option: options |> iter.from_array() |> iter.enumerate() { + idx := 0; + for ^option: options { + defer idx += 1; + button_rect, menu_rect = Flow.split_vertical(menu_rect, left_width=100); - if button(Flow.padding(button_rect, right=4), option.value.label, theme=^menu_button_theme, increment=option.index) { - option.value.action(); + if button(Flow.padding(button_rect, right=4), option.label, theme=^menu_button_theme, increment=idx) { + option.action(); } } -- 2.25.1