git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@441 35acf78f-673a-0410-8e92-d51de3d6d3f4
parent
56c0992fe6
commit
b721770076
13
readme.txt
13
readme.txt
|
@ -81,11 +81,18 @@ Win32-MinGW - ChibiOS/RT simulator and demo into a WIN32 process,
|
|||
- NEW: New dynamic chThdCreateFromHeap() and chthdCreateFromMemoryPool() APIs.
|
||||
The dynamic APIs are only included if the CH_USE_DYNAMIC option is specified
|
||||
into the project configuration file.
|
||||
- CHANGE: chThdCreateFast() is now a macro that uses chThdCreateStatic().
|
||||
- CHANGE: chThdWait() now releases the memory allocated by
|
||||
chThdCreateFromHeap() and chthdCreateFromMemoryPool(). Threads created
|
||||
through the static APIs are not affected thus the behavior is backward
|
||||
compatible.
|
||||
- FIX: The chThdCreate() had a regression in 0.7.0, the mode parameter was
|
||||
ignored. Note that in this version the API is deprecated and the bug
|
||||
documented as correct behavior. If you need to create a suspended thread
|
||||
please use the new chThdInit() API.
|
||||
ignored.
|
||||
- FIX: Removed duplicated call to chHeapInit() into chSysInit().
|
||||
- FIX: Fixed a syntax error in chheap.c, the error was only triggered when
|
||||
the CH_USE_DEBUG option was specified.
|
||||
- Added new test cases to the test suite for the new dynamic APIs.
|
||||
- Documentation fixes.
|
||||
|
||||
*** 0.7.0 ***
|
||||
- NEW: Memory Heap Allocator functionality added. The allocator implements a
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -40,18 +40,13 @@ void chSysInit(void) {
|
|||
#ifdef CH_USE_VIRTUAL_TIMERS
|
||||
chVTInit();
|
||||
#endif
|
||||
#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();
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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_ */
|
||||
|
||||
/** @} */
|
||||
|
|
Loading…
Reference in New Issue