* @brief Creates a new thread. * @post The created thread has a reference counter set to one, it is * caller responsibility to call @p chThdRelease() or @p chThdWait() * in order to release the reference. The thread persists in the * registry until its reference counter reaches zero. * @note A thread can terminate by calling @p chThdExit() or by simply *
| 323 | * @api |
| 324 | */ |
| 325 | thread_t *chThdCreateStatic(void *wsp, size_t size, |
| 326 | tprio_t prio, tfunc_t pf, void *arg) { |
| 327 | thread_t *tp; |
| 328 | |
| 329 | chDbgCheck((wsp != NULL) && |
| 330 | MEM_IS_ALIGNED(wsp, PORT_WORKING_AREA_ALIGN) && |
| 331 | (size >= THD_WORKING_AREA_SIZE(0)) && |
| 332 | MEM_IS_ALIGNED(size, PORT_STACK_ALIGN) && |
| 333 | (prio <= HIGHPRIO) && (pf != NULL)); |
| 334 | |
| 335 | #if (CH_CFG_USE_REGISTRY == TRUE) && \ |
| 336 | ((CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE)) |
| 337 | chDbgAssert(chRegFindThreadByWorkingArea(wsp) == NULL, |
| 338 | "working area in use"); |
| 339 | #endif |
| 340 | |
| 341 | #if CH_DBG_FILL_THREADS == TRUE |
| 342 | __thd_stackfill((uint8_t *)wsp, (uint8_t *)wsp + size); |
| 343 | #endif |
| 344 | |
| 345 | chSysLock(); |
| 346 | |
| 347 | /* The thread structure is laid out in the upper part of the thread |
| 348 | workspace. The thread position structure is aligned to the required |
| 349 | stack alignment because it represents the stack top.*/ |
| 350 | tp = threadref(((uint8_t *)wsp + size - |
| 351 | MEM_ALIGN_NEXT(sizeof (thread_t), PORT_STACK_ALIGN))); |
| 352 | |
| 353 | #if (CH_DBG_ENABLE_STACK_CHECK == TRUE) || (CH_CFG_USE_DYNAMIC == TRUE) |
| 354 | /* Stack boundary.*/ |
| 355 | tp->wabase = (stkalign_t *)wsp; |
| 356 | #endif |
| 357 | |
| 358 | /* Setting up the port-dependent part of the working area.*/ |
| 359 | PORT_SETUP_CONTEXT(tp, wsp, tp, pf, arg); |
| 360 | |
| 361 | tp = __thd_object_init(currcore, tp, "noname", prio); |
| 362 | |
| 363 | /* Starting the thread immediately.*/ |
| 364 | chSchWakeupS(tp, MSG_OK); |
| 365 | chSysUnlock(); |
| 366 | |
| 367 | return tp; |
| 368 | } |
| 369 | |
| 370 | /** |
| 371 | * @brief Starts a thread created with @p chThdCreateSuspended(). |