#include "tc_thread.h"


void tc_thread_init(tc_thread_t* thread, void* (*entry)(void*), void* self)
{
    if (thread)
    {
        pthread_attr_init(&thread->attr);

        // pthread_attr_setdetachstate(&thread->attr, PTHREAD_CREATE_JOINABLE);
        // pthread_attr_setdetachstate(&thread->attr, PTHREAD_CREATE_DETACHED);

        // if (0)
        // {
        //     pthread_attr_setinheritsched(&thread->attr, PTHREAD_EXPLICIT_SCHED);
        //     thread->param.sched_priority = 10;
        //     pthread_attr_setschedparam(&thread->attr, &thread->param);
        //     pthread_attr_setschedpolicy(&thread->attr, SCHED_FIFO);
        //     pthread_attr_setschedpolicy(&thread->attr, SCHED_RR);
        //     struct sched_param param;
        // }else{
        //     //默认模式
        //     pthread_attr_setschedpolicy(&thread->attr, SCHED_OTHER);
        //     pthread_attr_setinheritsched(&thread->attr, PTHREAD_INHERIT_SCHED);
        // }

        pthread_create(&thread->thread_id, &thread->attr, entry, self); 
        thread->entry = entry;
        thread->self = self;
    }
}

void tc_thread_exit(tc_thread_t* thread)
{
    if (thread)
    {
        pthread_join(thread->thread_id, NULL);
        pthread_attr_destroy(&thread->attr);
    }
}