linxu 线程创建

例1:

static struct task_struct *pmic_thread_handle = NULL;

pmic_thread_handle = kthread_create(pmic_thread_kthread, (void *) NULL, "pmic_thread_kthread");

 if (IS_ERR(pmic_thread_handle)) 
 {
        pmic_thread_handle = NULL;
        xlog_printk(ANDROID_LOG_INFO, "Power/PMIC", "[pmic_thread_kthread] creation fails\n");        
  }
  else
  {
        wake_up_process(pmic_thread_handle);
        xlog_printk(ANDROID_LOG_INFO, "Power/PMIC", "[pmic_thread_kthread] kthread_create Done\n");
  }

static int pmic_thread_kthread(void *x)

{

. . . . . . 

struct sched_param param = { .sched_priority = 98 };

 sched_setscheduler(current, SCHED_FIFO, &param);
    set_current_state(TASK_INTERRUPTIBLE);

while(1)

{

........

set_current_state(TASK_INTERRUPTIBLE);

    schedule();

}

}

void mt6323_pmic_eint_irq(void)
{
  . . . . . .
    wake_up_pmic();
    return ;
}

void wake_up_pmic(void)
{
  . . . . . .
      wake_up_process(pmic_thread_handle);
}


例2:

kthread_run(bat_thread_kthread, NULL, "bat_thread_kthread");

int bat_thread_kthread(void *x)

{

. . . . . .

}


你可能感兴趣的:(linxu 线程创建)