volatile sq_queue_t g_delayed_kfree;
#endif
+/* This gives number of alive tasks at any point of time in the system.
+ * If the system is already running CONFIG_MAX_TASKS, Creating new
+ * task is not supported.
+ */
+volatile uint8_t g_alive_taskcount;
+
/* This is the value of the last process ID assigned to a task */
volatile pid_t g_lastpid;
g_pidhash[PIDHASH(0)].tcb = &g_idletcb.cmn;
g_pidhash[PIDHASH(0)].pid = 0;
+ /* Increment the g_alive_taskcount as first task "idle task" is created */
+ g_alive_taskcount++;
+
/* Initialize the IDLE task TCB *******************************************/
/* Initialize a TCB for this thread of execution. NOTE: The default
* value for most components of the g_idletcb are zero. The entire
extern volatile dq_queue_t g_inactivetasks;
+/* This gives number of alive tasks at any point of time in the system.
+ * If the system is already running CONFIG_MAX_TASKS, Creating new
+ * task is not supported.
+ */
+extern volatile uint8_t g_alive_taskcount;
+
/* These are lists of dayed memory deallocations that need to be handled
* within the IDLE loop or worker thread. These deallocations get queued
* by sched_kufree and sched_kfree() if the OS needs to deallocate memory
* parameters are required, argv may be NULL.
*
* Return Value:
- * Returns the non-zero process ID of the new task or ERROR if memory is
- * insufficient or the task cannot be created. The errno will be set to
- * indicate the nature of the error (always ENOMEM).
+ * Returns the non-zero process ID of the new task on success
+ * ERROR on failure. The errno will be set to indicate the nature of the error.
+ *
+ * This function can fail for three reasons.
+ * 1) If the memory is insufficient, errno = ENOMEM
+ * 2) If requested priority is beyond the allowed range, errno = EINVAL
+ * 3) If it is unable to assign a new, unique task ID to the TCB. errno = EBUSY
*
****************************************************************************/
trace_begin(TTRACE_TAG_TASK, "thread_create");
+ /* Check whether we are allowed to create new task ? */
+ if (g_alive_taskcount == CONFIG_MAX_TASKS) {
+ sdbg("ERROR: CONFIG_MAX_TASKS(%d) count reached\n",CONFIG_MAX_TASKS);
+ errcode = EBUSY;
+ goto errout;
+ }
+
/* Allocate a TCB for the new task. */
tcb = (FAR struct task_tcb_s *)kmm_zalloc(sizeof(struct task_tcb_s));
* parameters are required, argv may be NULL.
*
* Return Value:
- * Returns the non-zero process ID of the new task or ERROR if memory is
- * insufficient or the task cannot be created. The errno will be set to
- * indicate the nature of the error (always ENOMEM).
+ * Returns the non-zero process ID of the new task on success
+ * ERROR on failure. The errno will be set to indicate the nature of the error.
+ *
+ * This function can fail for three reasons.
+ * 1) If the memory is insufficient, errno = ENOMEM
+ * 2) If requested priority is beyond the allowed range, errno = EINVAL
+ * 3) If it is unable to assign a new, unique task ID to the TCB. errno = EBUSY
*
****************************************************************************/