Print this page
8158 Want named threads API
9857 proc manpages should have LIBRARY section


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.


  24  */
  25 
  26 #include <strings.h>
  27 #include <stdlib.h>
  28 #include <syslog.h>
  29 #include <errno.h>
  30 #include <libintl.h>
  31 #include <door.h>
  32 #include <sys/types.h>
  33 #include <sys/stat.h>
  34 #include <fcntl.h>
  35 #include <procfs.h>

  36 #include "cachemgr.h"
  37 
  38 extern admin_t  current_admin;
  39 
  40 #define CLEANUP_WAIT_TIME 60
  41 
  42 typedef enum cleanup_type {
  43         CLEANUP_ALL     = 1,
  44         CLEANUP_BY_PID  = 2
  45 } cleanup_type_t;
  46 
  47 typedef struct cleanup_op {
  48         pid_t           pid;
  49         cleanup_type_t  type;
  50 } cleanup_op_t;
  51 
  52 typedef struct main_nscd_struct {
  53         pid_t           pid;                    /* main nscd pid */
  54         thread_t        tid;                    /* main nscd tid */
  55         int             in_progress;            /* A main nscd thread is */


 518                 waiting_list_set_cleanup(chg, pid);
 519         /*
 520          * wake up threads without setting chg.chg_wakeup.
 521          * It's for cleanup purpose, not for notifying changes.
 522          */
 523         (void) cond_broadcast(&chg->chg_cv);
 524         (void) mutex_unlock(&chg->chg_lock);
 525 }
 526 /*
 527  * If arg is NULL, it loops forever,
 528  * else it calls cleanup_threads once and exits.
 529  */
 530 void *
 531 chg_cleanup_waiting_threads(void *arg)
 532 {
 533         cleanup_op_t *op = (cleanup_op_t *)arg;
 534         cleanup_type_t type = 0;
 535         pid_t   pid;
 536         int     always = 1, waiting;
 537 


 538         if (op == NULL) {
 539                 waiting = 1;
 540                 type = CLEANUP_ALL;
 541                 pid = 0;
 542         } else {
 543                 waiting = 0;
 544                 type = op->type;
 545                 pid = op->pid;
 546         }
 547 
 548         while (always) {
 549                 if (waiting)
 550                         (void) sleep(CLEANUP_WAIT_TIME);
 551                 cleanup_threads(&chg, pid, type);
 552                 if (!waiting)
 553                         break;
 554         }
 555 
 556         if (op)
 557                 free(op);




   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2018 Joyent, Inc.
  26  */
  27 
  28 #include <strings.h>
  29 #include <stdlib.h>
  30 #include <syslog.h>
  31 #include <errno.h>
  32 #include <libintl.h>
  33 #include <door.h>
  34 #include <sys/types.h>
  35 #include <sys/stat.h>
  36 #include <fcntl.h>
  37 #include <procfs.h>
  38 #include <pthread.h>
  39 #include "cachemgr.h"
  40 
  41 extern admin_t  current_admin;
  42 
  43 #define CLEANUP_WAIT_TIME 60
  44 
  45 typedef enum cleanup_type {
  46         CLEANUP_ALL     = 1,
  47         CLEANUP_BY_PID  = 2
  48 } cleanup_type_t;
  49 
  50 typedef struct cleanup_op {
  51         pid_t           pid;
  52         cleanup_type_t  type;
  53 } cleanup_op_t;
  54 
  55 typedef struct main_nscd_struct {
  56         pid_t           pid;                    /* main nscd pid */
  57         thread_t        tid;                    /* main nscd tid */
  58         int             in_progress;            /* A main nscd thread is */


 521                 waiting_list_set_cleanup(chg, pid);
 522         /*
 523          * wake up threads without setting chg.chg_wakeup.
 524          * It's for cleanup purpose, not for notifying changes.
 525          */
 526         (void) cond_broadcast(&chg->chg_cv);
 527         (void) mutex_unlock(&chg->chg_lock);
 528 }
 529 /*
 530  * If arg is NULL, it loops forever,
 531  * else it calls cleanup_threads once and exits.
 532  */
 533 void *
 534 chg_cleanup_waiting_threads(void *arg)
 535 {
 536         cleanup_op_t *op = (cleanup_op_t *)arg;
 537         cleanup_type_t type = 0;
 538         pid_t   pid;
 539         int     always = 1, waiting;
 540 
 541         (void) pthread_setname_np(pthread_self(), "chg_cleanup_thr");
 542 
 543         if (op == NULL) {
 544                 waiting = 1;
 545                 type = CLEANUP_ALL;
 546                 pid = 0;
 547         } else {
 548                 waiting = 0;
 549                 type = op->type;
 550                 pid = op->pid;
 551         }
 552 
 553         while (always) {
 554                 if (waiting)
 555                         (void) sleep(CLEANUP_WAIT_TIME);
 556                 cleanup_threads(&chg, pid, type);
 557                 if (!waiting)
 558                         break;
 559         }
 560 
 561         if (op)
 562                 free(op);