Print this page
5045 use atomic_{inc,dec}_* instead of atomic_add_*


   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 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 
  26 #pragma ident   "%Z%%M% %I%     %E% SMI"
  27 
  28 #include <sys/proc.h>
  29 #include <sys/systm.h>
  30 #include <sys/param.h>
  31 #include <sys/atomic.h>
  32 #include <sys/kmem.h>
  33 #include <sys/sysmacros.h>
  34 #include <sys/procset.h>
  35 #include <sys/corectl.h>
  36 #include <sys/zone.h>
  37 #include <sys/cmn_err.h>
  38 #include <sys/policy.h>
  39 
  40 /*
  41  * Core File Settings
  42  * ------------------
  43  *
  44  * A process's core file path and content live in separate reference-counted
  45  * structures. The corectl_content_t structure is fairly straightforward --
  46  * the only subtlety is that we only really _need_ the mutex on architectures
  47  * on which 64-bit memory operations are not atomic. The corectl_path_t


  88         core_content_t content;
  89 
  90         mutex_enter(&ccp->ccc_mtx);
  91         content = ccp->ccc_content;
  92         mutex_exit(&ccp->ccc_mtx);
  93 
  94         return (content);
  95 }
  96 
  97 static void
  98 corectl_content_set(corectl_content_t *ccp, core_content_t content)
  99 {
 100         mutex_enter(&ccp->ccc_mtx);
 101         ccp->ccc_content = content;
 102         mutex_exit(&ccp->ccc_mtx);
 103 }
 104 
 105 void
 106 corectl_content_hold(corectl_content_t *ccp)
 107 {
 108         atomic_add_32(&ccp->ccc_refcnt, 1);
 109 }
 110 
 111 void
 112 corectl_content_rele(corectl_content_t *ccp)
 113 {
 114         if (atomic_add_32_nv(&ccp->ccc_refcnt, -1) == 0)
 115                 kmem_free(ccp, sizeof (corectl_content_t));
 116 }
 117 
 118 
 119 static corectl_path_t *
 120 corectl_path_alloc(const char *path)
 121 {
 122         corectl_path_t *ccp;
 123 
 124         ccp = kmem_zalloc(sizeof (corectl_path_t), KM_SLEEP);
 125         ccp->ccp_path = refstr_alloc(path);
 126         ccp->ccp_refcnt = 1;
 127 
 128         return (ccp);
 129 }
 130 
 131 refstr_t *
 132 corectl_path_value(corectl_path_t *ccp)
 133 {
 134         refstr_t *path;


 137         refstr_hold(path = ccp->ccp_path);
 138         mutex_exit(&ccp->ccp_mtx);
 139 
 140         return (path);
 141 }
 142 
 143 static void
 144 corectl_path_set(corectl_path_t *ccp, const char *path)
 145 {
 146         refstr_t *npath = refstr_alloc(path);
 147 
 148         mutex_enter(&ccp->ccp_mtx);
 149         refstr_rele(ccp->ccp_path);
 150         ccp->ccp_path = npath;
 151         mutex_exit(&ccp->ccp_mtx);
 152 }
 153 
 154 void
 155 corectl_path_hold(corectl_path_t *ccp)
 156 {
 157         atomic_add_32(&ccp->ccp_refcnt, 1);
 158 }
 159 
 160 void
 161 corectl_path_rele(corectl_path_t *ccp)
 162 {
 163         if (atomic_add_32_nv(&ccp->ccp_refcnt, -1) == 0) {
 164                 refstr_rele(ccp->ccp_path);
 165                 kmem_free(ccp, sizeof (corectl_path_t));
 166         }
 167 }
 168 
 169 /*
 170  * Constructor routine to be called when a zone is created.
 171  */
 172 /*ARGSUSED*/
 173 static void *
 174 core_init_zone(zoneid_t zoneid)
 175 {
 176         struct core_globals *cg;
 177 
 178         cg = kmem_alloc(sizeof (*cg), KM_SLEEP);
 179         mutex_init(&cg->core_lock, NULL, MUTEX_DEFAULT, NULL);
 180         cg->core_file = NULL;
 181         cg->core_options = CC_PROCESS_PATH;
 182         cg->core_content = CC_CONTENT_DEFAULT;
 183         cg->core_rlimit = RLIM64_INFINITY;




   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 2006 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  */
  25 


  26 #include <sys/proc.h>
  27 #include <sys/systm.h>
  28 #include <sys/param.h>
  29 #include <sys/atomic.h>
  30 #include <sys/kmem.h>
  31 #include <sys/sysmacros.h>
  32 #include <sys/procset.h>
  33 #include <sys/corectl.h>
  34 #include <sys/zone.h>
  35 #include <sys/cmn_err.h>
  36 #include <sys/policy.h>
  37 
  38 /*
  39  * Core File Settings
  40  * ------------------
  41  *
  42  * A process's core file path and content live in separate reference-counted
  43  * structures. The corectl_content_t structure is fairly straightforward --
  44  * the only subtlety is that we only really _need_ the mutex on architectures
  45  * on which 64-bit memory operations are not atomic. The corectl_path_t


  86         core_content_t content;
  87 
  88         mutex_enter(&ccp->ccc_mtx);
  89         content = ccp->ccc_content;
  90         mutex_exit(&ccp->ccc_mtx);
  91 
  92         return (content);
  93 }
  94 
  95 static void
  96 corectl_content_set(corectl_content_t *ccp, core_content_t content)
  97 {
  98         mutex_enter(&ccp->ccc_mtx);
  99         ccp->ccc_content = content;
 100         mutex_exit(&ccp->ccc_mtx);
 101 }
 102 
 103 void
 104 corectl_content_hold(corectl_content_t *ccp)
 105 {
 106         atomic_inc_32(&ccp->ccc_refcnt);
 107 }
 108 
 109 void
 110 corectl_content_rele(corectl_content_t *ccp)
 111 {
 112         if (atomic_dec_32_nv(&ccp->ccc_refcnt) == 0)
 113                 kmem_free(ccp, sizeof (corectl_content_t));
 114 }
 115 
 116 
 117 static corectl_path_t *
 118 corectl_path_alloc(const char *path)
 119 {
 120         corectl_path_t *ccp;
 121 
 122         ccp = kmem_zalloc(sizeof (corectl_path_t), KM_SLEEP);
 123         ccp->ccp_path = refstr_alloc(path);
 124         ccp->ccp_refcnt = 1;
 125 
 126         return (ccp);
 127 }
 128 
 129 refstr_t *
 130 corectl_path_value(corectl_path_t *ccp)
 131 {
 132         refstr_t *path;


 135         refstr_hold(path = ccp->ccp_path);
 136         mutex_exit(&ccp->ccp_mtx);
 137 
 138         return (path);
 139 }
 140 
 141 static void
 142 corectl_path_set(corectl_path_t *ccp, const char *path)
 143 {
 144         refstr_t *npath = refstr_alloc(path);
 145 
 146         mutex_enter(&ccp->ccp_mtx);
 147         refstr_rele(ccp->ccp_path);
 148         ccp->ccp_path = npath;
 149         mutex_exit(&ccp->ccp_mtx);
 150 }
 151 
 152 void
 153 corectl_path_hold(corectl_path_t *ccp)
 154 {
 155         atomic_inc_32(&ccp->ccp_refcnt);
 156 }
 157 
 158 void
 159 corectl_path_rele(corectl_path_t *ccp)
 160 {
 161         if (atomic_dec_32_nv(&ccp->ccp_refcnt) == 0) {
 162                 refstr_rele(ccp->ccp_path);
 163                 kmem_free(ccp, sizeof (corectl_path_t));
 164         }
 165 }
 166 
 167 /*
 168  * Constructor routine to be called when a zone is created.
 169  */
 170 /*ARGSUSED*/
 171 static void *
 172 core_init_zone(zoneid_t zoneid)
 173 {
 174         struct core_globals *cg;
 175 
 176         cg = kmem_alloc(sizeof (*cg), KM_SLEEP);
 177         mutex_init(&cg->core_lock, NULL, MUTEX_DEFAULT, NULL);
 178         cg->core_file = NULL;
 179         cg->core_options = CC_PROCESS_PATH;
 180         cg->core_content = CC_CONTENT_DEFAULT;
 181         cg->core_rlimit = RLIM64_INFINITY;