Changeset 3173 in kBuild for trunk/src/kmk/kmkbuiltin.c
- Timestamp:
- Mar 21, 2018 9:37:41 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kmk/kmkbuiltin.c
r3172 r3173 5 5 6 6 /* 7 * Copyright (c) 2005-201 0knut st. osmundsen <[email protected]>7 * Copyright (c) 2005-2018 knut st. osmundsen <[email protected]> 8 8 * 9 9 * This file is part of kBuild. … … 24 24 */ 25 25 26 /******************************************************************************* 27 * Header Files * 28 *******************************************************************************/ 26 27 /********************************************************************************************************************************* 28 * Header Files * 29 *********************************************************************************************************************************/ 29 30 #include <string.h> 30 31 #include <stdlib.h> … … 39 40 #include "makeint.h" 40 41 #include "job.h" 42 #include "variable.h" 41 43 #if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 42 44 # include "w32/winchildren.h" … … 48 50 extern char **environ; 49 51 #endif 52 53 54 /********************************************************************************************************************************* 55 * Global Variables * 56 *********************************************************************************************************************************/ 57 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 58 extern int print_stats_flag; 59 #endif 60 50 61 51 62 … … 234 245 static const KMKBUILTINENTRY g_aBuiltIns[] = 235 246 { 236 #define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fM pSafe, fNeedEnv) \247 #define BUILTIN_ENTRY(a_fn, a_sz, a_uFnSignature, fMtSafe, fNeedEnv) \ 237 248 { { { sizeof(a_sz) - 1, a_sz, } }, \ 238 (uintptr_t)a_fn, a_uFnSignature, fM pSafe, fNeedEnv }249 (uintptr_t)a_fn, a_uFnSignature, fMtSafe, fNeedEnv } 239 250 240 251 /* More frequently used commands: */ … … 245 256 BUILTIN_ENTRY(kmk_builtin_kDepObj, "kDepObj", FN_SIG_MAIN, 1, 0), 246 257 #ifdef KBUILD_OS_WINDOWS 247 BUILTIN_ENTRY(kmk_builtin_kSubmit, "kSubmit", FN_SIG_MAIN_SPAWNS, 0, 0),258 BUILTIN_ENTRY(kmk_builtin_kSubmit, "kSubmit", FN_SIG_MAIN_SPAWNS, 0, 1), 248 259 #endif 249 260 BUILTIN_ENTRY(kmk_builtin_mkdir, "mkdir", FN_SIG_MAIN, 0, 0), 250 261 BUILTIN_ENTRY(kmk_builtin_mv, "mv", FN_SIG_MAIN, 0, 0), 251 BUILTIN_ENTRY(kmk_builtin_redirect, "redirect", FN_SIG_MAIN_SPAWNS, 0, 1),262 BUILTIN_ENTRY(kmk_builtin_redirect, "redirect", FN_SIG_MAIN_SPAWNS, 1, 1), 252 263 BUILTIN_ENTRY(kmk_builtin_rm, "rm", FN_SIG_MAIN, 0, 1), 253 264 BUILTIN_ENTRY(kmk_builtin_rmdir, "rmdir", FN_SIG_MAIN, 0, 0), … … 347 358 /* 348 359 * That's a match! 360 * 361 * First get the environment if it is actually needed. This is 362 * especially important when we run on a worker thread as it must 363 * not under any circumstances do stuff like target_environment. 349 364 */ 350 int rc; 365 int rc; 366 char **papszEnvVars = NULL; 367 if (pEntry->fNeedEnv) 368 { 369 papszEnvVars = pChild->environment; 370 if (!papszEnvVars) 371 pChild->environment = papszEnvVars = target_environment(pChild->file); 372 } 373 351 374 #if defined(KBUILD_OS_WINDOWS) && defined(CONFIG_NEW_WIN_CHILDREN) 352 if (pEntry->fMpSafe) 353 { 354 rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, pEntry->fNeedEnv ? pChild->environment : NULL, 355 pChild, pPidSpawned); 375 /* 376 * If the built-in is multi thread safe, we will run it on a job slot thread. 377 */ 378 if (pEntry->fMtSafe) 379 { 380 rc = MkWinChildCreateBuiltIn(pEntry, argc, argv, papszEnvVars, pChild, pPidSpawned); 356 381 # ifdef CONFIG_WITH_KMK_BUILTIN_STATS 357 382 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cAsyncTimes++; … … 361 386 #endif 362 387 { 363 char **envp = pChild->environment ? pChild->environment : environ;364 365 388 /* 366 389 * Call the worker function, making sure to preserve umask. 367 390 */ 368 391 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 369 big_int nsStart = nano_timestamp();392 big_int nsStart = print_stats_flag ? nano_timestamp() : 0; 370 393 #endif 371 394 int const iUmask = umask(0); /* save umask */ … … 373 396 374 397 if (pEntry->uFnSignature == FN_SIG_MAIN) 375 rc = pEntry->u.pfnMain(argc, argv, envp);398 rc = pEntry->u.pfnMain(argc, argv, papszEnvVars); 376 399 else if (pEntry->uFnSignature == FN_SIG_MAIN_SPAWNS) 377 rc = pEntry->u.pfnMainSpawns(argc, argv, envp, pChild, pPidSpawned);400 rc = pEntry->u.pfnMainSpawns(argc, argv, papszEnvVars, pChild, pPidSpawned); 378 401 else if (pEntry->uFnSignature == FN_SIG_MAIN_TO_SPAWN) 379 402 { … … 383 406 * problem then (the call stack shows what's been going on). 384 407 */ 385 rc = pEntry->u.pfnMainToSpawn(argc, argv, envp, ppapszArgvToSpawn);408 rc = pEntry->u.pfnMainToSpawn(argc, argv, papszEnvVars, ppapszArgvToSpawn); 386 409 if ( !rc 387 410 && *ppapszArgvToSpawn … … 410 433 411 434 #ifdef CONFIG_WITH_KMK_BUILTIN_STATS 412 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cTimes++; 413 g_aBuiltInStats[pEntry - &g_aBuiltIns[0]].cNs += nano_timestamp() - nsStart; 435 if (print_stats_flag) 436 { 437 uintptr_t iEntry = pEntry - &g_aBuiltIns[0]; 438 g_aBuiltInStats[iEntry].cTimes++; 439 g_aBuiltInStats[iEntry].cNs += nano_timestamp() - nsStart; 440 } 414 441 #endif 415 442 } … … 442 469 extern void kmk_builtin_print_stats(FILE *pOutput, const char *pszPrefix) 443 470 { 444 const unsigned 471 const unsigned cEntries = sizeof(g_aBuiltInStats) / sizeof(g_aBuiltInStats[0]); 445 472 unsigned i; 473 assert(print_stats_flag); 446 474 fprintf(pOutput, "\n%skmk built-in command statistics:\n", pszPrefix); 447 475 for (i = 0; i < cEntries; i++)
Note:
See TracChangeset
for help on using the changeset viewer.