Ignore:
Timestamp:
Mar 21, 2018, 12:27:47 PM (7 years ago)
Author:
bird
Message:

kmk/win: Run kDepObj on worker thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin.c

    r3168 r3169  
    3535#ifdef _MSC_VER
    3636# include <io.h>
     37#endif
     38#if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
     39# include "makeint.h"
     40# include "job.h"
     41# include "w32/winchildren.h"
    3742#endif
    3843#include "kmkbuiltin/err.h"
     
    226231 * kmk built command.
    227232 */
    228 static struct KMKBUILTINENTRY
     233static const KMKBUILTINENTRY g_aBuiltins[] =
    229234{
    230     const char *pszName;
    231     size_t      cchName;
    232     union
    233     {
    234         uintptr_t uPfn;
    235 #define FN_SIG_MAIN             0
    236         int (* pfnMain)(int argc, char **argv, char **envp);
    237 #define FN_SIG_MAIN_SPAWNS      1
    238         int (* pfnMainSpawns)(int argc, char **argv, char **envp, struct child *pChild, pid_t *pPid);
    239 #define FN_SIG_MAIN_TO_SPAWN    2
    240         int (* pfnMainToSpawn)(int argc, char **argv, char **envp, char ***ppapszArgvToSpawn);
    241     } u;
    242     size_t      uFnSignature : 8;
    243     size_t      fMpSafe : 1;
    244     size_t      fNeedEnv : 1;
    245 } const g_aBuiltins[] =
    246 {
    247 #define BUILTIN_ENTRY(a_fn, a_uFnSignature, fMpSafe, fNeedEnv) \
    248     { &(#a_fn)[12], sizeof(#a_fn) - 12 - 1, \
    249        (uintptr_t)a_fn,                     a_uFnSignature,  fMpSafe, fNeedEnv }
     235#define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fMpSafe, fNeedEnv) \
     236    {  { { sizeof(a_sz) - 1, a_sz, } }, \
     237       (uintptr_t)a_fn,                                 a_uFnSignature,   fMpSafe, fNeedEnv }
    250238
    251239    /* More frequently used commands: */
    252     BUILTIN_ENTRY(kmk_builtin_append,       FN_SIG_MAIN,            0, 0),
    253     BUILTIN_ENTRY(kmk_builtin_printf,       FN_SIG_MAIN,            0, 0),
    254     BUILTIN_ENTRY(kmk_builtin_echo,         FN_SIG_MAIN,            0, 0),
    255     BUILTIN_ENTRY(kmk_builtin_install,      FN_SIG_MAIN,            0, 0),
    256     BUILTIN_ENTRY(kmk_builtin_kDepObj,      FN_SIG_MAIN,            0, 0),
     240    BUILTIN_ENTRY(kmk_builtin_append,   "append",       FN_SIG_MAIN,            0, 0),
     241    BUILTIN_ENTRY(kmk_builtin_printf,   "printf",       FN_SIG_MAIN,            0, 0),
     242    BUILTIN_ENTRY(kmk_builtin_echo,     "echo",         FN_SIG_MAIN,            0, 0),
     243    BUILTIN_ENTRY(kmk_builtin_install,  "install",      FN_SIG_MAIN,            0, 0),
     244    BUILTIN_ENTRY(kmk_builtin_kDepObj,  "kDepObj",      FN_SIG_MAIN,            1, 0),
    257245#ifdef KBUILD_OS_WINDOWS
    258     BUILTIN_ENTRY(kmk_builtin_kSubmit,      FN_SIG_MAIN_SPAWNS,     0, 0),
    259 #endif
    260     BUILTIN_ENTRY(kmk_builtin_mkdir,        FN_SIG_MAIN,            0, 0),
    261     BUILTIN_ENTRY(kmk_builtin_mv,           FN_SIG_MAIN,            0, 0),
    262     BUILTIN_ENTRY(kmk_builtin_redirect,     FN_SIG_MAIN_SPAWNS,     0, 0),
    263     BUILTIN_ENTRY(kmk_builtin_rm,           FN_SIG_MAIN,            0, 0),
    264     BUILTIN_ENTRY(kmk_builtin_rmdir,        FN_SIG_MAIN,            0, 0),
    265     BUILTIN_ENTRY(kmk_builtin_test,         FN_SIG_MAIN_TO_SPAWN,   0, 0),
     246    BUILTIN_ENTRY(kmk_builtin_kSubmit,  "kSubmit",      FN_SIG_MAIN_SPAWNS,     0, 0),
     247#endif
     248    BUILTIN_ENTRY(kmk_builtin_mkdir,    "mkdir",        FN_SIG_MAIN,            0, 0),
     249    BUILTIN_ENTRY(kmk_builtin_mv,       "mv",           FN_SIG_MAIN,            0, 0),
     250    BUILTIN_ENTRY(kmk_builtin_redirect, "redirect",     FN_SIG_MAIN_SPAWNS,     0, 1),
     251    BUILTIN_ENTRY(kmk_builtin_rm,       "rm",           FN_SIG_MAIN,            0, 1),
     252    BUILTIN_ENTRY(kmk_builtin_rmdir,    "rmdir",        FN_SIG_MAIN,            0, 0),
     253    BUILTIN_ENTRY(kmk_builtin_test,     "test",         FN_SIG_MAIN_TO_SPAWN,   0, 0),
    266254    /* Less frequently used commands: */
    267     BUILTIN_ENTRY(kmk_builtin_kDepIDB,      FN_SIG_MAIN,            0, 0),
    268     BUILTIN_ENTRY(kmk_builtin_chmod,        FN_SIG_MAIN,            0, 0),
    269     BUILTIN_ENTRY(kmk_builtin_cp,           FN_SIG_MAIN,            0, 0),
    270     BUILTIN_ENTRY(kmk_builtin_expr,         FN_SIG_MAIN,            0, 0),
    271     BUILTIN_ENTRY(kmk_builtin_ln,           FN_SIG_MAIN,            0, 0),
    272     BUILTIN_ENTRY(kmk_builtin_md5sum,       FN_SIG_MAIN,            0, 0),
    273     BUILTIN_ENTRY(kmk_builtin_cmp,          FN_SIG_MAIN,            0, 0),
    274     BUILTIN_ENTRY(kmk_builtin_cat,          FN_SIG_MAIN,            0, 0),
    275     BUILTIN_ENTRY(kmk_builtin_touch,        FN_SIG_MAIN,            0, 0),
    276     BUILTIN_ENTRY(kmk_builtin_sleep,        FN_SIG_MAIN,            0, 0),
    277     BUILTIN_ENTRY(kmk_builtin_dircache,     FN_SIG_MAIN,            0, 0),
     255    BUILTIN_ENTRY(kmk_builtin_kDepIDB,  "kDepIDB",      FN_SIG_MAIN,            0, 0),
     256    BUILTIN_ENTRY(kmk_builtin_chmod,    "chmod",        FN_SIG_MAIN,            0, 0),
     257    BUILTIN_ENTRY(kmk_builtin_cp,       "cp",           FN_SIG_MAIN,            0, 1),
     258    BUILTIN_ENTRY(kmk_builtin_expr,     "expr",         FN_SIG_MAIN,            0, 0),
     259    BUILTIN_ENTRY(kmk_builtin_ln,       "ln",           FN_SIG_MAIN,            0, 0),
     260    BUILTIN_ENTRY(kmk_builtin_md5sum,   "md5sum",       FN_SIG_MAIN,            0, 0),
     261    BUILTIN_ENTRY(kmk_builtin_cmp,      "cmp",          FN_SIG_MAIN,            0, 0),
     262    BUILTIN_ENTRY(kmk_builtin_cat,      "cat",          FN_SIG_MAIN,            0, 0),
     263    BUILTIN_ENTRY(kmk_builtin_touch,    "touch",        FN_SIG_MAIN,            0, 0),
     264    BUILTIN_ENTRY(kmk_builtin_sleep,    "sleep",        FN_SIG_MAIN,            0, 0),
     265    BUILTIN_ENTRY(kmk_builtin_dircache, "dircache",     FN_SIG_MAIN,            0, 0),
    278266};
    279267
     
    289277    {
    290278        struct KMKBUILTINENTRY const *pEntry;
    291         size_t cchCmd;
    292         char ch0;
    293         int  cLeft;
     279        size_t cchAndStart;
     280        int    cLeft;
    294281
    295282        pszCmd += sizeof(s_szPrefix) - 1;
     283
     284        /*
     285         * Calc the length and start word to avoid calling memcmp/strcmp on each entry.
     286         */
     287#if K_ARCH_BITS != 64 && K_ARCH_BITS != 32
     288# error "PORT ME!"
     289#endif
     290        cchAndStart = strlen(pszCmd);
     291#if K_ENDIAN == K_ENDIAN_BIG
     292        cchAndStart <<= K_ARCH_BITS - 8;
     293        switch (cchAndStart)
     294        {
     295            default:                                   /* fall thru */
     296# if K_ARCH_BITS >= 64
     297            case 7: cchAndStart |= (size_t)pszCmd[6] << (K_ARCH_BITS - 56); /* fall thru */
     298            case 6: cchAndStart |= (size_t)pszCmd[5] << (K_ARCH_BITS - 48); /* fall thru */
     299            case 5: cchAndStart |= (size_t)pszCmd[4] << (K_ARCH_BITS - 40); /* fall thru */
     300            case 4: cchAndStart |= (size_t)pszCmd[3] << (K_ARCH_BITS - 32); /* fall thru */
     301# endif
     302            case 3: cchAndStart |= (size_t)pszCmd[2] << (K_ARCH_BITS - 24); /* fall thru */
     303            case 2: cchAndStart |= (size_t)pszCmd[1] << (K_ARCH_BITS - 16); /* fall thru */
     304            case 1: cchAndStart |= (size_t)pszCmd[0] << (K_ARCH_BITS -  8); /* fall thru */
     305            case 0: break;
     306        }
     307#else
     308        switch (cchAndStart)
     309        {
     310            default:                                   /* fall thru */
     311# if K_ARCH_BITS >= 64
     312            case 7: cchAndStart |= (size_t)pszCmd[6] << 56; /* fall thru */
     313            case 6: cchAndStart |= (size_t)pszCmd[5] << 48; /* fall thru */
     314            case 5: cchAndStart |= (size_t)pszCmd[4] << 40; /* fall thru */
     315            case 4: cchAndStart |= (size_t)pszCmd[3] << 32; /* fall thru */
     316# endif
     317            case 3: cchAndStart |= (size_t)pszCmd[2] << 24; /* fall thru */
     318            case 2: cchAndStart |= (size_t)pszCmd[1] << 16; /* fall thru */
     319            case 1: cchAndStart |= (size_t)pszCmd[0] <<  8; /* fall thru */
     320            case 0: break;
     321        }
     322#endif
    296323
    297324        /*
    298325         * Look up the builtin command in the table.
    299326         */
    300         cchCmd  = strlen(pszCmd);
    301         ch0     = *pszCmd;
    302327        pEntry  = &g_aBuiltins[0];
    303328        cLeft   = sizeof(g_aBuiltins) / sizeof(g_aBuiltins[0]);
    304329        while (cLeft-- > 0)
    305             if (   *pEntry->pszName != ch0
    306                 || pEntry->cchName != cchCmd
    307                 || memcmp(pEntry->pszName, pszCmd, cchCmd) != 0)
     330            if (   pEntry->uName.cchAndStart != cchAndStart
     331                || (   pEntry->uName.s.cch >= sizeof(cchAndStart)
     332                    && memcmp(pEntry->uName.s.sz, pszCmd, pEntry->uName.s.cch) != 0) )
    308333                pEntry++;
    309334            else
    310335            {
     336                /*
     337                 * That's a match!
     338                 */
    311339                int rc;
    312 #if defined(KBUILD_OS_WINDOWS) && CONFIG_NEW_WIN_CHILDREN
     340#if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN)
    313341                if (pEntry->fMpSafe)
     342                    rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, pEntry->fNeedEnv ? pChild->environment : NULL,
     343                                                 pChild, pPidSpawned);
     344                else
     345#endif
    314346                {
    315                     rc = 98;
    316                 }
    317                 else
    318 #endif
    319                 {
    320                     char **envp = environ; /** @todo fixme? */
     347                    char **envp = pChild->environment ? pChild->environment : environ;
    321348
    322349                    /*
     
    364391                return rc;
    365392            }
     393
     394        /*
     395         * No match! :-(
     396         */
    366397        fprintf(stderr, "kmk_builtin: Unknown command '%s%s'!\n", s_szPrefix, pszCmd);
    367398    }
Note: See TracChangeset for help on using the changeset viewer.