|
|

|
Listing 4: pp_flip.c
pthread_t pp_thread;
// our periodic thread
void *pp_thread_ep(void *rate) {
static int nState = 0;
// make this realtime thread periodic
pthread_make_periodic_np(pthread_self(),gethrtime(),FRAME_PERIOD_NS);
// this loop wakes up once per period
while (1)
{
if (nState) outb(nStateý, LPT1_DATA); else outb(nState++,LPT1_DATA);
// wait until next period of time
pthread_wait_np();
}
}
int init_module(void) {
pthread_attr_t attrib;
struct sched_param sched_param;
// output string to /var/log/kern.log
printk(ýinit_module pp_flip\ný);
// prepare periodic thread for creation
// initialize thread attributes
sched_param.sched_priority = sched_get_priority_max(SCHED_FIFO);
// obtain highest priority
pthread_attr_init(&attrib);
// set our priority
pthread_attr_setschedparam(&attrib, &sched_param);
// and finally create the thread
pthread_create(&pp_thread, &attrib, pp_thread_ep, (void *)0);
return 0;
}
int cleanup_module(void) {
printk(ýcleanup_module pp_flip\ný);
pthread_delete_np(pp_thread); // kill the thread
return 0;
}
Return to article
|
|
|
Ready to take that job and shove it?
|
|