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


   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 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright 2016 Joyent, Inc.
  28  */
  29 
  30 #include "lint.h"
  31 #include "thr_uberdata.h"
  32 
  33 /*
  34  * pthread_once related data
  35  * This structure is exported as pthread_once_t in pthread.h.
  36  * We export only the size of this structure. so check
  37  * pthread_once_t in pthread.h before making a change here.
  38  */
  39 typedef struct  __once {
  40         mutex_t mlock;
  41         union {
  42                 uint32_t        pad32_flag[2];
  43                 uint64_t        pad64_flag;
  44         } oflag;
  45 } __once_t;
  46 
  47 #define once_flag       oflag.pad32_flag[1]


 111         const thrattr_t *ap = attr? attr->__pthread_attrp : def_thrattr();
 112         const pcclass_t *pccp;
 113         long            flag;
 114         pthread_t       tid;
 115         int             error;
 116 
 117         update_sched(self);
 118 
 119         if (ap == NULL)
 120                 return (EINVAL);
 121 
 122         /* validate explicit scheduling attributes */
 123         if (ap->inherit == PTHREAD_EXPLICIT_SCHED &&
 124             (ap->policy == SCHED_SYS ||
 125             (pccp = get_info_by_policy(ap->policy)) == NULL ||
 126             ap->prio < pccp->pcc_primin || ap->prio > pccp->pcc_primax))
 127                 return (EINVAL);
 128 
 129         flag = ap->scope | ap->detachstate | ap->daemonstate | THR_SUSPENDED;
 130         error = _thrp_create(ap->stkaddr, ap->stksize, start_routine, arg,
 131             flag, &tid, ap->guardsize);
 132         if (error == 0) {
 133                 /*
 134                  * Record the original inheritence value for
 135                  * pthread_getattr_np(). We should always be able to find the
 136                  * thread.
 137                  */
 138                 (void) _thr_setinherit(tid, ap->inherit);
 139 
 140                 if (ap->inherit == PTHREAD_EXPLICIT_SCHED &&
 141                     (ap->policy != self->ul_policy ||
 142                     ap->prio != (self->ul_epri ? self->ul_epri :
 143                     self->ul_pri))) {
 144                         /*
 145                          * The SUSv3 specification requires pthread_create()
 146                          * to fail with EPERM if it cannot set the scheduling
 147                          * policy and parameters on the new thread.
 148                          */
 149                         error = _thr_setparam(tid, ap->policy, ap->prio);
 150                 }
 151 




   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 /*
  23  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  */
  26 /*
  27  * Copyright 2018 Joyent, Inc.
  28  */
  29 
  30 #include "lint.h"
  31 #include "thr_uberdata.h"
  32 
  33 /*
  34  * pthread_once related data
  35  * This structure is exported as pthread_once_t in pthread.h.
  36  * We export only the size of this structure. so check
  37  * pthread_once_t in pthread.h before making a change here.
  38  */
  39 typedef struct  __once {
  40         mutex_t mlock;
  41         union {
  42                 uint32_t        pad32_flag[2];
  43                 uint64_t        pad64_flag;
  44         } oflag;
  45 } __once_t;
  46 
  47 #define once_flag       oflag.pad32_flag[1]


 111         const thrattr_t *ap = attr? attr->__pthread_attrp : def_thrattr();
 112         const pcclass_t *pccp;
 113         long            flag;
 114         pthread_t       tid;
 115         int             error;
 116 
 117         update_sched(self);
 118 
 119         if (ap == NULL)
 120                 return (EINVAL);
 121 
 122         /* validate explicit scheduling attributes */
 123         if (ap->inherit == PTHREAD_EXPLICIT_SCHED &&
 124             (ap->policy == SCHED_SYS ||
 125             (pccp = get_info_by_policy(ap->policy)) == NULL ||
 126             ap->prio < pccp->pcc_primin || ap->prio > pccp->pcc_primax))
 127                 return (EINVAL);
 128 
 129         flag = ap->scope | ap->detachstate | ap->daemonstate | THR_SUSPENDED;
 130         error = _thrp_create(ap->stkaddr, ap->stksize, start_routine, arg,
 131             flag, &tid, ap->guardsize, ap->name);
 132         if (error == 0) {
 133                 /*
 134                  * Record the original inheritence value for
 135                  * pthread_getattr_np(). We should always be able to find the
 136                  * thread.
 137                  */
 138                 (void) _thr_setinherit(tid, ap->inherit);
 139 
 140                 if (ap->inherit == PTHREAD_EXPLICIT_SCHED &&
 141                     (ap->policy != self->ul_policy ||
 142                     ap->prio != (self->ul_epri ? self->ul_epri :
 143                     self->ul_pri))) {
 144                         /*
 145                          * The SUSv3 specification requires pthread_create()
 146                          * to fail with EPERM if it cannot set the scheduling
 147                          * policy and parameters on the new thread.
 148                          */
 149                         error = _thr_setparam(tid, ap->policy, ap->prio);
 150                 }
 151