Changeset 142 for trunk/src/sh_pthread.c


Ignore:
Timestamp:
Oct 30, 2007, 12:17:00 AM (17 years ago)
Author:
rainer
Message:

Login watch runs in thread.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/sh_pthread.c

    r141 r142  
    4040
    4141/* MODULES: init()
    42  *             -- starts thread_run() function if threaded
    43  *             -- fallback on internal_init if threading fails
    44  *             -- and returns MODULE_INACTIVE/MODULE_ACTIVE/MODULE_THREADED
    45  *
    46  *                int retval = MODULE_INACTIVE;
    47  *                if (0 != sh_pthread_create(thread_run, NULL))
    48  *                   return internal_init();
    49  *                return MODULE_THREADED;
    50  *
    51  *          thread_run()
     42 *
     43 * #ifdef HAVE_PTHREAD
     44 *  if (arg != NULL)
     45 *    {
     46 *      if (0 == sh_pthread_create(sh_threaded_module_run, (void *)arg))
     47 *        return SH_MOD_THREAD;
     48 *      else
     49 *        return SH_MOD_FAILED;
     50 *    }
     51 * #else
     52 *  return sh_utmp_init_internal();
     53 * #endif
     54 *
     55 *
     56 *          sh_threaded_module_run(module_struct)
    5257 *             -- calls internal init,
    5358 *             -- polls timer,
     
    131136/* ---- Utility functions for modules ----
    132137 */
    133 void sh_threaded_module_reconf(void *arg)
     138void sh_threaded_module_cleanup(void *arg)
    134139{
    135140  sh_mtype * this_module = (sh_mtype *) arg;
    136   this_module->mod_reconf();
     141  this_module->mod_cleanup();
    137142  return;
    138143}
    139144
    140 void sh_threaded_module_run(void *arg)
     145void * sh_threaded_module_run(void *arg)
    141146{
    142147  sh_mtype * this_module = (sh_mtype *) arg;
     
    153158      if (0 == this_module->mod_init(NULL))
    154159        {
    155           pthread_cleanup_push(sh_threaded_module_reconf, arg);
     160          pthread_cleanup_push(sh_threaded_module_cleanup, arg);
    156161
    157162          while (1)
     
    159164              if (0 != this_module->mod_timer(time(NULL)))
    160165                {
    161                   this_module->mod_check();
     166                  /* If module has been de-activated on reconfigure,
     167                   * mod_check() must return non-zero.
     168                   * The mod_cleanup() routine must then enable the
     169                   * module to be re-activated eventually.
     170                   */
     171                  if (0 != this_module->mod_check())
     172                    break;
    162173                  pthread_testcancel();
    163174                  retry_msleep(1,0);
     
    171182  pthread_cleanup_pop(1);
    172183
    173   return;
     184  return NULL;
    174185}
    175186
Note: See TracChangeset for help on using the changeset viewer.