Commit graph

45 commits

Author SHA1 Message Date
Sönke Ludwig df03416eea Reduce visibility of minor debug log message. 2021-01-12 17:37:01 +01:00
Sönke Ludwig ba6c058148 Add some more VibeTaskLog logging. 2020-12-10 09:22:38 +01:00
Sönke Ludwig 3d1be3b3cb Improve debug trace logging. 2020-11-25 23:24:27 +01:00
Sönke Ludwig 3182160a9a Avoid bogus "A task cannot interrupt itself" assertion failure.
Calling Task.interrupt() on a task that is already finished, but ran on the same fiber would trigger an assertion failure instead of returning silently.
2020-11-19 16:06:49 +01:00
Geod24 9a685523f9 Add support for DMD 2.094 -preview=in switch
This will allow users to use -preview=in as soon as it's released.
2020-08-31 06:59:50 +02:00
Geod24 bd8c2c6e90 Use logException consistently and use logDiagnostic
Many places around were re-inventing logException with varying level of success.
In addition, the full error is now printed as a diagnostic instead of debug.
This is more in line with the description of `LogLevel.diagnostic`
("Extended user information (e.g. for more detailed error information)"),
as opposed to the one of `LogLevel.debug_`
("Developer information useful for algorithm debugging").
2020-08-24 05:17:59 +02:00
Sönke Ludwig 1eebe7a9ce Add TaskSwitchPriority to control the priority to use when transferring execution. 2020-03-15 10:54:35 +01:00
Sönke Ludwig d07c2f02e6 Fix TaskQueue.insertBackPred. 2020-03-15 10:54:32 +01:00
Sönke Ludwig 280023dfc2 Avoid potential overflow for dynamic task priority. 2020-03-15 08:59:17 +01:00
Sönke Ludwig 6a2dfa468b Implement priority based task scheduling.
1. Removes the marker task used by schedule() and instead limits the number of task resumptions to the initial length of the task queue
2. Assigns a static and a dynamic priority to each task. The dynamic priority starts with the same value as the static priority and gets incremented by the static priority each time the task gets overtaken by a higher priority task, eventually leading to the task becoming the highest priority (unless the static priority is zero). Tasks with a higher dynamic priority generally take precedence, unless the concurrency exceeds 10 scheduled tasks, in which case the front of the queue is scheduled in normal FIFO order.
2020-03-14 20:37:33 +01:00
Sönke Ludwig 8e24c4a204 Correct copyright holder.
rejectedsoftware e.K. doesn't exist anymore since mid-2019.
2020-01-27 19:20:52 +01:00
Sönke Ludwig 5640516ba8 Remove SpinLock and use core.sync.mutex.Mutex instead.
The places that used it showed too much contention in load tests, so that the spin lock was more expensive that the regular OS mutex/futex.
2019-09-19 11:25:14 +02:00
Sönke Ludwig 8c63f79ea7 Avoid yielding in the task finalization phase. Fixes #161.
Makes sure that the task finalization finishes (including notifying possibly multiple joiners) before the fiber yields, because it won't be resumed by the scheduler before the next task gets assigned to the fiber.
2019-06-16 22:44:11 +02:00
Geod24 40f82b22e5 Remove useless imports to std.variant 2019-05-28 14:24:42 +09:00
Sönke Ludwig f734b4a142 Improve thread-correctness of Task/TaskFiber.
- Task.join and Task.interrupt are now thread-safe
- TaskFiber.task returns Task.init if no task is running (avoids bogus resumes of the TaskFiber by the scheduler)

