MCPcopy Create free account
hub / github.com/Moddable-OpenSource/moddable / run_async

Function run_async

modules/data/mp3/libmad/decoder.c:466–526  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

464
465# if defined(USE_ASYNC)
466static
467int run_async(struct mad_decoder *decoder)
468{
469 pid_t pid;
470 int ptoc[2], ctop[2], flags;
471
472 if (pipe(ptoc) == -1)
473 return -1;
474
475 if (pipe(ctop) == -1) {
476 close(ptoc[0]);
477 close(ptoc[1]);
478 return -1;
479 }
480
481 flags = fcntl(ptoc[0], F_GETFL);
482 if (flags == -1 ||
483 fcntl(ptoc[0], F_SETFL, flags | O_NONBLOCK) == -1) {
484 close(ctop[0]);
485 close(ctop[1]);
486 close(ptoc[0]);
487 close(ptoc[1]);
488 return -1;
489 }
490
491 pid = fork();
492 if (pid == -1) {
493 close(ctop[0]);
494 close(ctop[1]);
495 close(ptoc[0]);
496 close(ptoc[1]);
497 return -1;
498 }
499
500 decoder->async.pid = pid;
501
502 if (pid) {
503 /* parent */
504
505 close(ptoc[0]);
506 close(ctop[1]);
507
508 decoder->async.in = ctop[0];
509 decoder->async.out = ptoc[1];
510
511 return 0;
512 }
513
514 /* child */
515
516 close(ptoc[1]);
517 close(ctop[0]);
518
519 decoder->async.in = ptoc[0];
520 decoder->async.out = ctop[1];
521
522 _exit(run_sync(decoder));
523

Callers

nothing calls this directly

Calls 2

run_syncFunction · 0.85
closeFunction · 0.50

Tested by

no test coverage detected