package core.alloc
#load "./arena"
+#load "./atomic"
#load "./fixed"
#load "./heap"
#load "./ring"
// is not needed for the general purpose heap allocator,
// as that already has a thread-safe implementation.
+use core.alloc
use core.sync
AtomicAllocator :: struct {
Allocator.{ atomic, atomic_alloc };
#overload
-core.alloc.as_allocator :: make_allocator
+alloc.as_allocator :: make_allocator
#local
write_index := 0;
while n > 0 && !reader_empty(reader) {
+ if start != end {
+ to_write := math.min(n, end);
+ memory.copy(bytes.data + write_index, buffer.data + start, to_write);
+ n -= to_write;
+ write_index += to_write;
+ start += to_write;
+ }
+
+ if n == 0 do break;
+
if err := reader_read_next_chunk(reader);
err == .ReadPending || err == .ReadLater
{
return write_index, err;
}
-
- to_write := math.min(n, end);
- memory.copy(bytes.data + write_index, buffer.data, to_write);
- n -= to_write;
- write_index += to_write;
- start += to_write;
}
last_byte = cast(i32) bytes[write_index - 1];
array.init(&out, allocator=allocator);
while done := false; !done {
+ if start == end {
+ while reader_read_next_chunk(reader) == .ReadPending ---
+ }
+
count := start;
while count < end && buffer[count] != #char "\n" {
count += 1;
if would_block do return .ReadLater, bytes_read;
+ if bytes_read == 0 do return .EOF, bytes_read;
+
return .None, bytes_read;
},
}
last_index_of :: (s: str, c: u8) -> i32 {
- for range.{s.count, 0, -1} {
+ for range.{s.count-1, 0, -1} {
if s[it] == c do return it;
}
return -1;
fds = alloca(params->data[1].of.i32 * sizeof(struct pollfd));
- for (i=0; i<params->data[1].of.i32; i++) {
+ for (i=0; i < params->data[1].of.i32; i++) {
fds[i].fd = *(i32 *) ONYX_PTR(params->data[0].of.i32 + 4 * i);
fds[i].events = POLLIN;
fds[i].revents = 0;