To enable thread-safe join/interrupt, the task counter is now stored together with the necessary flags within a single shared ulong that is manipulated atomically.
2019-04-13 20:53:01 +02:00
Sönke Ludwig b5ccb784a1 Allow Task.interrupt to be called within a yieldLock. 2019-01-22 18:06:55 +01:00
Sönke Ludwig 9b2aa13ef4 Fix possible infinite loop in TaskScheduler.process.
Fixes a discrepancy in TaskFiberQueue between empty and length, which causes process() to never return, thus processing events without timeout indefinitely.
2018-08-26 13:03:14 +02:00
Sönke Ludwig fd92a7f555 Fix Task.running and Task.yield directly after runTask/yieldLock.
The status of the task was erroneously reported as not running until the task was actually executed for the first time (which only happens after the yield lock has been lifted).
2018-04-08 01:30:43 +02:00
Sönke Ludwig 2653c8c5e0 Always remove task from queue when switching to it. Fixes #58.
Previously the task was only removed if switchTo was called from another task. Now it also gets removed when switchTo (e.g. due to a runTask() call) gets called form outside of a task.
2018-02-23 01:25:13 +01:00
Sönke Ludwig e4eaaddbba Make high-frequency log messages in the task scheduler optional.
Requires -debug=VibeTaskLog to enable them now.
2018-02-14 13:11:51 +01:00
Sönke Ludwig 874e174d38 Add const overload for Task.tid. 2017-10-24 09:44:54 +02:00
Sönke Ludwig 19db7732e6 Add nothrow annotations. 2017-07-20 13:36:27 +02:00
Sönke Ludwig bfc6b89ca4
Use abort() in case of uncaught Error exceptions.
Fixes "dwarfeh(224) fatal error" that are suspected to be related to occasional infinite loops.
2017-07-19 00:11:12 +02:00
Sönke Ludwig 4f69b1eaf3 Add setTaskCreationCallback() for better remote debugger integration. 2017-07-16 22:07:59 +02:00
Sönke Ludwig 719c62d6c9
Fix TLS initialization condition. 2017-07-16 00:08:07 +02:00
Sönke Ludwig 254d91dcdf
Improve error message. 2017-07-15 10:12:52 +02:00
Sönke Ludwig bc689489a8
Add yieldLock(), which enables enforcing no task switches within a scope.
runTask() was altered to delay the task switch in case it gets called within an active yieldLock(), so that running tasks is still possible.
2017-06-11 11:40:25 +02:00
Sönke Ludwig 99a5b882d8
Limit the number of recycled fibers.
This allows the process to free up memory after heavy load spikes, while not impacting performance negatively.
2017-05-30 11:00:37 +02:00
Dentcho Bankov aef2936abd Fix for #11. Cross port of fix for #1742 from vibe.d 2017-04-15 00:04:08 +03:00
Sönke Ludwig 897c43051f
Fix nothrow inference for runTask. 2017-02-23 15:49:59 +01:00
Sönke Ludwig 9ac908c599 Use a ring buffer for worker tasks and make TaskFuncInfo creation slightly more efficient. 2017-02-22 19:52:22 +01:00
Sönke Ludwig 40713db075 Move worker task logic into a new TaskPool class. 2017-02-22 18:35:51 +01:00
Sönke Ludwig db29e4730f Let uncaught errors in fibers terminate the process. 2017-02-16 11:56:04 +01:00
Sönke Ludwig b8663f9fbc
Conditionally compile TaskFiber.state.
See https://issues.dlang.org/show_bug.cgi?id=17131
2017-02-01 11:05:53 +01:00
Sönke Ludwig d0a55ef374
Add an uninterruptible variant of Task.join. 2017-01-29 20:20:08 +01:00
Sönke Ludwig 7803fdaa81 Make Task.interrupt nothrow + add diagnostic assertion. 2017-01-13 22:08:12 +01:00
Sönke Ludwig 8c0660781d Thread safety improvements in the task system.
Removes some invalid safety annotations and adds a workaround for a starvation issue in Task.join() across threads boundaries. This is still not thread-safe, but now has a safety-net and is documented, so that it doesn't get lost.
2016-12-19 20:24:08 +01:00
Sönke Ludwig bf2edc7fb2 Fix TaskScheduler.waitAndProcess to not block if any tasks were resumed.
In situations where no events were involved in an multi-task scenario, the old behavior could lead to the process to starve or hang until an event arrived.
2016-12-10 14:13:44 +01:00
Sönke Ludwig 0c3c31b969 Annotate more of Task/TaskLocal as safe. 2016-11-04 21:33:01 +01:00
Sönke Ludwig c08f101549 Update for eventcore 0.5.0 and the latest DMD beta. 2016-10-24 08:22:49 +02:00
Sönke Ludwig e294d24a4b Update for latest eventcore version. 2016-10-05 14:40:29 +02:00
Sönke Ludwig 1005f5c674 Fix all ManualEvent related tests. 2016-06-17 22:33:04 +02:00
Sönke Ludwig f9579a5dd2 Various task scheduling fixes.
- the initial task yield() now is done in an uninterruptible way
- switchToTask now handles switching to an already scheduled task gracefully
- TaskScheduler.hibernate() now properly blocks when called form outside of a task
- added yieldUninterruptible()
2016-06-16 10:58:12 +02:00
Sönke Ludwig 3b0e4e0452 Big refactoring step.
- Moves a lot of stuff from vibe.core.core to vibe.core.task
- Introduces TaskScheduler to unify the scheduling process
- Refines how tasks are scheduled and processed (can push to the front of the task queue and uses a marker task to keep track of the spot up to which to process)
- Start to add proper support for task interrupts and timeouts by properly cancelling in-flight async operations
- Work on ManualEvent - still not functional for the shared case
- Implement proper IP address parsing in NetworkAddress
2016-06-14 08:01:03 +02:00
Sönke Ludwig 7e2d1dd038 Initial commit.
The library is able to support simple TCP servers in the current state. The API is still mostly compatible with mainline vibe.d, but the driver systen has been replaced by the eventcore library and sockets/files/timers/... are now structs with automatic reference counting instead of GC collected classes. The stream interfaces have been removed for now.
2016-03-01 20:30:42 +01:00