int work_hpthread(int argc, char *argv[]) { /* Loop forever */ for (;;) { /* First, perform garbage collection. This cleans-up memory de-allocations * that were queued because they could not be freed in that execution * context (for example, if the memory was freed from an interrupt handler). * NOTE: If the work thread is disabled, this clean-up is performed by * the IDLE thread (at a very, very low priority). */ #ifndef CONFIG_SCHED_LPWORK sched_garbagecollection(); #endif /* Then process queued work. We need to keep interrupts disabled while * we process items in the work list. */ work_process(&g_work[HPWORK]); } return OK; /* To keep some compilers happy */ }
int ProcessPool::add_process(int listenfd){ Process *process = new Process(); if(process == NULL)return -1; if(socketpair(AF_UNIX, SOCK_STREAM, 0, process->pipefd)<0){ perror("socketpair"); return -1; } pid_t pid = fork(); if(pid < 0){ perror("fork"); return -1; } else if(pid == 0){ sleep(1); work_process(listenfd, process->pipefd); } else{ close(process->pipefd[1]); process->pid = pid; printf("create process, pid=%d\n",process->pid); workers.push_back(process); } return 0; }
int work_usrthread(int argc, char *argv[]) { /* Loop forever */ for (;;) { /* Then process queued work. We need to keep interrupts disabled while * we process items in the work list. */ work_process(&g_work[USRWORK], USRWORK); } return PX4_OK; /* To keep some compilers happy */ }
static pthread_addr_t work_usrthread(pthread_addr_t arg) #endif { /* Loop forever */ for (; ; ) { /* Then process queued work. We need to keep the work queue locked * while we process items in the work list. */ work_process(&g_usrwork); } #ifdef CONFIG_BUILD_PROTECTED return OK; /* To keep some compilers happy */ #else return NULL; /* To keep some compilers happy */ #endif }
static int work_lpthread(int argc, char *argv[]) { #if CONFIG_SCHED_LPNTHREADS > 0 int wndx; pid_t me = getpid(); int i; /* Find out thread index by search the workers in g_lpwork */ for (wndx = 0, i = 0; i < CONFIG_SCHED_LPNTHREADS; i++) { if (g_lpwork.worker[i].pid == me) { wndx = i; break; } } DEBUGASSERT(i < CONFIG_SCHED_LPNTHREADS); #endif /* Loop forever */ for (; ; ) { #if CONFIG_SCHED_LPNTHREADS > 0 /* Thread 0 is special. Only thread 0 performs period garbage collection */ if (wndx > 0) { /* The other threads will perform work, waiting indefinitely until * signalled for the next work availability. * * The special value of zero for the poll period instructs work_process * to wait indefinitely until a signal is received. */ work_process((FAR struct kwork_wqueue_s *)&g_lpwork, 0, wndx); } else #endif { /* Perform garbage collection. This cleans-up memory de-allocations * that were queued because they could not be freed in that execution * context (for example, if the memory was freed from an interrupt handler). * NOTE: If the work thread is disabled, this clean-up is performed by * the IDLE thread (at a very, very low priority). * * In the event of multiple low priority threads, on index == 0 will do * the garbage collection. */ sched_garbage_collection(); /* Then process queued work. work_process will not return until: * (1) there is no further work in the work queue, and (2) the polling * period provided by g_lpwork.delay expires. */ work_process((FAR struct kwork_wqueue_s *)&g_lpwork, g_lpwork.delay, 0); } } return OK; /* To keep some compilers happy */ }