cleanup and changes
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 26 Oct 2021 01:36:27 +0000 (20:36 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Tue, 26 Oct 2021 01:36:27 +0000 (20:36 -0500)
src/app/debug_log.onyx
src/app/work_units.onyx
src/features/hex_editor/hex_viewer.onyx
src/features/wasm/wasm.onyx
src/ui/menubar.onyx

index fa054ec20f9d5804c9939f00f98db990d64956f9..f703cef30ec5c3734a6706be8ab94a328690eb8d 100644 (file)
@@ -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 {
index 873055964a9ebf723133b2ca767cfc85bd2bb35a..0f3c2c0b1f65627bb204f77272b0055629681b85 100644 (file)
@@ -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
+}
index 523cd0819a59e2c273bdc18cf1f14e526441f905..5b844f9de09b9c2bc164b2edf249f9f2bf47ce29 100644 (file)
@@ -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); });
 }
 
index 88f01957449a07d127c0689ca581eec2defe45de..ade7ef663c4aaa9fadc4fb2119153614baa1dd95 100644 (file)
@@ -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);
 }
index 8a259b564c3b20a39d7977b687247f95165e5a90..638c884b7095720c5645233a30d63a52aa3e09af 100644 (file)
@@ -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();
         }
     }