Lines Matching refs:thd
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()
93 pthread_join(thread->thd, &dummy); in mpp_thread_stop()
305 pthread_t thd; member
333 static rk_s32 check_sthd(const char *name, MppSThdImpl *thd) in check_sthd() argument
335 if (!thd) { in check_sthd()
340 if (thd->ctx.thd != thd) { in check_sthd()
341 mpp_err("mpp_sthd check %p:%p mismatch at %s\n", thd->ctx.thd, thd, name); in check_sthd()
348 #define CHECK_STHD(thd) check_sthd(__FUNCTION__, (MppSThdImpl *)(thd)) argument
350 static void mpp_sthd_init(MppSThdImpl *thd, rk_s32 idx) in mpp_sthd_init() argument
356 pthread_mutex_init(&thd->lock, &attr); in mpp_sthd_init()
359 pthread_cond_init(&thd->cond, NULL); in mpp_sthd_init()
360 thd->ctx.thd = thd; in mpp_sthd_init()
361 thd->idx = idx; in mpp_sthd_init()
364 static void mpp_sthd_deinit(MppSThdImpl *thd) in mpp_sthd_deinit() argument
366 mpp_assert(thd->ctx.thd == thd); in mpp_sthd_deinit()
367 mpp_assert(thd->status < MPP_STHD_RUNNING); in mpp_sthd_deinit()
369 pthread_mutex_lock(&thd->lock); in mpp_sthd_deinit()
370 thd->status = MPP_STHD_UNINITED; in mpp_sthd_deinit()
371 thd->ctx.thd = NULL; in mpp_sthd_deinit()
372 pthread_mutex_unlock(&thd->lock); in mpp_sthd_deinit()
374 pthread_cond_destroy(&thd->cond); in mpp_sthd_deinit()
375 pthread_mutex_destroy(&thd->lock); in mpp_sthd_deinit()
378 static MPP_RET mpp_sthd_create(MppSThdImpl *thd) in mpp_sthd_create() argument
383 mpp_assert(thd->ctx.thd == thd); in mpp_sthd_create()
384 mpp_assert(thd->status < MPP_STHD_RUNNING); in mpp_sthd_create()
390 thd->status = MPP_STHD_RUNNING; in mpp_sthd_create()
391 if (0 == pthread_create(&thd->thd, &attr, (MppThreadFunc)thd->func, &thd->ctx)) { in mpp_sthd_create()
392 ret = (MPP_RET)pthread_setname_np(thd->thd, thd->name); in mpp_sthd_create()
394 mpp_err("%s %p setname failed\n", thd->thd, thd->func); in mpp_sthd_create()
397 thd->name, thd->func, thd->ctx.ctx); in mpp_sthd_create()
400 thd->status = MPP_STHD_READY; in mpp_sthd_create()
411 MppSThdImpl *thd = mpp_calloc_size(MppSThdImpl, size); in mpp_sthd_get() local
413 if (!thd) { in mpp_sthd_get()
418 thd->name = (char *)(thd + 1); in mpp_sthd_get()
422 snprintf(thd->name, THREAD_NAME_LEN - 1, "%s", name); in mpp_sthd_get()
424 mpp_sthd_init(thd, -1); in mpp_sthd_get()
426 return thd; in mpp_sthd_get()
429 void mpp_sthd_put(MppSThd thd) in mpp_sthd_put() argument
431 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_put()
434 mpp_assert(impl->ctx.thd == impl); in mpp_sthd_put()
442 MppSThdStatus mpp_sthd_get_status(MppSThd thd) in mpp_sthd_get_status() argument
444 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_get_status()
451 const char* mpp_sthd_get_name(MppSThd thd) in mpp_sthd_get_name() argument
453 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_get_name()
460 rk_s32 mpp_sthd_get_idx(MppSThd thd) in mpp_sthd_get_idx() argument
462 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_get_idx()
469 rk_s32 mpp_sthd_check(MppSThd thd) in mpp_sthd_check() argument
471 return CHECK_STHD(thd); in mpp_sthd_check()
474 void mpp_sthd_setup(MppSThd thd, MppSThdFunc func, void *ctx) in mpp_sthd_setup() argument
476 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_setup()
499 void mpp_sthd_start(MppSThd thd) in mpp_sthd_start() argument
501 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_start()
522 void mpp_sthd_stop(MppSThd thd) in mpp_sthd_stop() argument
524 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_stop()
546 void mpp_sthd_stop_sync(MppSThd thd) in mpp_sthd_stop_sync() argument
548 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_stop_sync()
559 pthread_join(impl->thd, &dummy); in mpp_sthd_stop_sync()
571 void mpp_sthd_lock(MppSThd thd) in mpp_sthd_lock() argument
573 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_lock()
580 void mpp_sthd_unlock(MppSThd thd) in mpp_sthd_unlock() argument
582 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_unlock()
589 int mpp_sthd_trylock(MppSThd thd) in mpp_sthd_trylock() argument
591 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_trylock()
598 void mpp_sthd_wait(MppSThd thd) in mpp_sthd_wait() argument
600 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_wait()
613 void mpp_sthd_signal(MppSThd thd) in mpp_sthd_signal() argument
615 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_signal()
622 void mpp_sthd_broadcast(MppSThd thd) in mpp_sthd_broadcast() argument
624 MppSThdImpl *impl = (MppSThdImpl *)thd; in mpp_sthd_broadcast()
651 MppSThdImpl *thd = &grp->thds[i]; in mpp_sthd_grp_get() local
653 thd->name = grp->name; in mpp_sthd_grp_get()
654 mpp_sthd_init(thd, i); in mpp_sthd_grp_get()
679 MppSThdImpl *thd = &impl->thds[i]; in mpp_sthd_grp_put() local
681 mpp_sthd_deinit(thd); in mpp_sthd_grp_put()
703 MppSThdImpl *thd = &impl->thds[i]; in mpp_sthd_grp_setup() local
705 thd->func = func; in mpp_sthd_grp_setup()
706 thd->ctx.ctx = ctx; in mpp_sthd_grp_setup()
707 thd->status = next; in mpp_sthd_grp_setup()
762 MppSThdImpl *thd = &impl->thds[i]; in mpp_sthd_grp_stop() local
764 pthread_mutex_lock(&thd->lock); in mpp_sthd_grp_stop()
765 thd->status = MPP_STHD_STOPPING; in mpp_sthd_grp_stop()
766 pthread_cond_signal(&thd->cond); in mpp_sthd_grp_stop()
767 pthread_mutex_unlock(&thd->lock); in mpp_sthd_grp_stop()
794 MppSThdImpl *thd = &impl->thds[i]; in mpp_sthd_grp_stop_sync() local
796 pthread_join(thd->thd, &dummy); in mpp_sthd_grp_stop_sync()
797 thd->status = MPP_STHD_READY; in mpp_sthd_grp_stop_sync()