VirtualBox

Changeset 3156 in kBuild for trunk/src


Ignore:
Timestamp:
Mar 18, 2018 8:10:03 PM (7 years ago)
Author:
bird
Message:

kmk/win: Reworking child process handling. This effort will hopefully handle processor groups better and allow executing internal function off the main thread.

Location:
trunk/src/kmk
Files:
2 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.kmk

    r3154 r3156  
    5454TEMPLATE_BIN-KMK_CFLAGS.win.amd64 = $(TEMPLATE_BIN-THREADED_CFLAGS.win.amd64) -wd4244 -wd4267
    5555TEMPLATE_BIN-KMK_CLEAN.win = $(TEMPLATE_BIN-KMK_DEPS.win)
    56 TEMPLATE_BIN-KMK_DEFS.debug = $(TEMPLATE_BIN-KMK_DEPS.debug) MAKE_MAINTAINER_MODE
     56TEMPLATE_BIN-KMK_DEFS.debug = $(TEMPLATE_BIN_DEFS.debug) MAKE_MAINTAINER_MODE
    5757TEMPLATE_BIN-KMK_INCS = $(kmk_0_OUTDIR) . $(TEMPLATE_BIN-THREADED_INCS)
    5858ifneq ($(KBUILD_TARGET),os2)
     
    6969ifdef CONFIG_WITH_ALLOCCACHE_DEBUG
    7070 TEMPLATE_BIN-KMK_DEFS += CONFIG_WITH_ALLOCCACHE_DEBUG
     71endif
     72ifdef CONFIG_NEW_WIN_CHILDREN
     73 TEMPLATE_BIN-KMK_DEFS.win = $(TEMPLATE_BIN_DEFS.win) CONFIG_NEW_WIN_CHILDREN
    7174endif
    7275# GCC sanitizers.
     
    275278endif
    276279
     280ifndef CONFIG_NEW_WIN_CHILDREN
    277281kmk_SOURCES.win = \
    278282        w32/subproc/sub_proc.c
     283else
     284kmk_SOURCES.win = \
     285        w32/winchildren.c
     286endif
    279287
    280288kmk_DEFS.freebsd.x86 = CONFIG_WITHOUT_THREADS
     
    512520endif
    513521
     522ifndef CONFIG_NEW_WIN_CHILDREN
    514523kmk_gmake_SOURCES.win = \
    515524        w32/subproc/sub_proc.c
     525else
     526kmk_gmake_SOURCES.win = \
     527        w32/winchildren.c
     528endif
    516529
    517530
  • trunk/src/kmk/commands.c

    r3140 r3156  
    2424#include <windows.h>
    2525#include "w32err.h"
     26# ifdef CONFIG_NEW_WIN_CHILDREN
     27#  include "w32/winchildren.h"
     28# endif
    2629#endif
    2730#ifdef CONFIG_WITH_LAZY_DEPS_VARS
     
    765768      for (c = children; c != 0; c = c->next)
    766769        if (!c->remote)
     770# if defined (CONFIG_NEW_WIN_CHILDREN) && defined (WINDOWS32)
     771          MkWinChildKill (c->pid, SIGTERM, c);
     772# else
    767773          (void) kill (c->pid, SIGTERM);
     774# endif
    768775    }
    769776
  • trunk/src/kmk/function.c

    r3145 r3156  
    2929#ifdef WINDOWS32 /* bird */
    3030# include "pathstuff.h"
     31# ifdef CONFIG_NEW_WIN_CHILDREN
     32#  include "w32/winchildren.h"
     33# endif
    3134#endif
    3235
     
    22952298/*untested*/
    22962299
     2300# ifndef CONFIG_NEW_WIN_CHILDREN
    22972301#include <windows.h>
    22982302#include <io.h>
    22992303#include "sub_proc.h"
    2300 
    23012304
    23022305int
     
    24252428    }
    24262429}
     2430# endif /* !CONFIG_NEW_WIN_CHILDREN */
    24272431#endif
    24282432
     
    25782582
    25792583#elif defined(WINDOWS32)
     2584# ifdef CONFIG_NEW_WIN_CHILDREN
     2585  pipedes[1] = -1;
     2586  MkWinChildCreateWithStdOutPipe (command_argv, envp, errfd, &pid, &pipedes[0]);
     2587# else
    25802588  windows32_openpipe (pipedes, errfd, &pid, command_argv, envp);
     2589# endif
    25812590  /* Restore the value of just_print_flag.  */
    25822591  just_print_flag = j_p_f;
  • trunk/src/kmk/job.c

    r3141 r3156  
    117117# include <io.h>
    118118# include <process.h>
    119 # include "sub_proc.h"
     119# ifdef CONFIG_NEW_WIN_CHILDREN
     120#  include "w32/winchildren.h"
     121# else
     122#  include "sub_proc.h"
     123# endif
    120124# include "w32err.h"
    121125# include "pathstuff.h"
     
    262266
    263267#ifdef WINDOWS32
     268# ifndef CONFIG_NEW_WIN_CHILDREN /* (only used by commands.c) */
    264269/*
    265270 * The macro which references this function is defined in makeint.h.
     
    270275  return ((process_kill ((HANDLE)pid, sig) == TRUE) ? 0 : -1);
    271276}
     277# endif /* !CONFIG_NEW_WIN_CHILDREN */
    272278
    273279/* This function creates a temporary file name with an extension specified
     
    807813#endif /* _AMIGA */
    808814#ifdef WINDOWS32
     815# ifndef CONFIG_NEW_WIN_CHILDREN
    809816          {
    810817            HANDLE hPID;
     
    869876            pid = (pid_t) hPID;
    870877          }
     878# else  /* CONFIG_NEW_WIN_CHILDREN */
     879          assert (!any_remote);
     880          pid = 0;
     881          coredump = exit_sig = exit_code = 0;
     882          {
     883            int rc = MkWinChildWait(block, &pid, &exit_code, &exit_sig, &coredump, &c);
     884            if (rc != 0)
     885                  ON (fatal, NILF, _("MkWinChildWait: %u"), rc);
     886          }
     887          if (pid == 0)
     888            {
     889              /* No more children, stop. */
     890              reap_more = 0;
     891              break;
     892            }
     893
     894          /* If we have started jobs in this second, remove one.  */
     895          if (job_counter)
     896            --job_counter;
     897# endif /* CONFIG_NEW_WIN_CHILDREN */
    871898#endif /* WINDOWS32 */
    872899        }
     
    16561683#ifdef WINDOWS32
    16571684  {
     1685#  ifndef CONFIG_NEW_WIN_CHILDREN
    16581686      HANDLE hPID;
    16591687      char* arg0;
     
    16991727          goto error;
    17001728        }
     1729#  else   /* CONFIG_NEW_WIN_CHILDREN */
     1730    struct variable *shell_var = lookup_variable("SHELL", 5);
     1731    const char *shell_value = !shell_var ? NULL
     1732                            : !shell_var->recursive || strchr(shell_var->value, '$') == NULL
     1733                            ? shell_var->value : variable_expand (shell_var->value);
     1734    int rc = MkWinChildCreate(argv, child->environment, shell_value, child, &child->pid);
     1735    if (rc != 0)
     1736      {
     1737        int i;
     1738        unblock_sigs ();
     1739        fprintf (stderr, _("failed to launch process (rc=%d)\n"), rc);
     1740        for (i = 0; argv[i]; i++)
     1741          fprintf (stderr, "%s ", argv[i]);
     1742        fprintf (stderr, "\n", argv[i]);
     1743        goto error;
     1744      }
     1745#endif  /* CONFIG_NEW_WIN_CHILDREN */
    17011746  }
    17021747#endif /* WINDOWS32 */
     
    17711816#endif
    17721817#ifdef WINDOWS32
     1818# ifndef CONFIG_NEW_WIN_CHILDREN
    17731819          || (process_used_slots () >= MAXIMUM_WAIT_OBJECTS)
     1820# endif
    17741821#endif
    17751822          ))
     
    21932240  time_t now;
    21942241
    2195 #ifdef WINDOWS32
     2242#if defined(WINDOWS32) && !defined(CONFIG_NEW_WIN_CHILDREN)
    21962243  /* sub_proc.c cannot wait for more than MAXIMUM_WAIT_OBJECTS children */
    21972244  if (process_used_slots () >= MAXIMUM_WAIT_OBJECTS)
     
    24362483
    24372484
     2485#if !defined(WINDOWS32) || !defined(CONFIG_NEW_WIN_CHILDREN)
    24382486#ifndef _AMIGA
    24392487/* Replace the current process with one running the command in ARGV,
     
    24592507#else
    24602508#ifdef WINDOWS32
     2509# ifndef CONFIG_NEW_WIN_CHILDREN
    24612510  HANDLE hPID;
    24622511  HANDLE hWaitPID;
     
    25142563  /* return child's exit code as our exit code */
    25152564  exit (exit_code);
    2516 
     2565# else  /* CONFIG_NEW_WIN_CHILDREN */
     2566
     2567# endif /* CONFIG_NEW_WIN_CHILDREN */
    25172568#else  /* !WINDOWS32 */
    25182569
     
    26482699
    26492700#endif /* On Amiga */
     2701#endif /* !defined(WINDOWS32) || !defined(CONFIG_NEW_WIN_CHILDREN) */
    26502702
    26512703
     
    27772829
    27782830  const char *sh_chars;
    2779   const char **sh_cmds;
     2831  char const * const * sh_cmds;                                                /* kmk: +_sh +const*2 */
    27802832#elif defined(__riscos__)
    27812833  static const char *sh_chars = "";
     
    33303382                /* This is the start of a new recipe line.  Skip whitespace
    33313383                   and prefix characters but not newlines.  */
     3384#ifndef CONFIG_WITH_COMMANDS_FUNC
    33323385                while (ISBLANK (*f) || *f == '-' || *f == '@' || *f == '+')
     3386#else
     3387                char ch;
     3388                while (ISBLANK ((ch = *f)) || ch == '-' || ch == '@' || ch == '+' || ch == '%')
     3389#endif
    33333390                  ++f;
    33343391
     
    33823439                /* This is the start of a new recipe line.  Skip whitespace
    33833440                   and prefix characters but not newlines.  */
     3441#ifndef CONFIG_WITH_COMMANDS_FUNC
    33843442                while (ISBLANK (*f) || *f == '-' || *f == '@' || *f == '+')
     3443#else
     3444                char ch;
     3445                while (ISBLANK ((ch = *f)) || ch == '-' || ch == '@' || ch == '+' || ch == '%')
     3446#endif
    33853447                  ++f;
    33863448
  • trunk/src/kmk/job.h

    r3140 r3156  
    147147#elif defined(__EMX__)
    148148int exec_command (char **argv, char **envp);
    149 #else
     149#elif !defined(WINDOWS32) || !defined(CONFIG_NEW_WIN_CHILDREN)
    150150void exec_command (char **argv, char **envp) __attribute__ ((noreturn));
    151151#endif
  • trunk/src/kmk/kmkbuiltin/kSubmit.c

    r3140 r3156  
    5151#endif
    5252#ifdef KBUILD_OS_WINDOWS
    53 # include "sub_proc.h"
     53# ifndef CONFIG_NEW_WIN_CHILDREN
     54#  include "sub_proc.h"
     55# else
     56#  include "../w32/winchildren.h"
     57# endif
    5458#endif
    5559
     
    933937    if (rc == -1)
    934938    {
     939# ifndef CONFIG_NEW_WIN_CHILDREN
    935940        if (process_kmk_register_submit(pWorker->OverlappedRead.hEvent, (intptr_t)pWorker, pPidSpawned) == 0)
    936941        { /* likely */ }
     
    942947            goto l_again;
    943948        }
     949# else
     950        if (MkWinChildCreateSubmit((intptr_t)pWorker->OverlappedRead.hEvent, pWorker, pPidSpawned) == 0)
     951        { /* likely */ }
     952        else
     953        {
     954            /* We need to do the waiting here because sub_proc.c has too much to do. */
     955            warnx("MkWinChildCreateSubmit failed!");
     956            WaitForSingleObject(pWorker->OverlappedRead.hEvent, INFINITE);
     957            goto l_again;
     958        }
     959# endif
    944960    }
    945961    else
  • trunk/src/kmk/kmkbuiltin/redirect.c

    r3145 r3156  
    7070#include "kmkbuiltin.h"
    7171#ifdef KMK
     72# include "job.h"
     73# include "variable.h"
    7274# ifdef KBUILD_OS_WINDOWS
    73 #  include "sub_proc.h"
     75#  ifndef CONFIG_NEW_WIN_CHILDREN
     76#   include "sub_proc.h"
     77#  else
     78#   include "../w32/winchildren.h"
     79#  endif
    7480#  include "pathstuff.h"
    7581# endif
    76 # include "job.h"
    77 # include "variable.h"
    7882#endif
    7983
     
    888892                if ((intptr_t)hProcess != -1)
    889893                {
     894# ifndef CONFIG_NEW_WIN_CHILDREN
    890895                    if (process_kmk_register_redirect(hProcess, pPidSpawned) == 0)
     896# else
     897                    if (MkWinChildCreateRedirect((intptr_t)hProcess, pPidSpawned) == 0)
     898# endif
    891899                    {
    892900                        if (cVerbosity > 0)
     
    896904                    {
    897905                        DWORD dwTmp;
     906# ifndef CONFIG_NEW_WIN_CHILDREN
    898907                        warn("sub_proc is out of slots, waiting for child...");
     908# else
     909                        warn("MkWinChildCreateRedirect failed...");
     910# endif
    899911                        dwTmp = WaitForSingleObject(hProcess, INFINITE);
    900912                        if (dwTmp != WAIT_OBJECT_0)
  • trunk/src/kmk/main.c

    r3155 r3156  
    3838# include <io.h>
    3939# include "pathstuff.h"
    40 # include "sub_proc.h"
     40# ifndef CONFIG_NEW_WIN_CHILDREN
     41#  include "sub_proc.h"
     42# else
     43#  include "w32/winchildren.h"
     44# endif
    4145# include "w32err.h"
    4246#endif
     
    22032207 job_setup_complete:
    22042208
     2209#if defined (WINDOWS32) && defined(CONFIG_NEW_WIN_CHILDREN)
     2210  /* Initialize the windows child management. */
     2211  MkWinChildInit(job_slots);
     2212#endif
     2213
    22052214  /* The extra indirection through $(MAKE_COMMAND) is done
    22062215     for hysterical raisins.  */
     
    31203129            setrlimit (RLIMIT_STACK, &stack_limit);
    31213130#endif
     3131# if !defined(WINDOWS32) || !defined(CONFIG_NEW_WIN_CHILDREN)
    31223132          exec_command ((char **)nargv, environ);
     3133# else
     3134          MkWinChildReExecMake ((char **)nargv, environ);
     3135# endif
    31233136#endif
    31243137          free (aargv);
  • trunk/src/kmk/makeint.h

    r3140 r3156  
    474474# include <malloc.h>
    475475# define pipe(_p)        _pipe((_p), 512, O_BINARY)
     476# ifndef CONFIG_NEW_WIN_CHILDREN /* (only used by commands.c) */
    476477# define kill(_pid,_sig) w32_kill((_pid),(_sig))
     478# endif
    477479/* MSVC and Watcom C don't have ftruncate.  */
    478480# if defined(_MSC_VER) || defined(__WATCOMC__)
     
    485487
    486488void sync_Path_environment (void);
     489# ifndef CONFIG_NEW_WIN_CHILDREN /* (only used by commands.c) */
    487490int w32_kill (pid_t pid, int sig);
     491# endif
    488492int find_and_set_default_shell (const char *token);
    489493
  • trunk/src/kmk/output.c

    r3140 r3156  
    3737# include <windows.h>
    3838# include <io.h>
    39 # include "sub_proc.h"
     39# ifndef CONFIG_NEW_WIN_CHILDREN
     40#  include "sub_proc.h"
     41# else
     42#  include "w32/winchildren.h"
     43# endif
    4044#endif /* WINDOWS32 */
    4145
  • trunk/src/kmk/read.c

    r3145 r3156  
    3333#ifdef WINDOWS32
    3434#include <windows.h>
    35 #include "sub_proc.h"
     35# ifndef _MSC_VER
     36#  ifndef CONFIG_NEW_WIN_CHILDREN
     37#   include "sub_proc.h"
     38#  else
     39#   include "w32/winchildren.h"
     40#  endif
     41# endif
    3642#else  /* !WINDOWS32 */
    3743#ifndef _AMIGA
     
    423429    }
    424430
     431#ifdef _MSC_VER
     432  ENULLLOOP (ebuf.fp, fopen (filename, "rN")); /* N == noinherit */
     433#else
    425434  ENULLLOOP (ebuf.fp, fopen (filename, "r"));
     435#endif
    426436
    427437  /* Save the error code so we print the right message later.  */
     
    454464          const char *included = concat (3, include_directories[i],
    455465                                         "/", filename);
     466#ifdef _MSC_VER
     467          ebuf.fp = fopen (included, "rN"); /* N == noinherit */
     468#else
    456469          ebuf.fp = fopen (included, "r");
     470#endif
    457471          if (ebuf.fp)
    458472            {
     
    496510  /* Set close-on-exec to avoid leaking the makefile to children, such as
    497511     $(shell ...).  */
     512#ifndef _MSC_VER /* not necessary, see fopen calls above. */
    498513#ifdef HAVE_FILENO
    499514  CLOSE_ON_EXEC (fileno (ebuf.fp));
     515#endif
    500516#endif
    501517
  • trunk/src/kmk/w32/include/sub_proc.h

    r3140 r3156  
    1717#ifndef SUB_PROC_H
    1818#define SUB_PROC_H
     19#ifdef CONFIG_NEW_WIN_CHILDREN
     20# error "Just checking..."
     21#endif
    1922
    2023/*
  • trunk/src/kmk/w32/w32os.c

    r3140 r3156  
    2424#include <io.h>
    2525#include "pathstuff.h"
    26 #include "sub_proc.h"
     26#ifndef CONFIG_NEW_WIN_CHILDREN
     27# include "sub_proc.h"
     28#else
     29# include "winchildren.h"
     30#endif
    2731#include "w32err.h"
    2832#include "os.h"
     
    169173jobserver_acquire (int timeout)
    170174{
     175#ifndef CONFIG_NEW_WIN_CHILDREN
    171176    HANDLE handles[MAXIMUM_WAIT_OBJECTS + 1]; /* bird: + 1 to prevent trashing the stack. */
     177#else
     178    HANDLE handles[2];
     179#endif
    172180    DWORD dwHandleCount;
    173181    DWORD dwEvent;
     
    176184    handles[0] = jobserver_semaphore;
    177185
     186#ifndef CONFIG_NEW_WIN_CHILDREN
    178187    /* Build array of handles to wait for.  */
    179188    dwHandleCount = 1 + process_set_handles (&handles[1]);
     189#else
     190    /* Add the completed children event as the 2nd one. */
     191    handles[1] = (HANDLE)MkWinChildGetCompleteEventHandle();
     192    dwHandleCount = 2;
     193#endif
    180194
    181195    dwEvent = WaitForMultipleObjects (
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette