MCPcopy Create free account
hub / github.com/apache/nuttx / nxtask_assign_pid

Function nxtask_assign_pid

sched/task/task_setup.c:84–202  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

82 ****************************************************************************/
83
84static int nxtask_assign_pid(FAR struct tcb_s *tcb)
85{
86 FAR struct tcb_s **pidhash;
87 irqstate_t flags;
88 pid_t next_pid;
89 int hash_ndx;
90 void *temp;
91 int i;
92
93 /* NOTE:
94 * ERROR means that the g_pidhash[] table is completely full.
95 * We cannot allow another task to be started.
96 */
97
98 /* We'll try every allowable pid */
99
100retry:
101
102 /* Protect the following operation with a critical section
103 * because g_pidhash is accessed from an interrupt context
104 */
105
106 flags = enter_critical_section();
107
108 /* Get the next process ID candidate */
109
110 next_pid = g_lastpid + 1;
111 for (i = 0; i < g_npidhash; i++)
112 {
113 /* Verify that the next_pid is in the valid range */
114
115 if (next_pid <= 0)
116 {
117 next_pid = 1;
118 }
119
120 /* Get the hash_ndx associated with the next_pid */
121
122 hash_ndx = PIDHASH(next_pid);
123
124 /* Check if there is a (potential) duplicate of this pid */
125
126 if (!g_pidhash[hash_ndx])
127 {
128 /* Assign this PID to the task */
129
130 g_pidhash[hash_ndx] = tcb;
131 tcb->pid = next_pid;
132 g_lastpid = next_pid;
133
134 leave_critical_section(flags);
135 return OK;
136 }
137
138 next_pid++;
139 }
140
141 /* If we get here, then the g_pidhash[] table is completely full.

Callers 1

nxthread_setup_schedulerFunction · 0.85

Calls 4

enter_critical_sectionFunction · 0.85
leave_critical_sectionFunction · 0.85
kmm_zallocFunction · 0.85
kmm_freeFunction · 0.85

Tested by

no test coverage detected