exit_process() source code

exit_process() source code based on Contiki's source code 

Line# Code
123 static void
124 exit_process(struct process *p, struct process *fromprocess)
125 {
126     register struct process *q;
127     struct process *old_current = process_current;
128  
129     PRINTF("process: exit_process '%s'\n", PROCESS_NAME_STRING(p));
130  
131      /* Make sure the process is in the process list before we try to
132        exit it. */
133      for(q = process_list; q != p && q != NULL; q = q->next);
134      if(q == NULL) {
135         return;
136       }
137  
138      if(process_is_running(p)) {
139          /* Process was running */
140          p->state = PROCESS_STATE_NONE;
141  
142           /*
143            * Post a synchronous event to all processes to inform them that
144            * this process is about to exit. This will allow services to
145            * deallocate state associated with this process.
146            */
147         for(q = process_list; q != NULL; q = q->next) {
148             if(p != q) {
149                 call_process(q, PROCESS_EVENT_EXITED, (process_data_t)p);
150              }
151         }
152  
153       if(p->thread != NULL && p != fromprocess) {
154              /* Post the exit event to the process that is about to exit. */
155              process_current = p;
156              p->thread(&p->pt, PROCESS_EVENT_EXIT, NULL);
157       }
158   }
159  
160   if(p == process_list) {
161      process_list = process_list->next;
162    } else {
163      for(q = process_list; q != NULL; q = q->next) {
164          if(q->next == p) {
165              q->next = p->next;
166               break;
167           }
168      }
169    }
170    receiver->state = PROCESS_STATE_RUNNING;
171    process_current = old_current;
172 }

 

https://people.iut.ac.ir/en/mahmoudzadeh/exitprocess-source-code