Something went wrong. Try again.
a less like pager but for fun
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162#include "shared.h"
pthread_t tid_key, tid_draw, tid_auto;
pthread_mutex_t queue_lock;pthread_cond_t queue_cond;
// Argument arg should be a pointer to key_info// which c1 being file context// and c2 being help contextvoid *Tkey(void *arg) { key_info *ki = (key_info*) arg; handle_keys(ki->win, ki->c1, ki->c2); // we need to leave return NULL;}
// arg empty fornowvoid *Tdraw(void *arg) { (void) arg; while (1) { if(!consume_queue()) return NULL; }}
void *Tauto(void *arg) { (void) arg; do { queue_autopaging(); // maybe passing NULL is better for 1ord arg nanosleep(&FLAGS.autopaging_ts, &FLAGS.autopaging_ts); } while (FLAGS.autopaging); return NULL;}
void start_auto_paging() { pthread_create(&tid_auto, NULL, Tauto, NULL); pthread_setname_np(tid_draw, "Tauto");}
void start_threads(key_info ki) { pthread_mutex_init(&queue_lock, NULL); pthread_cond_init(&queue_cond, NULL);
init_draw_queue();
pthread_create(&tid_key, NULL, Tkey, (void *) &ki); pthread_create(&tid_draw, NULL, Tdraw, NULL);
pthread_setname_np(tid_key, "Tkey"); pthread_setname_np(tid_draw, "Tdraw");
if (FLAGS.autopaging) start_auto_paging();
pthread_join(tid_key, NULL); pthread_join(tid_draw, NULL); if (tid_auto != 0) pthread_join(tid_auto, NULL);
pthread_mutex_destroy(&queue_lock); pthread_cond_destroy(&queue_cond);}