int thread_create(thread_id_t *tid, const char *name, void (*entry)(uint32_t), uint32_t arg) { struct thread_context *tc = malloc(sizeof(struct thread_context)); if (!tc) return -E_NO_MEM; memset(tc, 0, sizeof(struct thread_context)); thread_set_name(tc, name); tc->tc_tid = alloc_tid(); tc->tc_stack_bottom = malloc(stack_size); if (!tc->tc_stack_bottom) { free(tc); return -E_NO_MEM; } void *stacktop = tc->tc_stack_bottom + stack_size; // Terminate stack unwinding stacktop = stacktop - 4; memset(stacktop, 0, 4); memset(&tc->tc_jb, 0, sizeof(tc->tc_jb)); tc->tc_jb.jb_esp = (uint32_t)stacktop; tc->tc_jb.jb_eip = (uint32_t)&thread_entry; tc->tc_entry = entry; tc->tc_arg = arg; threadq_push(&thread_queue, tc); if (tid) *tid = tc->tc_tid; return 0; }
void _socket_set_loop_name(struct socket_t* s, const char* name) { if (s->name != NULL) { size_t len = strlen(s->name) + strlen(name) + 4; char t_name[len]; sprintf(t_name, "%s - %s", s->name, name); thread_set_name(t_name); } }
void _rtp_recorder_synchronization_loop(void* ctx) { thread_set_name("Synchronization loop"); struct rtp_recorder_t* rr = (struct rtp_recorder_t*)ctx; mutex_lock(rr->timer_mutex); while (condition_times_wait(rr->timer_cond, rr->timer_mutex, 2000)) _rtp_recorder_send_timing_request(rr); mutex_unlock(rr->timer_mutex); }