value : V;
}
+}
+
+#inject Map {
//
// These need to have aliases because some of them like
// 'delete', collide with the global 'delete', which
update :: update
clear :: clear
empty :: empty
+ literal :: literal
+ as_iter :: as_iter
}
make :: ($Key: type_expr, $Value: type_expr, default := Value.{}) -> Map(Key, Value) {
}
}
+#local
+MapLiteralValue :: struct (K: type_expr, V: type_expr) {
+ key: K;
+ value: V;
+}
+
+literal :: ($Key: type_expr, $Value: type_expr, values: [] MapLiteralValue(Key, Value)) => {
+ m := core.map.make(Key, Value);
+ for ^ values {
+ m->put(it.key, it.value);
+ }
+
+ return m;
+}
+
+
+#overload core.iter.as_iterator as_iter
+
+as_iter :: (m: ^Map) =>
+ core.iter.generator(
+ ^.{ m = m, i = 0 },
+
+ (ctx) => {
+ if ctx.i >= ctx.m.entries.count {
+ return (typeof ctx.m.entries.data).{}, false;
+ }
+
+ defer ctx.i += 1;
+ return ^ctx.m.entries.data[ctx.i], true;
+ });
+
//
// Private symbols
//
pulse_time_ms := 500;
emit_data_events := true;
+}
+#inject TCP_Server {
listen :: tcp_server_listen
stop :: tcp_server_stop
pulse :: tcp_server_pulse
}
}
- array.sort(clients, (a, b) => {
- a_val := 1 if a == null else 0;
- b_val := 1 if b == null else 0;
-
- if a_val != b_val do return b_val - a_val;
-
- return cast(i32) a.state - cast(i32) b.state;
- });
-
client_count = array.count_where(clients, #(it != null));
return server.alive;
// ATOMIC ARENA ALLOCATOR
+// Currently, this is only available on Linux, as it is using pthreads.
+#ifdef _BH_LINUX
+
typedef struct bh_atomic_arena {
bh_allocator backing;
ptr first_arena, current_arena;
BH_DEF bh_allocator bh_atomic_arena_allocator(bh_atomic_arena* alloc);
BH_DEF BH_ALLOCATOR_PROC(bh_atomic_arena_allocator_proc);
+#endif
+
// ATOMIC ARENA ALLOCATOR IMPLEMENTATION
+#ifdef _BH_LINUX
BH_DEF void bh_atomic_arena_init(bh_atomic_arena* alloc, bh_allocator backing, isize arena_size) {
arena_size = bh_max(arena_size, size_of(ptr));
ptr data = bh_alloc(backing, arena_size);
pthread_mutex_unlock(&alloc_arena->mutex);
return retval;
}
+#endif