Lines Matching refs:thread

24     MppThread *thread = mpp_malloc(MppThread, 1);  in mpp_thread_create()  local
27 if (thread) { in mpp_thread_create()
28 thread->func = func; in mpp_thread_create()
29 thread->ctx = ctx; in mpp_thread_create()
31 thread->thd_status[THREAD_WORK] = MPP_THREAD_UNINITED; in mpp_thread_create()
32 thread->thd_status[THREAD_INPUT] = MPP_THREAD_RUNNING; in mpp_thread_create()
33 thread->thd_status[THREAD_OUTPUT] = MPP_THREAD_RUNNING; in mpp_thread_create()
34 thread->thd_status[THREAD_CONTROL] = MPP_THREAD_RUNNING; in mpp_thread_create()
37 strncpy(thread->name, name, THREAD_NAME_LEN - 1); in mpp_thread_create()
38 thread->name[THREAD_NAME_LEN - 1] = '\0'; in mpp_thread_create()
40 snprintf(thread->name, THREAD_NAME_LEN, "MppThread"); in mpp_thread_create()
43 mpp_mutex_cond_init(&thread->mutex_cond[i]); in mpp_thread_create()
47 return thread; in mpp_thread_create()
50 void mpp_thread_dump_status(MppThread *thread) in mpp_thread_dump_status() argument
52 mpp_log("thread %s status: %d %d %d %d\n", thread->name, in mpp_thread_dump_status()
53 thread->thd_status[THREAD_WORK], thread->thd_status[THREAD_INPUT], in mpp_thread_dump_status()
54 thread->thd_status[THREAD_OUTPUT], thread->thd_status[THREAD_CONTROL]); in mpp_thread_dump_status()
57 void mpp_thread_start(MppThread *thread) in mpp_thread_start() argument
64 if (mpp_thread_get_status(thread, THREAD_WORK) == MPP_THREAD_UNINITED) { in mpp_thread_start()
65 mpp_thread_set_status(thread, MPP_THREAD_RUNNING, THREAD_WORK); in mpp_thread_start()
66 if (0 == pthread_create(&thread->thd, &attr, thread->func, thread->ctx)) { in mpp_thread_start()
67 int ret = pthread_setname_np(thread->thd, thread->name); in mpp_thread_start()
69 mpp_err("thread %p setname %s failed\n", thread->func, thread->name); in mpp_thread_start()
72 thread->name, thread->func, thread->ctx); in mpp_thread_start()
74 mpp_thread_set_status(thread, MPP_THREAD_UNINITED, THREAD_WORK); in mpp_thread_start()
81 void mpp_thread_stop(MppThread *thread) in mpp_thread_stop() argument
83 if (mpp_thread_get_status(thread, THREAD_WORK) != MPP_THREAD_UNINITED) { in mpp_thread_stop()
86 mpp_thread_lock(thread, THREAD_WORK); in mpp_thread_stop()
87 mpp_thread_set_status(thread, MPP_THREAD_STOPPING, THREAD_WORK); in mpp_thread_stop()
89 thread_dbg(THREAD_DBG_FUNC, "MPP_THREAD_STOPPING status set thd %p\n", (void *)thread); in mpp_thread_stop()
90 mpp_thread_signal(thread, THREAD_WORK); in mpp_thread_stop()
91 mpp_thread_unlock(thread, THREAD_WORK); in mpp_thread_stop()
93 pthread_join(thread->thd, &dummy); in mpp_thread_stop()
94 …EAD_DBG_FUNC, "thread %s %p context %p destroy success\n", thread->name, thread->func, thread->ctx… in mpp_thread_stop()
96 mpp_thread_set_status(thread, MPP_THREAD_UNINITED, THREAD_WORK); in mpp_thread_stop()
100 void mpp_thread_destroy(MppThread *thread) in mpp_thread_destroy() argument
102 if (thread) { in mpp_thread_destroy()
103 mpp_thread_stop(thread); in mpp_thread_destroy()
104 mpp_free(thread); in mpp_thread_destroy()
243 void mpp_thread_init(MppThread *thread, MppThreadFunc func, void *ctx, const char *name) in mpp_thread_init() argument
245 thread->func = func; in mpp_thread_init()
246 thread->ctx = ctx; in mpp_thread_init()
250 strncpy(thread->name, name, THREAD_NAME_LEN - 1); in mpp_thread_init()
251 thread->name[THREAD_NAME_LEN - 1] = '\0'; in mpp_thread_init()
254 mpp_mutex_cond_init(&thread->mutex_cond[i]); in mpp_thread_init()
255 thread->thd_status[i] = MPP_THREAD_UNINITED; in mpp_thread_init()
259 void mpp_thread_set_status(MppThread *thread, MppThreadStatus status, MppThreadSignalId id) in mpp_thread_set_status() argument
262 thread->thd_status[id] = status; in mpp_thread_set_status()
265 MppThreadStatus mpp_thread_get_status(MppThread *thread, MppThreadSignalId id) in mpp_thread_get_status() argument
268 return thread->thd_status[id]; in mpp_thread_get_status()
271 void mpp_thread_lock(MppThread *thread, MppThreadSignalId id) in mpp_thread_lock() argument
274 mpp_mutex_cond_lock(&thread->mutex_cond[id]); in mpp_thread_lock()
277 void mpp_thread_unlock(MppThread *thread, MppThreadSignalId id) in mpp_thread_unlock() argument
280 mpp_mutex_cond_unlock(&thread->mutex_cond[id]); in mpp_thread_unlock()
283 void mpp_thread_wait(MppThread *thread, MppThreadSignalId id) in mpp_thread_wait() argument
286 MppThreadStatus status = thread->thd_status[id]; in mpp_thread_wait()
287 thread->thd_status[id] = MPP_THREAD_WAITING; in mpp_thread_wait()
288 mpp_mutex_cond_wait(&thread->mutex_cond[id]); in mpp_thread_wait()
290 if (thread->thd_status[id] == MPP_THREAD_WAITING) in mpp_thread_wait()
291 thread->thd_status[id] = status; in mpp_thread_wait()
294 void mpp_thread_signal(MppThread *thread, MppThreadSignalId id) in mpp_thread_signal() argument
297 mpp_mutex_cond_signal(&thread->mutex_cond[id]); in mpp_thread_signal()