Commit Graph

57 Commits

Author SHA1 Message Date
Calvin Rose b3a6e25ce0 Add weak references in the form of weak tables.
Any references exclusively held by a weak table may be collected
without the programmer needing to free references manually. A table
can be setup to have weak keys, weak values, or both.
2023-09-27 23:36:09 -05:00
Calvin Rose d12464fc0e Make poll work by going back to array of listeners for gc keeping. 2023-09-26 23:02:06 -05:00
Calvin Rose 1ee98e1e66 Get IOCP reworked event loop passing tests. 2023-09-25 15:19:39 -07:00
Calvin Rose 81f35f5dd1 Redo state management for Janet listeners.
Make more use of the built in GC code for abstracts to
be sure things are more correct. Issue before was streams could
be freed before IOCP events arrived.
2023-09-25 00:43:36 -07:00
Calvin Rose e6e9bd8147 Redo async connect code to be moved out of ev.c.
Async connect is different than write.
2023-09-24 10:08:40 -07:00
Calvin Rose ffd79c6097 Allow multiple simultaneous interrupts cleanly for #1262
Instead of setting a flag, each interrupt increments an atomic
counter. When the interrupt is finally handled, either by scheduling
code to run on the event loop or executing some out of band code, the
user must now decrement the interrupt counter with
janet_interpreter_interrupt_handled. While this counter is non-zero, the
event loop will not enter the interpreter. This changes the API a bit but
makes it possible and easy to handle signals without race conditions
or scheduler hacks, as the runtime can ensure that high priority code is
run before re-entering possibly blocking interpreter code again.

Also included is a new function janet_schedule_soon, which prepends to
the task queue instead of appending, allowing interrupt handler to skip
ahead of all other scheduled fibers.

Lastly, also update meson default options to include the
interpreter_interrupt code and raise a runtime error if os/sigaction
is used with interpreter interrupt but that build option is not enabled.
2023-08-24 07:38:53 -05:00
Calvin Rose ca4c1e4259 Try to use atomics inside signal handler for ref count. 2023-08-20 08:49:49 -05:00
Calvin Rose f45571033c Add os/sigaction for signal handling.
Also improve interrupts to work better with busy loops
and signals.
2023-08-19 13:26:29 -05:00
Calvin Rose 3858b2e177 Add `ev/all-tasks` to get running and pending root fibers. 2023-04-01 18:57:13 -05:00
Calvin Rose b032d94877 Add sandboxing API.
The sandboxing API is meant to make janet a bit more attractive
for certain application embedding use cases. The sandboxing API
puts limits on what system resources the interpreter can access.
2023-02-06 09:05:57 -06:00
sogaiu 310bcec260 Misc comment tweaks 2023-01-25 18:45:19 +09:00
Calvin Rose a0f40042cb Update copyright year. 2023-01-07 15:03:35 -06:00
Calvin Rose 07fe9bcdf6 Update state header to include pthread 2022-11-11 11:48:50 -06:00
Calvin Rose a3a42eebea Create pthread threads with detached attribute.
Rather than calling pthread_detach on a default thread.
2022-11-11 11:01:59 -06:00
Calvin Rose 3715d7a184 Auto update copyright date. 2022-03-21 18:22:59 -05:00
Calvin Rose 6c58347916 Remove thread module.
Instead, use the more general and non-blocing `ev/` module.
2021-09-19 14:19:32 -05:00
llmII f2e4c1ae9a
Forgot a semicolon... 2021-09-03 16:31:20 -05:00
llmII a209a01284
Add kqueue support to Janet
Note that this is a work in progress and simply a first attempt at
getting some code into place before being able to test it. This code
follows of sorts both the poll and epoll sections of the codebase hoping
to achieve the exact same.
2021-09-03 14:33:47 -05:00
Calvin Rose ab740f92db Fix ev thread swallowing error in some case. 2021-08-27 11:46:42 -05:00
Calvin Rose cc066dd6a1 Add basic runtime support for threaded abstracts.
A threaded abstract is an abstract type that can be freely shared
between threads. While no synchronization is provided, refcounting
and transport between threads is. This will let implementers more easily
exploit OS-level parallelism in C library code. The caveat with these
types is that they need to be careful in how they interact with objects
on other heaps.
2021-08-19 21:16:20 -05:00
Calvin Rose eb0b37f729 Initial threaded abstract types. 2021-08-19 20:56:48 -05:00
Calvin Rose 037215f7c4 Initial working draft of threaded channels.
Introduces close semtantics to channels as well, but otherwise
threaded channels behave much like non-threaded channels. They have
different marshalling behavior though, and can only send values over by
packing and unpacking them. For now, this means only primitive values
although this will be expanded.

