mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-15 12:23:15 +00:00
144 lines
3.6 KiB
Diff
144 lines
3.6 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Ali Mohammad Pur <ali.mpfard@gmail.com>
|
|
Date: Fri, 11 Feb 2022 16:32:42 +0330
|
|
Subject: [PATCH] Make fiber a noop
|
|
|
|
Serenity doesn't have ucontext.
|
|
---
|
|
src/fiber.c | 22 ++++++++++++++++++++--
|
|
1 file changed, 20 insertions(+), 2 deletions(-)
|
|
|
|
diff --git a/src/fiber.c b/src/fiber.c
|
|
index e8a99f15443dbf21c3d2944df2eb99fb18723f3a..23afae64c68105146badce7e65d5802082ed5de8 100644
|
|
--- a/src/fiber.c
|
|
+++ b/src/fiber.c
|
|
@@ -49,6 +49,7 @@ extern int waitForAllFibers();
|
|
#endif
|
|
/* <HEADER */
|
|
|
|
+#ifndef __serenity__
|
|
#include <malloc.h>
|
|
#include <ucontext.h>
|
|
|
|
@@ -76,21 +77,25 @@ static int numFibers = 0;
|
|
|
|
// The "main" execution context
|
|
static ucontext_t mainContext;
|
|
+#endif
|
|
|
|
// Sets all the fibers to be initially inactive
|
|
void initFibers()
|
|
{
|
|
+#ifndef __serenity__
|
|
int i;
|
|
for (i = 0; i < MAX_FIBERS; ++i) {
|
|
fiberList[i].active = 0;
|
|
}
|
|
|
|
return;
|
|
+#endif
|
|
}
|
|
|
|
// Switches from a fiber to main or from main to a fiber
|
|
void fiberYield()
|
|
{
|
|
+#ifndef __serenity__
|
|
// If we are in a fiber, switch to the main process
|
|
if (inFiber) {
|
|
// Switch to the main context
|
|
@@ -129,6 +134,7 @@ void fiberYield()
|
|
fiberList[numFibers].active = 0;
|
|
}
|
|
}
|
|
+#endif
|
|
return;
|
|
}
|
|
|
|
@@ -137,16 +143,21 @@ void fiberYield()
|
|
// context of execution.
|
|
static void fiberStart(ctr_object* block)
|
|
{
|
|
+#ifndef __serenity__
|
|
fiberList[currentFiber].active = 1;
|
|
ctr_block_run_here(block, NULL, block);
|
|
fiberList[currentFiber].active = 0;
|
|
|
|
// Yield control, but because active == 0, this will free the fiber
|
|
fiberYield();
|
|
+#endif
|
|
}
|
|
|
|
int spawnFiber(ctr_object* block)
|
|
{
|
|
+#ifdef __serenity__
|
|
+ return 0;
|
|
+#else
|
|
if (numFibers == MAX_FIBERS)
|
|
return LF_MAXFIBERS;
|
|
|
|
@@ -171,10 +182,12 @@ int spawnFiber(ctr_object* block)
|
|
++numFibers;
|
|
|
|
return LF_NOERROR;
|
|
+#endif
|
|
}
|
|
|
|
int waitForAllFibers()
|
|
{
|
|
+#ifndef __serenity__
|
|
int fibersRemaining = 0;
|
|
|
|
// If we are in a fiber, wait for all the *other* fibers to quit
|
|
@@ -187,12 +200,14 @@ int waitForAllFibers()
|
|
// Execute the fibers until they quit
|
|
while (numFibers > fibersRemaining)
|
|
fiberYield();
|
|
+#endif
|
|
|
|
return LF_NOERROR;
|
|
}
|
|
|
|
int waitForFiber(int id)
|
|
{
|
|
+#ifndef __serenity__
|
|
int fibersRemaining = id;
|
|
|
|
// If we are in a fiber, wait for all the *other* fibers to quit
|
|
@@ -205,15 +220,18 @@ int waitForFiber(int id)
|
|
// Execute the fibers until they quit
|
|
while (numFibers > fibersRemaining)
|
|
fiberYield();
|
|
+#endif
|
|
|
|
return LF_NOERROR;
|
|
}
|
|
|
|
int yieldNTimes(int n)
|
|
{
|
|
+#ifndef __serenity__
|
|
while (--n != 0) {
|
|
fiberYield();
|
|
}
|
|
+#endif
|
|
return LF_NOERROR;
|
|
}
|
|
|
|
@@ -258,7 +276,7 @@ ctr_object* ctr_fiber_spawn(ctr_object* myself, ctr_argument* argumentList)
|
|
int fiber = spawnFiber(argumentList->object);
|
|
ctr_internal_object_add_property(
|
|
fiberObj, ctr_build_string_from_cstring("fiberId"),
|
|
- ctr_build_number_from_float(numFibers), CTR_CATEGORY_PRIVATE_PROPERTY);
|
|
+ ctr_build_number_from_float(0), CTR_CATEGORY_PRIVATE_PROPERTY);
|
|
return fiberObj;
|
|
}
|
|
|
|
@@ -381,7 +399,7 @@ void ctr_fiber_begin_init()
|
|
CtrStdFiber, ctr_build_string_from_cstring("unpack:"), &ctr_fiber_assign);
|
|
ctr_internal_object_add_property(
|
|
CtrStdFiber, ctr_build_string_from_cstring("fiberId"),
|
|
- ctr_build_number_from_float(numFibers), CTR_CATEGORY_PRIVATE_PROPERTY);
|
|
+ ctr_build_number_from_float(0), CTR_CATEGORY_PRIVATE_PROPERTY);
|
|
CtrStdFiber->info.sticky = 1;
|
|
|
|
ctr_internal_object_add_property(
|