]> pd.if.org Git - nbds/blobdiff - runtime/lwt.c
Warning tests are failing in this version
[nbds] / runtime / lwt.c
index 8212c5cf00ecaa072a0886f9e282f8a4e80b3ec6..0c3147fe5f18489b9ccef75e6a6c10994d15fea7 100644 (file)
@@ -6,7 +6,7 @@
  */
 #include <stdio.h>
 #include "common.h"
-#include "runtime_local.h"
+#include "rlocal.h"
 #include "lwt.h"
 #include "mem.h"
 
@@ -18,9 +18,9 @@ volatile int halt_ = 0;
 
 typedef struct lwt_record {
     uint64_t timestamp;
-    const char *format;
-    size_t value1;
-    size_t value2;
+    uint64_t format;
+    uint64_t value1;
+    uint64_t value2;
 } lwt_record_t;
 
 typedef struct lwt_buffer {
@@ -54,12 +54,12 @@ void lwt_set_trace_level (const char *flags)
 static inline void dump_record (FILE *file, int thread_id, lwt_record_t *r, uint64_t offset)
 {
     // print the record if its trace category is enabled at a high enough level
-    int flag  =  (size_t)r->format >> 56;
-    int level = ((size_t)r->format >> 48) & 0xFF;
+    int flag  =  r->format >> 56;
+    int level = (r->format >> 48) & 0xFF;
     if (flag_state_[(unsigned)flag] >= level) {
         char s[3] = {flag, level, '\0'};
-        fprintf(file, "%09llu %d %s ", ((uint64_t)r->timestamp - offset) >> 6, thread_id, s);
-        const char *format = (const char *)((size_t)r->format & MASK(48)); // strip out the embedded flags
+        fprintf(file, "%09llu %d %s ", ((uint64_t)r->timestamp - offset) >> 5, thread_id, s);
+        const char *format = (const char *)(size_t)(r->format & MASK(48)); // strip out the embedded flags
         fprintf(file, format, r->value1, r->value2);
         fprintf(file, "\n");
     }
@@ -80,6 +80,10 @@ static void dump_buffer (FILE *file, int thread_id, uint64_t offset)
     }
 }
 
+void lwt_halt (void) {
+    halt_ = 1;
+}
+
 void lwt_dump (const char *file_name)
 {
     halt_ = 1;
@@ -114,9 +118,8 @@ void lwt_dump (const char *file_name)
     }
 }
 
-void lwt_trace_i (const char *format, size_t value1, size_t value2) {
-    if (*(volatile int *)&halt_)
-        return;
+void lwt_trace_i (uint64_t format, size_t value1, size_t value2) {
+    while (halt_) {}
     LOCALIZE_THREAD_LOCAL(tid_, int);
     lwt_buffer_t *tb = lwt_buf_[tid_];
     if (tb != NULL) {