Also missing some implementation for closing threaded channels, and a
whole lot of testing. Achtung!, Caveat emptor, here be dragons and bugs.
2021-08-15 11:48:13 -05:00
Calvin Rose 7e5f226480 Put source mapping info in stack traces. 2021-07-29 21:29:08 -05:00
bakpakin 160dd830a0 Add janet_interpreter_interrupt for custom scheduling.
This would allow an embedder to suspend the current Janet fiber
via an external event like a signal, other thread, or really anything.
This is a useful primitive for custom schedulers that would call
janet_interpreter_interupt periodically (say, in an interval with SIG_ALRM),
do some work, and then use janet_continue on the janet_root_fiber, or
for embedding into other soft-realtime applications like a game. To say,
only allow about 5ms per frame of interpreter time.
2021-07-24 15:14:37 -05:00
Calvin Rose ab27b789e4 Fix minimal build. 2021-07-17 13:10:55 -05:00
Calvin Rose 3a1a59f1eb Address windows build issue. 2021-07-16 21:10:02 -05:00
Calvin Rose 1ef6db16ed Add janet_vm_save and janet_vm_load.
This lets a user multiplex multiple Janet VMs on a single
thread or process if they are willing to implement context switching
themselves.
2021-07-16 20:59:03 -05:00
Calvin Rose bbae43f259 Update copyright dates. 2021-05-31 13:46:02 -05:00
Calvin Rose a0abf307b4 Merge branch 'master' into ev 2020-07-03 12:14:48 -05:00
Calvin Rose 95c633914f Add auto-resizing of gc interval.
This should prevent over use of GC and O(n^2)
behavior.
2020-06-27 16:51:20 -05:00
Calvin Rose 328ee94412 Merge branch 'master' into ev 2020-06-22 22:25:44 -05:00
Calvin Rose de9951594e Allow setting dynamic bindings at C top level.
Before, these bindings we just ignored. However, it useful for
controlling janet_printf and janet_eprintf, for example. These can
be called from C code without being inside a call to janet_continue.
2020-06-22 08:56:04 -05:00
Calvin Rose b68b0a256e Start with ev module. 2020-05-28 10:39:40 -05:00
Calvin Rose d2ebf4b52d Merge branch 'net' 2020-04-26 12:27:37 -05:00
Calvin Rose a87015598c Make janet_equals and janet_compare non recursive
This makes these operatios use constant stack space rather
than linear stackspace given the size of the inputs. This is important
to prevent certain parser input from causing a stack overflow - in
general, we try to avoid unbounded recursion.
2020-04-24 16:18:31 -05:00
Calvin Rose 596111c988 Merge branch 'master' into net 2020-04-17 15:08:26 -05:00
Calvin Rose a3aaa6634d Use separate registry table for abstract types.
This avoids overloading the registry table, which is intended
for names of c functions.
2020-03-14 10:25:39 -05:00
Calvin Rose f4d7fd97f6 Working TCP echo server and client.
Required a few changes to APIs, namely janet_root_fiber()
to get topmost fiber that is active in the current scheduler.
This is distinct from janet_current_fiber(), which gets the bottom
most fiber in the fiber stack - it might have a parent, and so cannot
be reliably resumed.
This is the kind of situation that makes symmetric coroutines more
attractive.
2020-02-09 20:00:50 -06:00
Calvin Rose 333ae7c4f8 Make amalgamtion the default when building.
This way we can support fewer build configurations. Also, remove
all undefined behavior due to use of memcpy with NULL pointers. GCC
was exploiting this to remove NULL checks in some builds.
2020-01-28 23:38:52 -06:00
Calvin Rose a68ee7aac6 Update Copyright 2020. 2020-01-12 10:50:37 -06:00
Calvin Rose 6c7f376410 Try to remove potential overflow bugs.
Also make integer to size_t casts explicit rather than relying on
int32_t * sizeof(x) = size_t. This is kind of a personal preference for
this problem.
2020-01-02 22:08:17 -06:00
Calvin Rose fd4220f254 Keep single global pthread_cond_t per thread.
This will allow thread/select to be implemented.
Also add thread/close and close method to threads.
2019-12-04 21:44:53 -06:00
Calvin Rose 70c8b6838d Use make-image-dict and load-image-dict in thread/new
Rather than messing with janet_core_dictionary, we
instead cache the core enevironment, and pull out the
needed tables from there. This is more flexible, more correct, and
also exposes janet_resolve_core, which can be easily used from the C
API.
2019-12-02 04:15:22 -06:00
Calvin Rose 6a763aac95 Work on threads.
Add send and receive.
2019-12-01 20:28:12 -06:00
Calvin Rose c150f2f2c1 Add scratch memory API.
This should make it easier to write
code that does not leak memory on panics.
2019-06-01 23:31:39 -04:00
Calvin Rose 8a3f512746 Experimental changes to janet_call to make it faster.
Remove setjmp and fiber creationg from janet_call. This
adds the constraint to janet_call can only be called when there
is already a current fiber.
2019-02-01 11:56:25 -05:00
Calvin Rose 6f3bc3d577 Update copyright date, fix types, remove trailing whitespace. 2019-01-06 03:23:03 -05:00
Calvin Rose 9b579c9ce6 Merge code back from correctgc. 2018-09-23 17:53:55 -04:00
Calvin Rose d9752a9028 Garbage collection no longer blows stack. 2018-09-22 14:59:50 -04:00
Calvin Rose c8ef2a0d88 Rename to janet 2018-09-05 22:18:42 -04:00