VirtualBox

Changeset 2053 in kBuild


Ignore:
Timestamp:
Nov 4, 2008 12:26:28 AM (16 years ago)
Author:
bird
Message:

kmk/incdep.c: Check for the environment variables KMK_THREADS_DISABLED / KMK_THREADS_ENABLED to overload the defaults for starting worker threads. Also check for fakeroot and disable all threads if seen - it seems to have trouble with our worker thread or something.

File:
1 edited

Legend:

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

    r2019 r2053  
    585585#endif
    586586
     587/* Checks if threads are enabled or not.
     588
     589   This is a special hack so that is possible to disable the threads when in a
     590   debian fakeroot environment.  Thus, in addition to the KMK_THREADS_DISABLED
     591   and KMK_THREADS_ENABLED environment variable check we also check for signs
     592   of fakeroot.  */
     593static int
     594incdep_are_threads_enabled (void)
     595{
     596  if (getenv("KMK_THREADS_DISABLED"))
     597    return 0;
     598  if (getenv("KMK_THREADS_ENABLED"))
     599    return 1;
     600#if defined(__gnu_linux__) || defined(__linux__)
     601  if (getenv("FAKEROOTKEY"))
     602    return 0;
     603  if (getenv("FAKEROOTUID"))
     604    return 0;
     605  if (getenv("FAKEROOTGID"))
     606    return 0;
     607  if (getenv("FAKEROOTEUID"))
     608    return 0;
     609  if (getenv("FAKEROOTEGID"))
     610    return 0;
     611  if (getenv("FAKEROOTSUID"))
     612    return 0;
     613  if (getenv("FAKEROOTSGID"))
     614    return 0;
     615  if (getenv("FAKEROOTFUID"))
     616    return 0;
     617  if (getenv("FAKEROOTFGID"))
     618    return 0;
     619  if (getenv("FAKEROOTDONTTRYCHOWN"))
     620    return 0;
     621  if (getenv("FAKEROOT_FD_BASE"))
     622    return 0;
     623  if (getenv("FAKEROOT_DB_SEARCH_PATHS"))
     624    return 0;
     625#endif /* GNU/Linux */
     626  return 1;
     627}
     628
    587629/* Creates the the worker threads. */
    588630static void
     
    651693
    652694  incdep_terminate = 0;
    653   incdep_num_threads = sizeof (incdep_threads) / sizeof (incdep_threads[0]);
    654   if (incdep_num_threads + 1 > job_slots)
    655     incdep_num_threads = job_slots <= 1 ? 1 : job_slots - 1;
    656   for (i = 0; i < incdep_num_threads; i++)
    657     {
    658       /* init caches */
    659       unsigned rec_size = sizeof (struct incdep_variable_in_set);
    660       if (rec_size < sizeof (struct incdep_variable_def))
    661         rec_size = sizeof (struct incdep_variable_def);
    662       if (rec_size < sizeof (struct incdep_recorded_files))
    663         rec_size = sizeof (struct incdep_recorded_files);
    664       alloccache_init (&incdep_rec_caches[i], rec_size, "incdep rec",
    665                        incdep_cache_allocator, (void *)(size_t)i);
    666       alloccache_init (&incdep_dep_caches[i], sizeof(struct dep), "incdep dep",
    667                        incdep_cache_allocator, (void *)(size_t)i);
    668       strcache2_init (&incdep_dep_strcaches[i],
    669                       "incdep dep", /* name */
    670                       65536,        /* hash size */
    671                       0,            /* default segment size*/
     695  if (incdep_are_threads_enabled())
     696    {
     697      incdep_num_threads = sizeof (incdep_threads) / sizeof (incdep_threads[0]);
     698      if (incdep_num_threads + 1 > job_slots)
     699        incdep_num_threads = job_slots <= 1 ? 1 : job_slots - 1;
     700      for (i = 0; i < incdep_num_threads; i++)
     701        {
     702          /* init caches */
     703          unsigned rec_size = sizeof (struct incdep_variable_in_set);
     704          if (rec_size < sizeof (struct incdep_variable_def))
     705            rec_size = sizeof (struct incdep_variable_def);
     706          if (rec_size < sizeof (struct incdep_recorded_files))
     707            rec_size = sizeof (struct incdep_recorded_files);
     708          alloccache_init (&incdep_rec_caches[i], rec_size, "incdep rec",
     709                           incdep_cache_allocator, (void *)(size_t)i);
     710          alloccache_init (&incdep_dep_caches[i], sizeof(struct dep), "incdep dep",
     711                           incdep_cache_allocator, (void *)(size_t)i);
     712          strcache2_init (&incdep_dep_strcaches[i],
     713                          "incdep dep", /* name */
     714                          65536,        /* hash size */
     715                          0,            /* default segment size*/
    672716#ifdef HAVE_CASE_INSENSITIVE_FS
    673                       1,            /* case insensitive */
     717                          1,            /* case insensitive */
    674718#else
    675                       0,            /* case insensitive */
    676 #endif
    677                       0);           /* thread safe */
    678 
    679       strcache2_init (&incdep_var_strcaches[i],
    680                       "incdep var", /* name */
    681                       32768,        /* hash size */
    682                       0,            /* default segment size*/
    683                       0,            /* case insensitive */
    684                       0);           /* thread safe */
    685 
    686       /* create the thread. */
     719                          0,            /* case insensitive */
     720#endif
     721                          0);           /* thread safe */
     722
     723          strcache2_init (&incdep_var_strcaches[i],
     724                          "incdep var", /* name */
     725                          32768,        /* hash size */
     726                          0,            /* default segment size*/
     727                          0,            /* case insensitive */
     728                          0);           /* thread safe */
     729
     730          /* create the thread. */
    687731#ifdef HAVE_PTHREAD
    688       rc = pthread_attr_init (&attr);
    689       if (rc)
    690         fatal (f, _("pthread_attr_init failed: err=%d"), rc);
    691       /*rc = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE); */
    692       rc = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
    693       if (rc)
    694         fatal (f, _("pthread_attr_setdetachstate failed: err=%d"), rc);
    695       rc = pthread_create(&incdep_threads[i], &attr,
    696                            incdep_worker_pthread, (void *)(size_t)i);
    697       if (rc)
    698         fatal (f, _("pthread_mutex_init failed: err=%d"), rc);
    699       pthread_attr_destroy (&attr);
     732          rc = pthread_attr_init (&attr);
     733          if (rc)
     734            fatal (f, _("pthread_attr_init failed: err=%d"), rc);
     735          /*rc = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_JOINABLE); */
     736          rc = pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED);
     737          if (rc)
     738            fatal (f, _("pthread_attr_setdetachstate failed: err=%d"), rc);
     739          rc = pthread_create(&incdep_threads[i], &attr,
     740                               incdep_worker_pthread, (void *)(size_t)i);
     741          if (rc)
     742            fatal (f, _("pthread_mutex_init failed: err=%d"), rc);
     743          pthread_attr_destroy (&attr);
    700744
    701745#elif defined (WINDOWS32)
    702       tid = 0;
    703       hThread = _beginthreadex (NULL, 128*1024, incdep_worker_windows,
    704                                 (void *)i, 0, &tid);
    705       if (hThread == 0 || hThread == ~(uintptr_t)0)
    706         fatal (f, _("_beginthreadex failed: err=%d"), errno);
    707       incdep_threads[i] = (HANDLE)hThread;
     746          tid = 0;
     747          hThread = _beginthreadex (NULL, 128*1024, incdep_worker_windows,
     748                                    (void *)i, 0, &tid);
     749          if (hThread == 0 || hThread == ~(uintptr_t)0)
     750            fatal (f, _("_beginthreadex failed: err=%d"), errno);
     751          incdep_threads[i] = (HANDLE)hThread;
    708752
    709753#elif defined (__OS2__)
    710       tid = _beginthread (incdep_worker_os2, NULL, 128*1024, (void *)i);
    711       if (tid <= 0)
    712         fatal (f, _("_beginthread failed: err=%d"), errno);
    713       incdep_threads[i] = tid;
    714 #endif
    715     }
     754          tid = _beginthread (incdep_worker_os2, NULL, 128*1024, (void *)i);
     755          if (tid <= 0)
     756            fatal (f, _("_beginthread failed: err=%d"), errno);
     757          incdep_threads[i] = tid;
     758#endif
     759        }
     760    }
     761  else
     762    incdep_num_threads = 0;
    716763
    717764  incdep_initialized = 1;
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