#include "thread.h" static thread_handle_t myThdHandles[THREAD_ID_MAX]={0}; int thread_start(int id, thread_fn fn, void *arg, int stksize, int prio) { int r; pthread_attr_t attr; if(id>=THREAD_ID_MAX) { return -1; } thread_handle_t *h=&myThdHandles[id]; h->arg = arg; h->quit = 0; r = pthread_attr_init(&attr); if(r) { printf("____ thread %d attr init failed\n", id); return -1; } #if 0 h->stk = malloc(stksize); if(h->stk) { r = pthread_attr_setstack(h->stk, stksize); if(r) { printf("____ thread %d attr setstack failed\n", id); } } else { r = pthread_attr_setstacksize(&attr, stksize); if(r) { printf("____ thread %d attr setstacksize %d failed\n", id, stksize); } } #endif r = pthread_create(&h->tid, &attr, fn, h); pthread_attr_destroy(&attr); return r; } int thread_stop(int id) { if(id>=THREAD_ID_MAX) { return -1; } thread_handle_t *h=&myThdHandles[id]; h->quit = 1; pthread_join(h->tid, NULL); h->tid = 0; h->arg = NULL; h->fn = NULL; return 0; } int thread_stop_all(void) { int i; for(i=0; i