mirror of
https://github.com/janet-lang/janet
synced 2025-06-27 07:32:51 +00:00
Begin implementing async subproccesses for windows.
This commit is contained in:
parent
1c7ed8ca48
commit
47bb7fd21b
@ -990,7 +990,7 @@ void janet_loop1_impl(int has_timeout, JanetTimestamp to) {
|
|||||||
if (!has_timeout) {
|
if (!has_timeout) {
|
||||||
/* queue emptied */
|
/* queue emptied */
|
||||||
}
|
}
|
||||||
} else if (NULL == completionKey) {
|
} else if (0 == completionKey) {
|
||||||
/* Custom event */
|
/* Custom event */
|
||||||
JanetSelfPipeEvent *response = (JanetSelfPipeEvent *)(overlapped);
|
JanetSelfPipeEvent *response = (JanetSelfPipeEvent *)(overlapped);
|
||||||
response->cb(response->msg);
|
response->cb(response->msg);
|
||||||
@ -1308,7 +1308,10 @@ static DWORD WINAPI janet_thread_body(LPVOID ptr) {
|
|||||||
/* Reuse memory from thread init for returning data */
|
/* Reuse memory from thread init for returning data */
|
||||||
init->msg = subr(msg);
|
init->msg = subr(msg);
|
||||||
init->cb = cb;
|
init->cb = cb;
|
||||||
janet_assert(PostQueuedCompletionStatus(iocp, sizeof(JanetSelfPipeEvent), NULL, init),
|
janet_assert(PostQueuedCompletionStatus(iocp,
|
||||||
|
sizeof(JanetSelfPipeEvent),
|
||||||
|
0,
|
||||||
|
(LPOVERLAPPED) init),
|
||||||
"failed to post completion event");
|
"failed to post completion event");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -344,6 +344,17 @@ typedef struct {
|
|||||||
|
|
||||||
#ifdef JANET_EV
|
#ifdef JANET_EV
|
||||||
|
|
||||||
|
#ifdef JANET_WINDOWS
|
||||||
|
|
||||||
|
static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
||||||
|
JanetProc *proc = (JanetProc *) args.argp;
|
||||||
|
WaitForSingleObject(proc->pHandle, INFINITE);
|
||||||
|
GetExitCodeProcess(proc->pHandle, &args.argi);
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else /* windows check */
|
||||||
|
|
||||||
/* Function that is called in separate thread to wait on a pid */
|
/* Function that is called in separate thread to wait on a pid */
|
||||||
static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
||||||
JanetProc *proc = (JanetProc *) args.argp;
|
JanetProc *proc = (JanetProc *) args.argp;
|
||||||
@ -352,14 +363,6 @@ static JanetEVGenericMessage janet_proc_wait_subr(JanetEVGenericMessage args) {
|
|||||||
do {
|
do {
|
||||||
result = waitpid(proc->pid, &status, 0);
|
result = waitpid(proc->pid, &status, 0);
|
||||||
} while (result == -1 && errno == EINTR);
|
} while (result == -1 && errno == EINTR);
|
||||||
args.argi = status;
|
|
||||||
return args;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Callback that is called in main thread when subroutine completes. */
|
|
||||||
static void janet_proc_wait_cb(JanetEVGenericMessage args) {
|
|
||||||
int status = args.argi;
|
|
||||||
JanetProc *proc = (JanetProc *) args.argp;
|
|
||||||
/* Use POSIX shell semantics for interpreting signals */
|
/* Use POSIX shell semantics for interpreting signals */
|
||||||
if (WIFEXITED(status)) {
|
if (WIFEXITED(status)) {
|
||||||
status = WEXITSTATUS(status);
|
status = WEXITSTATUS(status);
|
||||||
@ -368,6 +371,16 @@ static void janet_proc_wait_cb(JanetEVGenericMessage args) {
|
|||||||
} else {
|
} else {
|
||||||
status = WTERMSIG(status) + 128;
|
status = WTERMSIG(status) + 128;
|
||||||
}
|
}
|
||||||
|
args.argi = status;
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* End windows check */
|
||||||
|
|
||||||
|
/* Callback that is called in main thread when subroutine completes. */
|
||||||
|
static void janet_proc_wait_cb(JanetEVGenericMessage args) {
|
||||||
|
int status = args.argi;
|
||||||
|
JanetProc *proc = (JanetProc *) args.argp;
|
||||||
if (NULL != proc) {
|
if (NULL != proc) {
|
||||||
proc->return_code = (int32_t) status;
|
proc->return_code = (int32_t) status;
|
||||||
proc->flags |= JANET_PROC_WAITED;
|
proc->flags |= JANET_PROC_WAITED;
|
||||||
@ -383,7 +396,7 @@ static void janet_proc_wait_cb(JanetEVGenericMessage args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif /* End ev check */
|
||||||
|
|
||||||
static int janet_proc_gc(void *p, size_t s) {
|
static int janet_proc_gc(void *p, size_t s) {
|
||||||
(void) s;
|
(void) s;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user