ts-7000
[Top] [All Lists]

[ts-7000] Re: Trying to encapsulate thread in class

To:
Subject: [ts-7000] Re: Trying to encapsulate thread in class
From: "Richard" <>
Date: Tue, 22 Jan 2008 21:32:53 -0000
--- In  "Keith Engell" <> wrote:
>
> Finally!  A question I can answer! :-)
> 
> This is a classic problem in OOP.  I would recommend the following 
changes.
> 
> // watchdogcontrol.h
> class WatchdogControl
> {
>   ...
> private:
>     static void* resetWatchdog(void* arg);
> ...
> };
> 
> // watchdogcontrol.cpp
> void WatchdogControl::startWatchdogMonitor()
> {
>   if (!WatchdogTimerOn);  // why this statement?
>   pthread_t WatchdogMonitorId;
>   pthread_create (&WatchdogMonitorId, NULL,
> &WatchdogControl::resetWatchdog, this);
>   WatchdogTimerOn = true;
> }
> static void* WatchdogControl::resetWatchdog(void* arg)
> {
>   sleep(300);
>   WatchdogControl* pThis = static_cast<WatchdogControl*>(arg);
>   pThis->setWatchdogTimer();
>   return NULL;
> }
> 
> Hope this helps.
> 
> Keith Engell
> 
> On Jan 22, 2008 1:34 AM, Richard <> wrote:
> >
> >
> >
> >
> >
> >
> > Ok here is my source code, the first section is the 
implementation,
> >  the second section is the declaration, and the third is the 
compiler
> >  error. Any help on this would be appreciated.
> >
> >  /********************** Implementation **********************/
> >  #include "WatchdogControl.h"
> >  //Class Constructor, currently being used to set the default 
timer
> >  watchdog.
> >  WatchdogControl::WatchdogControl()
> >  {
> >  timerValue = 0x07;
> >  }
> >
> >  WatchdogControl::~WatchdogControl()
> >  {
> >  }
> >
> >  void WatchdogControl::startWatchdogMonitor()
> >  {
> >  if (!WatchdogTimerOn);
> >  pthread_t WatchdogMonitorId;
> >  pthread_create (&WatchdogMonitorId, NULL, &resetWatchdog, NULL);
> >  WatchdogTimerOn = true;
> >  }
> >
> >  void* WatchdogControl::resetWatchdog(void* nothing)
> >  {
> >  sleep(300);
> >  setWatchdogTimer();
> >  return NULL;
> >  }
> >
> >  void WatchdogControl::setWatchdogTimer()
> >  {
> >  int fd = open("/dev/mem", O_RDWR);
> >  assert(fd != -1);
> >
> >  wdt_control = (unsigned char
> >  *)mmap(0,getpagesize
(),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0x23800000);
> >  wdt_feed = (unsigned char
> >  *)mmap(0,getpagesize
(),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0x23C00000);
> >
> >  *wdt_feed = WATCHDOG_FEED_BYTE;
> >  *wdt_control = timerValue;
> >  }
> >
> >  /********************** Declaration **********************/
> >  #ifndef WATCHDOGCONTROL_H_
> >  #define WATCHDOGCONTROL_H_
> >
> >  //Classs Include Files
> >  #include<unistd.h>
> >  #include<sys/types.h>
> >  #include<sys/mman.h>
> >  #include<fcntl.h>
> >  #include<assert.h>
> >  #include <pthread.h>
> >
> >  //Class Definitions
> >  #define WATCHDOG_FEED_BYTE 0x05
> >
> >  //Class Declaration
> >  class WatchdogControl
> >  {
> >  public:
> >  //Public Class Variables
> >
> >  //Public Class Functions
> >  WatchdogControl();
> >  virtual ~WatchdogControl();
> >  void startWatchdogMonitor();
> >
> >
> >  private:
> >  //Private Class Variables
> >  volatile unsigned char *wdt_control;
> >  volatile unsigned char *wdt_feed;
> >  int timerValue;
> >  bool WatchdogTimerOn;
> >
> >  //Private Class Functions
> >  void* resetWatchdog(void* nothing);
> >  void setWatchdogTimer();
> >
> >  };
> >
> >  #endif /*WATCHDOGCONTROL_H_*/
> >
> >  /********************** Error **********************/
> >  Severity and Description Path Resource Location Creation Time Id
> >  error: cannot convert 'void* (WatchdogControl::*)(void*)' 
to 'void*
> >  (*)(void*)' for argument '3' to 'int pthread_create(pthread_t*, 
const
> >  pthread_attr_t*, void* (*)(void*), void*)' rbash/WatchdogControl
> >  WatchdogControl.cpp line 16 1200986943638 391
> >
> >
>


Tried this, for some reason the C++ compiler does notlike declaring 
this variable as a static variable.  Someone told me to try this:

pthread_create (&WatchdogMonitorId, NULL, &(this->resetWatchdog), 
NULL);
>From what i undestand about the nature of the error the compiler may 
be having problems becasue the class might not be thread safe.  I am 
not sure why this is an issue i have a flag to manage the thread.  
This is a lot different then treads in borland :( the down side to 
having borland do all the dirty work for you is that when you have to 
do it you dont know how to lol.

Richard



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ts-7000/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ts-7000/join
    (Yahoo! ID required)

<*> To change settings via email:
     
    

<*> To unsubscribe from this group, send an email to:
    

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

<Prev in Thread] Current Thread [Next in Thread>
Admin

Disclaimer: Neither Andrew Taylor nor the University of NSW School of Computer and Engineering take any responsibility for the contents of this archive. It is purely a compilation of material sent by many people to the birding-aus mailing list. It has not been checked for accuracy nor its content verified in any way. If you wish to get material removed from the archive or have other queries about the archive e-mail Andrew Taylor at this address: andrewt@cse.unsw.EDU.AU