rpi-rgb-led-matrix/thread.cc
Henner Zeller 2d3cc5d517 o emacs mode headers.
o support for 16x32 displays.
2014-09-03 21:12:00 -07:00

34 lines
769 B
C++

// -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
#include "thread.h"
#include <sched.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
void *Thread::PthreadCallRun(void *tobject) {
reinterpret_cast<Thread*>(tobject)->Run();
return NULL;
}
Thread::Thread() : started_(false) {}
Thread::~Thread() {
if (!started_) return;
int result = pthread_join(thread_, NULL);
if (result != 0) {
fprintf(stderr, "err code: %d %s\n", result, strerror(result));
}
}
void Thread::Start(int priority) {
assert(!started_);
pthread_create(&thread_, NULL, &PthreadCallRun, this);
if (priority > 0) {
struct sched_param p;
p.sched_priority = priority;
pthread_setschedparam(thread_, SCHED_FIFO, &p);
}
started_ = true;
}