The Class I'm currently writing should do the following:
Setting up a POSX timer (OK), setting up a signal-handler function (OK) which calls a member function and therefore uses the this-pointer (not OK).
As you can see in the function setUp(), I store the this-pointer into the sigev_value to pass it to the signal-handler function.Code:void Scheduler::setUp() { // interval occurrence this->timerSpecs.it_interval.tv_sec = 0; this->timerSpecs.it_interval.tv_nsec = HARDCODEDSCHINTERVALL; // First occurrence this->timerSpecs.it_value.tv_sec = 0; this->timerSpecs.it_value.tv_nsec = HARDCODEDSCHINTERVALL; // Define sigaction method this->SignalAction.sa_sigaction = Scheduler::tic; // the static signal handler function // set mask empty -> react on all signals sigemptyset(&this->SignalAction.sa_mask); this->SignalAction.sa_flags = SA_SIGINFO; // Define sigEvent this->signalEvent.sigev_value.sival_ptr = this; if (timer_create(CLOCK_REALTIME, NULL /*&this->signalEvent*/, &this->timerID) != 0) { // timer id koennte mit private probleme geben // TODO: throw Exception exit(1); } // install tic as signal handler if (sigaction(SIGALRM, &this->SignalAction, NULL)) { perror("Could not install new signal handler"); } } // Class layout class Scheduler { public: Scheduler(); virtual ~Scheduler(); timer_t timerID; sigset_t SigBlockSet; struct sigevent signalEvent; struct sigaction SignalAction; struct itimerspec timerSpecs; typedef pair<int, InfClockListener&> wakeUpCandidate; /** * Vector containing the Input Devices which want to be waken up */ vector<wakeUpCandidate *> wakeUpCandidates; int debug; /** * Add an InputDevice to the scheduler * @param interval Read-Out Intervall in Hz (n/seconde) * @param listener The reference to the input object */ void wakeMeUp(int interval, InfClockListener& listener); private: /** * Smallest possible time event RT. * Fired by the SIGALRM due timer stop * Checks the wakeUpCadidates and fires them up. */ static void tic(int sigNumb, siginfo_t *si, void *uc); /** * Prepares all necessary stuff (timer, blocking set usw.) */ void setUp(); };
This function looks like this:
Now the problem starts: During the signal-handler function I can us the passed pointer to access member function in the class Scheduler. That confuses me, because the pointer to the Scheduler Object is not the same at is was during the signal setupUp() function. Although I can access member of the class Scheduler through this new pointer but all I get are wrong random values.Code:void Scheduler::tic(int sigNumb, siginfo_t *si, void *uc) { core::Scheduler * ptrScheduler = reinterpret_cast<Scheduler *> (si->si_value.sival_ptr); // points to something other than I stored! int debugInt; debugInt = ptrScheduler->debug; // contains the wrong value stored in a public member variable debugInt= ptrScheduler->wakeUpCandidates.size(); // returns the incorrect size 3931200 }
Where gets the si->si_value.sival_ptr changed? What I'm doing wrong?
thanks for your help.



LinkBack URL
About LinkBacks



