diff options
| author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2008-09-24 11:55:40 +0000 | 
|---|---|---|
| committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2008-09-24 11:55:40 +0000 | 
| commit | b72177007695129c089c58f65d05ae6178f604a3 (patch) | |
| tree | 105973ae8132ba54df94ce7f997010583d48a811 /src | |
| parent | 56c0992fe6abb5b06f74f8518eb07b9bc63eac99 (diff) | |
| download | ChibiOS-b72177007695129c089c58f65d05ae6178f604a3.tar.gz ChibiOS-b72177007695129c089c58f65d05ae6178f604a3.tar.bz2 ChibiOS-b72177007695129c089c58f65d05ae6178f604a3.zip  | |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@441 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'src')
| -rw-r--r-- | src/chheap.c | 2 | ||||
| -rw-r--r-- | src/chinit.c | 7 | ||||
| -rw-r--r-- | src/chlists.c | 1 | ||||
| -rw-r--r-- | src/chthreads.c | 76 | ||||
| -rw-r--r-- | src/include/threads.h | 24 | 
5 files changed, 55 insertions, 55 deletions
diff --git a/src/chheap.c b/src/chheap.c index e8ce605c7..7a2f0ccac 100644 --- a/src/chheap.c +++ b/src/chheap.c @@ -150,7 +150,7 @@ void chHeapFree(void *p) {    hp = (struct header *)p - 1;
 -  chDbgAssert(hp->h_magig == MAGIC, "chheap.c, chHeapFree() #1");
 +  chDbgAssert(hp->h_magic == MAGIC, "chheap.c, chHeapFree() #1");
    qp = &heap.free;
    H_LOCK();
 diff --git a/src/chinit.c b/src/chinit.c index 0d4aafea1..9162d84f1 100644 --- a/src/chinit.c +++ b/src/chinit.c @@ -43,15 +43,10 @@ void chSysInit(void) {  #ifdef CH_USE_HEAP    chHeapInit();  #endif -#ifdef CH_USE_HEAP -  chHeapInit(); -#endif    /*     * Now this instructions flow becomes the main thread.     */ -  init_thread(&mainthread, NORMALPRIO); -  mainthread.p_state = PRCURR; -  currp = &mainthread; +  (currp = init_thread(&mainthread, NORMALPRIO))->p_state = PRCURR;    chSysEnable(); diff --git a/src/chlists.c b/src/chlists.c index dcb3b0412..3f5f3e8ee 100644 --- a/src/chlists.c +++ b/src/chlists.c @@ -114,6 +114,7 @@ void list_insert(Thread *tp, ThreadsList *tlp) {   *
   * @param tlp the pointer to the threads list header
   * @return the removed thread pointer
 + * @note The list must be non-empty before calling this function.
   */
  Thread *list_remove(ThreadsList *tlp) {
 diff --git a/src/chthreads.c b/src/chthreads.c index f4d355a4b..88dbefa4d 100644 --- a/src/chthreads.c +++ b/src/chthreads.c @@ -27,11 +27,11 @@  /*   * Initializes a thread structure.   */ -void init_thread(Thread *tp, tprio_t prio) { +Thread *init_thread(Thread *tp, tprio_t prio) {    static tid_t nextid = 0;    tp->p_tid = nextid++; -  tp->p_flags = 0; +  tp->p_flags = P_MEM_MODE_STATIC;    tp->p_prio = prio;    tp->p_state = PRSUSPENDED;  #ifdef CH_USE_MUTEXES @@ -54,6 +54,7 @@ void init_thread(Thread *tp, tprio_t prio) {  #ifdef CH_USE_THREAD_EXT    THREAD_EXT_INIT(tp);  #endif +  return tp;  }  #ifdef CH_USE_DEBUG @@ -95,8 +96,7 @@ Thread *chThdInit(void *workspace, size_t wsize,    memfill(workspace, wsize, MEM_FILL_PATTERN);  #endif    SETUP_CONTEXT(workspace, wsize, pf, arg); -  init_thread(tp, prio); -  return tp; +  return init_thread(tp, prio);  }  /** @@ -117,11 +117,7 @@ Thread *chThdInit(void *workspace, size_t wsize,  Thread *chThdCreateStatic(void *workspace, size_t wsize,                            tprio_t prio, tfunc_t pf, void *arg) { -  Thread *tp = chThdInit(workspace, wsize, prio, pf, arg); -  chSysLock(); -  chSchWakeupS(tp, RDY_OK); -  chSysUnlock(); -  return tp; +  return chThdResume(chThdInit(workspace, wsize, prio, pf, arg));  }  #if defined(CH_USE_DYNAMIC) && defined(CH_USE_WAITEXIT) && defined(CH_USE_HEAP) @@ -152,11 +148,8 @@ Thread *chThdCreateFromHeap(size_t wsize, tprio_t prio,    if (workspace == NULL)      return NULL;    Thread *tp = chThdInit(workspace, wsize, prio, pf, arg); -  tp->p_flags |= P_MEM_MODE_HEAP; -  chSysLock(); -  chSchWakeupS(tp, RDY_OK); -  chSysUnlock(); -  return tp; +  tp->p_flags = P_MEM_MODE_HEAP; +  return chThdResume(tp);  }  #endif /* defined(CH_USE_DYNAMIC) && defined(CH_USE_WAITEXIT) && defined(CH_USE_HEAP) */ @@ -188,12 +181,9 @@ Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio,    if (workspace == NULL)      return NULL;    Thread *tp = chThdInit(workspace, mp->mp_object_size, prio, pf, arg); -  tp->p_flags |= P_MEM_MODE_MEMPOOL; +  tp->p_flags = P_MEM_MODE_MEMPOOL;    tp->p_mpool = mp; -  chSysLock(); -  chSchWakeupS(tp, RDY_OK); -  chSysUnlock(); -  return tp; +  return chThdResume(tp);  }  #endif /* defined(CH_USE_DYNAMIC) && defined(CH_USE_WAITEXIT) && defined(CH_USE_MEMPOOLS) */ @@ -202,7 +192,19 @@ Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio,   * @param prio the priority level for the new thread. Usually the threads are   *             created with priority \p NORMALPRIO, priorities   *             can range from \p LOWPRIO to \p HIGHPRIO. - * @param mode ignored + * @param mode the creation option flags for the thread. The following options + *             can be OR'ed in this parameter:<br> + *             <ul> + *             <li>\p P_SUSPENDED, the thread is created in the + *                 \p PRSUSPENDED state and a subsequent call to + *                 \p chThdResume() will make it ready for + *                 execution.</li> + *             <li>\p P_TERMINATED, this flag is usually set + *                 by the \p chThdTerminate() function and it is not + *                 normally used as parameter for this function. The + *                 result would be to create a thread with a termination + *                 request already pending.</li> + *             </ul>   * @param workspace pointer to a working area dedicated to the thread stack   * @param wsize size of the working area.   * @param pf the thread function. Returning from this function automatically @@ -218,29 +220,10 @@ Thread *chThdCreateFromMemoryPool(MemoryPool *mp, tprio_t prio,  Thread *chThdCreate(tprio_t prio, tmode_t mode, void *workspace,                      size_t wsize, tfunc_t pf, void *arg) { -  return chThdCreateStatic(workspace, wsize, prio, pf, arg); -} - -/** - * Creates a new thread. - * @param prio the priority level for the new thread. Usually the threads are - *             created with priority \p NORMALPRIO, priorities - *             can range from \p LOWPRIO to \p HIGHPRIO. - * @param workspace pointer to a working area dedicated to the thread stack - * @param wsize size of the working area. - * @param pf the thread function. Returning from this function automatically - *           terminates the thread. - * @return the pointer to the \p Thread structure allocated for the - *         thread into the working space area. - * @note A thread can terminate by calling \p chThdExit() or by simply - *       returning from its main function. - * @deprecated Please use \p chThdCreateStatic() or \p chThdInit() instead, - *             this function will be removed in version 1.0.0. - */ -Thread *chThdCreateFast(tprio_t prio, void *workspace, -                        size_t wsize, tfunc_t pf) { - -  return chThdCreateStatic(workspace, wsize, prio, pf, NULL); +  Thread *tp = chThdInit(workspace, wsize, prio, pf, arg); +  if (mode & P_SUSPENDED) +    return tp; +  return chThdResume(tp);  }  /** @@ -291,13 +274,15 @@ void chThdSuspend(Thread **tpp) {  /**   * Resumes a suspended thread.   * @param tp the pointer to the thread + * @return the pointer to the thread   */ -void chThdResume(Thread *tp) { +Thread *chThdResume(Thread *tp) {    chSysLock();    chDbgAssert(tp->p_state == PRSUSPENDED, "chthreads.c, chThdResume()");    chSchWakeupS(tp, RDY_OK);    chSysUnlock(); +  return tp;  }  /** @@ -361,13 +346,12 @@ msg_t chThdWait(Thread *tp) {    msg_t msg;    chSysLock(); - +  chDbgAssert((tp != NULL) && (tp != currp), "chthreads.c, chThdWait()");    if (tp->p_state != PREXIT) {      list_insert(currp, &tp->p_waiting);      chSchGoSleepS(PRWAIT);    }    msg = tp->p_exitcode; -  #ifndef CH_USE_DYNAMIC    chSysUnlock();    return msg; diff --git a/src/include/threads.h b/src/include/threads.h index a1c8167b8..822a9ab69 100644 --- a/src/include/threads.h +++ b/src/include/threads.h @@ -146,6 +146,7 @@ struct Thread {  #define P_MEM_MODE_HEAP         1       /* Thread memory mode: heap.    */  #define P_MEM_MODE_MEMPOOL      2       /* Thread memory mode: mempool. */  #define P_TERMINATE             4       /* Termination requested.       */ +#define P_SUSPENDED             8       /* Create suspended (old).      */  /** Pseudo priority used by the ready list header, do not use.*/  #define NOPRIO      0 @@ -161,7 +162,7 @@ struct Thread {  #define ABSPRIO     255  /* Not an API, don't use into the application code.*/ -void init_thread(Thread *tp, tprio_t prio); +Thread *init_thread(Thread *tp, tprio_t prio);  /** Thread function.*/  typedef msg_t (*tfunc_t)(void *); @@ -186,7 +187,7 @@ extern "C" {                            size_t wsize, tfunc_t pf);    void chThdSetPriority(tprio_t newprio);    void chThdExit(msg_t msg); -  void chThdResume(Thread *tp); +  Thread *chThdResume(Thread *tp);    void chThdSuspend(Thread **tpp);    void chThdTerminate(Thread *tp);  #ifdef CH_USE_WAITEXIT @@ -243,6 +244,25 @@ extern "C" {   */  #define chThdResumeI(tp) chSchReadyI(tp) +/** + * Creates a new thread, simplified variant. + * @param prio the priority level for the new thread. Usually the threads are + *             created with priority \p NORMALPRIO, priorities + *             can range from \p LOWPRIO to \p HIGHPRIO. + * @param workspace pointer to a working area dedicated to the thread stack + * @param wsize size of the working area. + * @param pf the thread function. Returning from this function automatically + *           terminates the thread. + * @return the pointer to the \p Thread structure allocated for the + *         thread into the working space area. + * @note A thread can terminate by calling \p chThdExit() or by simply + *       returning from its main function. + * @deprecated Please use \p chThdCreateStatic() or \p chThdInit() instead, + *             this function will be removed in version 1.0.0. + */ +#define chThdCreateFast(prio, workspace, wsize, pf) \ +        chThdCreateStatic(workspace, wsize, prio, pf, NULL) +  #endif  /* _THREADS_H_ */  /** @} */  | 
