Thread.cpp

code format="cpp"
 * 1) include "linuxwrap.h"

//--- // CLASS: Thread //---

Thread::Thread(Thread::ThreadPriority p, std::string nme) : priority(p), name(nme) {	if(geteuid!=0) {		printf("You must have admin rights to use class Thread. Rerun program as root\n"); exit(1); } }

Thread::~Thread { }

void Thread::start {	pthread_attr_t attr; sched_param sched_p;

pthread_attr_init(&attr);										// Init attr pthread_attr_setschedpolicy(&attr, SCHED_RR);					// Set RR scheduling (RT, timesliced) pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED);	// Create thread with explicit (non-inherited) scheduling - setting priority will not work otherwise! sched_p.sched_priority = (int)priority;							// Set priority pthread_attr_setschedparam(&attr, &sched_p);					// Use the priority

pthread_create(&handle, &attr, threadMapper, (void*)this); }

bool Thread::setPriority(Thread::ThreadPriority p) { priority = p;	if(pthread_setschedprio(handle, priority) == 0) return true; else return false; }

DWORD Thread::threadMapper(void* p) { ((Thread*)p)->run; return 0; }

Thread::ThreadPriority Thread::getPriority {	return priority; }

string Thread::getName {	return name; }

code