Changeset 23 for trunk/kernel/kern/thread.h
- Timestamp:
- Jun 18, 2017, 10:06:41 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/kernel/kern/thread.h
r16 r23 3 3 * 4 4 * Author Ghassan Almaless (2008,2009,2010,2011,2012) 5 * Mohamed Lamine Karaoui (2015)6 5 * Alain Greiner (2016) 7 6 * … … 43 42 44 43 /*************************************************************************************** 45 * This defines the various pthread_attr_t flags. 46 **************************************************************************************/ 47 48 #define PT_FLAG_DETACH 0x001 // user defined not joinable 49 #define PT_FLAG_CLUSTER_DEFINED 0x002 // user defined target cluster 50 #define PT_FLAG_CORE_DEFINED 0x004 // user defined core cluster 51 52 /*************************************************************************************** 53 * This structure defines the input argument of the pthread_create() system call. 54 * It contains all informations required to initialize an user thread, and is passed 55 * as input argument to the thread_user_create() function. 56 * It is partly set by the kernel, partly set by the user application itself, 57 * using the pthread_attr_***() functions. 44 * These macros are used to compose or decompose global thread identifier (TRDID) 45 * to or from cluster identifier / local thread index (CXY , LTID) 46 **************************************************************************************/ 47 48 #define LTID_FROM_TRDID( trdid ) (ltid_t)(trdid & 0x0000FFFF) 49 #define CXY_FROM_TRDID( trdid ) (cxy_t)(trdid >> 16) 50 #define TRDID( cxy , ltid ) (trdid_t)((cxy << 16) | ltid ) 51 52 /*************************************************************************************** 53 * This defines the various pthread_attr_t attributes bit-vector. 54 **************************************************************************************/ 55 56 /*************************************************************************************** 57 * This opaque structure contains the user defined attributes for an user thread. 58 * It is passed as input argument to the thread_user_create() function. 59 * It is set by the user application itself, using the pthread_attr_***() functions. 60 * The currently supported attributes are defined below. 58 61 **************************************************************************************/ 59 62 60 63 typedef struct pthread_attr_s 61 64 { 62 pid_t pid; /*! owner process identifier */ 63 void * entry_func; /*! pointer on entry function */ 64 void * entry_args; /*! pointer on entry function arguments */ 65 uint32_t flags; /*! pthread flags (entirely user specified) */ 66 cxy_t cxy; /*! target cluster (can be user specified) */ 67 lid_t lid; /*! target core (can be user specified) */ 65 uint32_t attributes; /*! user defined attributes bit vector */ 66 cxy_t cxy; /*! target cluster identifier */ 67 lid_t lid; /*! target core index */ 68 68 } 69 69 pthread_attr_t; 70 70 71 typedef enum 72 { 73 PT_ATTR_DETACH = 0x0001, /*! user defined not joinable */ 74 PT_ATTR_CLUSTER_DEFINED = 0x0002, /*! user defined target cluster */ 75 PT_ATTR_CORE_DEFINED = 0x0004, /*! user defined core index in cluster */ 76 } 77 pt_attributes_t; 71 78 72 79 /*************************************************************************************** … … 86 93 87 94 /*************************************************************************************** 88 * This defines the masks associated to the thread flags.95 * This defines the thread flags bit-vector. 89 96 **************************************************************************************/ 90 97 91 98 #define THREAD_FLAG_LOADABLE 0x0001 /*! This thread has not been executed yet */ 92 #define THREAD_FLAG_DETACHED 0x0002 /*! This user thread is detached from parent */ 99 #define THREAD_FLAG_DETACHED 0x0002 /*! This thread is detached from parent */ 100 #define THREAD_FLAG_JOIN 0x0004 /*! Parent thread made a join */ 101 #define THREAD_FLAG_EXIT 0x0008 /*! This thread made an exit */ 93 102 94 103 /*************************************************************************************** … … 102 111 **************************************************************************************/ 103 112 104 #define THREAD_BLOCKED_GLOBAL 0x0001 /*! thread global blocking*/113 #define THREAD_BLOCKED_GLOBAL 0x0001 /*! thread desactivated / wait activation */ 105 114 #define THREAD_BLOCKED_IO 0x0002 /*! thread wait IO operation completion */ 106 115 #define THREAD_BLOCKED_MAPPER 0x0004 /*! thread wait mapper */ 107 #define THREAD_BLOCKED_EXIT 0x0010 /*! thread requested exit */ 116 #define THREAD_BLOCKED_JOIN 0x0008 /*! thread blocked in join / wait exit */ 117 #define THREAD_BLOCKED_EXIT 0x0010 /*! thread blocked in exit / wait join i */ 108 118 #define THREAD_BLOCKED_KILL 0x0020 /*! thread received kill signal */ 109 119 #define THREAD_BLOCKED_SEM 0x0040 /*! thread wait semaphore */ 110 120 #define THREAD_BLOCKED_PAGE 0x0080 /*! thread wait page access */ 121 #define THREAD_BLOCKED_USERSYNC 0x0100 /*! thread wait POSIX (cond/mutex/barrier) */ 122 111 123 #define THREAD_BLOCKED_IDLE 0x1000 /*! thread RPC wait activation */ 112 124 #define THREAD_BLOCKED_DEV_QUEUE 0x2000 /*! thread DEV wait queue */ … … 141 153 * that is returned by the kernel to the user: 142 154 * - The TRDID 16 LSB bits contain the LTID (Local Thread Index). 143 * - The TRDID 16 MSB bits contain the owner cluster CXY.155 * - The TRDID 16 MSB bits contain the CXY of cluster containing the thread. 144 156 * - The LTID is used to index the th_tbl[] array in the local process descriptor. 145 157 * This TRDID is computed by the process_register_thread() function, when the user … … 155 167 void * fpu_context; /*! used for dynamic FPU allocation */ 156 168 157 uint32_t trdid; /*! thread index ( in THTBL) */169 uint32_t trdid; /*! thread index (cxy.ltid) */ 158 170 thread_type_t type; /*! thread type */ 159 171 uint32_t quantum; /*! number of clock ticks given to thread */ … … 162 174 core_t * core; /*! pointer to the owner core */ 163 175 process_t * process; /*! pointer on local process descriptor */ 164 176 xptr_t parent; /*! extended pointer on parent thread */ 177 178 void * exit_value; /*! exit_value used in case of join */ 179 165 180 uint32_t local_locks; /*! number of local locks owned by thread */ 166 181 list_entry_t locks_root; /*! root of local locks list */ 182 183 remote_spinlock_t * flags_lock; /*! lock protecting the flags */ 167 184 168 185 uint32_t remote_locks; /*! number of local locks owned by thread */ … … 182 199 183 200 error_t errno; /*! errno value set by last system call */ 201 uint32_t utls; /*! user thread local storage */ 184 202 185 203 bool_t fork_user; /*! user defined placement for next fork() */ … … 231 249 /*************************************************************************************** 232 250 * This function allocates memory for an user thread descriptor in the local cluster, 233 * and initializes it from information contained in the "attr" argument.234 * It is used by the pthread_create system call, the CPU context is initialised from235 * scratch, and the "loadable" field is set.236 * The new thread is attached to the core specified in the "attr"argument.237 * It is registered in the local process descriptor for the process specified in "attr".251 * and initializes it from information contained in the arguments. 252 * It is used by the "pthread_create" system call. 253 * The CPU context is initialised from scratch, and the "loadable" field is set. 254 * The new thread is attached to the core specified in the <attr> argument. 255 * It is registered in the local process descriptor specified by the <pid> argument. 238 256 * The thread descriptor pointer is returned to allow the parent thread to register it 239 257 * in its children list. 240 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 241 *************************************************************************************** 242 * @ new_thread : address of buffer for new thread descriptor pointer. 258 * The THREAD_BLOCKED_GLOBAL bit is set => the thread must be activated to start. 259 *************************************************************************************** 260 * @ pid : process identifier. 261 * @ start_func : pointer on entry function. 262 * @ start_args : pointer on function argument (can be NULL). 243 263 * @ attr : pointer on pthread attributes descriptor. 244 * @ u_stack_base : actual user stack size. 245 * @ u_stack_size : actual user stack base. 264 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 246 265 * @ returns 0 if success / returns ENOMEM if error. 247 266 **************************************************************************************/ 248 error_t thread_user_create( thread_t ** new_thread, 267 error_t thread_user_create( pid_t pid, 268 void * start_func, 269 void * start_arg, 249 270 pthread_attr_t * attr, 250 intptr_t u_stack_base, 251 uint32_t u_stack_size ); 271 thread_t ** new_thread ); 252 272 253 273 /*************************************************************************************** … … 261 281 * The THREAD_BLOCKED_GLOBAL bit is set, and the thread must be activated to start. 262 282 *************************************************************************************** 263 * @ new_thread : address of buffer for new thread descriptor pointer.264 283 * @ process : local pointer on owner process descriptor. 265 * @ u_stack_base : actual user stack size. 266 * @ u_stack_size : actual user stack base. 284 * @ new_thread : [out] address of buffer for new thread descriptor pointer. 267 285 * @ returns 0 if success / returns ENOMEM if error. 268 286 **************************************************************************************/ 269 error_t thread_user_fork( thread_t ** new_thread, 270 process_t * process, 271 intptr_t u_stack_base, 272 uint32_t u_stack_size ); 287 error_t thread_user_fork( process_t * process, 288 thread_t ** new_thread ); 273 289 274 290 /*************************************************************************************** … … 343 359 * This function removes an user thread from the parent thread global list 344 360 * of attached children threads. 345 * It does take the lock, as this function can be called by the child thread.346 * In this case, it uses the extended pointer on the parent thread contained347 * in the pthread_attr_t embedded in the child thread descriptor.348 361 *************************************************************************************** 349 362 * @ xp_parent : extended pointer on the parent thread descriptor. … … 352 365 void thread_child_parent_unlink( xptr_t xp_parent, 353 366 xptr_t xp_child ); 354 355 367 356 368 /*************************************************************************************** … … 475 487 void thread_signals_handle( thread_t * thread ); 476 488 489 /*************************************************************************************** 490 * This function returns the extended pointer on a thread descriptor identified 491 * by its thread identifier, and process identifier. 492 * It can be called by any thread running in any cluster. 493 *************************************************************************************** 494 * @ pid : process identifier. 495 * @ trdid : thread identifier. 496 * @ return the extended pointer if thread found / return XPTR_NULL if not found. 497 **************************************************************************************/ 498 xptr_t thread_get_xptr( pid_t pid, 499 trdid_t trdid ); 477 500 478 501
Note: See TracChangeset
for help on using the changeset viewer.