This commit is contained in:
nakst 2022-02-02 22:23:07 +00:00
parent 9c321c3069
commit f8c4f764df
1 changed files with 7 additions and 3 deletions

View File

@ -281,6 +281,7 @@ typedef struct CoroutineState {
struct CoroutineState **previousCoroutineLink; struct CoroutineState **previousCoroutineLink;
struct CoroutineState *nextUnblockedCoroutine; struct CoroutineState *nextUnblockedCoroutine;
struct CoroutineState **previousUnblockedCoroutineLink; struct CoroutineState **previousUnblockedCoroutineLink;
struct CoroutineState *nextExternalCoroutine;
struct CoroutineState **waiters; struct CoroutineState **waiters;
size_t waiterCount; size_t waiterCount;
size_t waitersAllocated; size_t waitersAllocated;
@ -546,6 +547,7 @@ uint8_t TokenLookupPrecedence(uint8_t t) {
if (t == T_AWAIT) return 90; if (t == T_AWAIT) return 90;
if (t == T_LEFT_ROUND) return 100; if (t == T_LEFT_ROUND) return 100;
Assert(false); Assert(false);
return 0;
} }
Token TokenNext(Tokenizer *tokenizer) { Token TokenNext(Tokenizer *tokenizer) {
@ -4596,7 +4598,7 @@ void ExternalCoroutineDone(CoroutineState *coroutine) {
#ifdef __linux__ #ifdef __linux__
sem_post(&externalCoroutineSemaphore); sem_post(&externalCoroutineSemaphore);
pthread_mutex_lock(&externalCoroutineMutex); pthread_mutex_lock(&externalCoroutineMutex);
coroutine->nextUnblockedCoroutine = externalCoroutineUnblockedList; coroutine->nextExternalCoroutine = externalCoroutineUnblockedList;
externalCoroutineUnblockedList = coroutine; externalCoroutineUnblockedList = coroutine;
pthread_mutex_unlock(&externalCoroutineMutex); pthread_mutex_unlock(&externalCoroutineMutex);
#else #else
@ -4636,6 +4638,7 @@ int ExternalSystemShellExecute(ExecutionContext *context, Value *returnValue) {
#ifdef __linux__ #ifdef __linux__
pthread_t thread; pthread_t thread;
pthread_create(&thread, NULL, SystemShellExecuteThread, context->c); pthread_create(&thread, NULL, SystemShellExecuteThread, context->c);
pthread_detach(thread);
return 4; return 4;
#else #else
SystemShellExecuteThread(context->c); SystemShellExecuteThread(context->c);
@ -4713,6 +4716,7 @@ int ExternalSystemShellExecuteWithWorkingDirectory(ExecutionContext *context, Va
context->c->externalCoroutineData.i = pid; context->c->externalCoroutineData.i = pid;
pthread_t thread; pthread_t thread;
pthread_create(&thread, NULL, SystemShellExecuteWithWorkingDirectoryThread, context->c); pthread_create(&thread, NULL, SystemShellExecuteWithWorkingDirectoryThread, context->c);
pthread_detach(thread);
return 4; return 4;
} }
#else #else
@ -5413,8 +5417,8 @@ CoroutineState *ExternalCoroutineWaitAny(ExecutionContext *context) {
pthread_mutex_lock(&externalCoroutineMutex); pthread_mutex_lock(&externalCoroutineMutex);
CoroutineState *unblocked = externalCoroutineUnblockedList; CoroutineState *unblocked = externalCoroutineUnblockedList;
Assert(unblocked); Assert(unblocked);
externalCoroutineUnblockedList = unblocked->nextUnblockedCoroutine; externalCoroutineUnblockedList = unblocked->nextExternalCoroutine;
unblocked->nextUnblockedCoroutine = NULL; unblocked->nextExternalCoroutine = NULL;
pthread_mutex_unlock(&externalCoroutineMutex); pthread_mutex_unlock(&externalCoroutineMutex);
return unblocked; return unblocked;
} }