Changeset 2843 for trunk/src/kmk/w32


Ignore:
Timestamp:
Aug 28, 2016, 5:31:02 PM (9 years ago)
Author:
bird
Message:

kmk: kSubmit is mostly done.

Location:
trunk/src/kmk/w32
Files:
2 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/w32/include/sub_proc.h

    r2591 r2843  
    3939EXTERN_DECL(long process_pipe_io, (HANDLE proc, char *stdin_data,
    4040        int stdin_data_len));
     41#ifndef KMK /* unused */
    4142EXTERN_DECL(long process_file_io, (HANDLE proc));
     43#endif
    4244EXTERN_DECL(void process_cleanup, (HANDLE proc));
    4345EXTERN_DECL(HANDLE process_wait_for_any, (VOID_DECL));
     
    4648EXTERN_DECL(BOOL process_kill, (HANDLE proc, int signal));
    4749EXTERN_DECL(int process_used_slots, (VOID_DECL));
     50#ifdef KMK
     51EXTERN_DECL(int process_kmk_register_submit, (HANDLE hEvent, intptr_t clue));
     52#endif
    4853
    4954/* support routines */
  • trunk/src/kmk/w32/subproc/sub_proc.c

    r2636 r2843  
    2727#include <signal.h>
    2828#include <windows.h>
     29#ifdef KMK
     30# include <assert.h>
     31# include "make.h"
     32# include "kmkbuiltin.h"
     33#endif
     34
    2935
    3036#include "sub_proc.h"
     
    3440
    3541static char *make_command_line(char *shell_name, char *exec_path, char **argv);
     42#ifndef KMK
    3643extern char *xmalloc (unsigned int);
    37 #ifdef KMK
     44#else
    3845extern void kmk_cache_exec_image(const char *); /* imagecache.c */
    3946#endif
    4047
    4148typedef struct sub_process_t {
     49#ifdef KMK
     50        enum { kRegular = 0, kSubmit, kSubProcFreed } enmType;
     51        intptr_t clue;
     52#endif
    4253        intptr_t sv_stdin[2];
    4354        intptr_t sv_stdout[2];
     
    6475static int fake_exits_pending = 0;
    6576
     77#ifndef KMK /* Inefficient! */
    6678/*
    6779 * When a process has been waited for, adjust the wait state
     
    88100        }
    89101}
     102#endif /* !KMK */
    90103
    91104/*
     
    112125        /* wait for someone to exit */
    113126        if (!fake_exits_pending) {
     127#ifdef KMK
     128l_wait_again:
     129#endif
    114130                retval = WaitForMultipleObjects(proc_index, handles, FALSE, INFINITE);
    115131                which = retval - WAIT_OBJECT_0;
     
    123139        if (retval != WAIT_FAILED) {
    124140                sub_process* pproc = proc_array[which];
     141#ifdef KMK
     142                if (pproc->enmType == kSubmit) {
     143                    /* Try get the result from kSubmit.c.  This may not succeed if the whole
     144                       result hasn't arrived yet, in which we just restart the wait. */
     145                    if (kSubmitSubProcGetResult(pproc->clue, &pproc->exit_code, &pproc->signal) != 0) {
     146                        goto l_wait_again;
     147                    }
     148                }
     149#endif
     150#ifndef KMK /* Inefficient! */
    125151                process_adjust_wait_state(pproc);
     152#else
     153                proc_index--;
     154                if ((int)which < proc_index)
     155                        proc_array[which] = proc_array[proc_index];
     156                proc_array[proc_index] = NULL;
     157#endif
    126158                return pproc;
    127159        } else
     
    133165 */
    134166BOOL
    135 process_kill(HANDLE proc, int signal)
     167 process_kill(HANDLE proc, int signal)
    136168{
    137169        sub_process* pproc = (sub_process*) proc;
    138170        pproc->signal = signal;
     171#ifdef KMK
     172        if (pproc->enmType == kRegular) {
     173#endif
    139174        return (TerminateProcess((HANDLE) pproc->pid, signal));
     175#ifdef KMK
     176        } else if (pproc->enmType == kSubmit) {
     177                return kSubmitSubProcKill(pproc->clue, signal) == 0;
     178        }
     179        assert(0);
     180        return FALSE;
     181#endif
    140182}
    141183
     
    149191process_register(HANDLE proc)
    150192{
     193#ifdef KMK
     194        assert(((sub_process *)proc)->enmType == kRegular);
     195#endif
    151196        if (proc_index < MAXIMUM_WAIT_OBJECTS)
    152197                proc_array[proc_index++] = (sub_process *) proc;
    153198}
     199
     200#ifdef KMK
     201/**
     202 * Interface used by kmkbuiltin/kSubmit.c to register stuff going down in a
     203 * worker process.
     204 *
     205 * @returns 0 on success, -1 if there are too many sub-processes already.
     206 * @param   hEvent              The event semaphore to wait on.
     207 * @param   clue                The clue to base.
     208 */
     209int
     210process_kmk_register_submit(HANDLE hEvent, intptr_t clue)
     211{
     212        if (proc_index < MAXIMUM_WAIT_OBJECTS) {
     213                sub_process *pSubProc = (sub_process *)xcalloc(sizeof(*pSubProc));
     214                pSubProc->enmType = kSubmit;
     215                pSubProc->clue    = clue;
     216                pSubProc->pid     = (intptr_t)hEvent;
     217
     218                proc_array[proc_index++] = pSubProc;
     219                return 0;
     220        }
     221        return -1;
     222}
     223#endif
    154224
    155225/*
     
    197267                 */
    198268#ifdef KMK
    199                 (void) process_file_io_private(pproc, FALSE);
     269                if (pproc->enmType == kRegular) {
     270                    (void)process_file_io_private(pproc, FALSE);
     271                }
    200272#else
    201273                (void) process_file_io(pproc);
     
    445517#ifdef KMK
    446518        size_t exec_path_len;
     519
     520        assert (pproc->enmType == kRegular);
    447521#endif
    448522
     
    783857        bool_t child_dead = FALSE;
    784858        BOOL GetExitCodeResult;
     859#ifdef KMK
     860        assert (pproc->enmType == kRegular);
     861#endif
    785862
    786863        /*
     
    918995}
    919996
     997#ifndef KMK /* unused */
    920998/*
    921999 * Purpose: collects output from child process and returns results
     
    9431021        return process_file_io_private(proc, TRUE);
    9441022}
     1023#endif /* !KMK - unused */
    9451024
    9461025/* private function, avoid some kernel calls. (bird) */
     
    10241103        int i;
    10251104
     1105#ifdef KMK
     1106        if (pproc->enmType == kRegular) {
     1107#endif
     1108
    10261109        if (pproc->using_pipes) {
    10271110                for (i= 0; i <= 1; i++) {
     
    10361119        if ((HANDLE)pproc->pid)
    10371120                CloseHandle((HANDLE)pproc->pid);
     1121#ifdef KMK
     1122        } else if (pproc->enmType == kSubmit) {
     1123            /* nothing to do. */
     1124        } else {
     1125            assert(0);
     1126            return;
     1127        }
     1128        pproc->enmType = kSubProcFreed;
     1129#endif
    10381130
    10391131        free(pproc);
Note: See TracChangeset for help on using the changeset viewer.