2012-06-13 66 views
1

我正在为x86-64计算机上的Linux编写代码。它在x86-64上完美工作,但我将相同的代码移植到基于ARM的设备,现在我收到错误:定时器代码的无效参数。以下是我的计时器代码:错误的获取无效参数错误(22)

/** 
* FUNCTION NAME : startRetryCount 
* @brief start the retry count 
* @param isAuth: if true start retry for Auth message else for Normal message 
* @return true if success and false if not 
*/ 
bool startRetryCount(bool isAuth) 
{ 
    m_RetryAuth = isAuth; 
    stopRetryCount(); 

    struct sigevent sigev; 
    struct itimerspec itval; 
    struct itimerspec oitval; 
    struct sigaction sigact; 

    if(sigemptyset(&sigact.sa_mask) == -1) 
    { 
     printLog(LOG_ERROR,"[%s:%d#%s] <<<<sigemptyset>>>> : %s\n", 
          __FILE__,__LINE__,__func__,strerror(errno)); 
    } 

    sigact.sa_flags = SA_SIGINFO; 
    sigact.sa_sigaction = signalHandler; 

    m_RetryCount = ConfigureManager_SingleTon::getInstance()->getRetryCount(); 
    printLog(LOG_INFO,"**Retry Count Started**\n"); 
    printLog(LOG_INFO,"Number of Retry Count:%d\n",m_RetryCount); 
    printLog(LOG_INFO,"Retry time is:%d\n", 
      ConfigureManager_SingleTon::getInstance()->getRetryTime()); 

    // set up sigaction to catch signal 
    if (sigaction(SIGTIMER, &sigact, NULL) == -1) 
    { 
     printLog(LOG_ERROR,"[%s:%d#%s] <<<<time_settime>>>> : %s\n", 
          __FILE__,__LINE__,__func__,strerror(errno)); 
     return false; 
    } 

    //Create the POSIX timer to generate signo 
    sigev.sigev_notify = SIGEV_SIGNAL; 
    sigev.sigev_signo = SIGRTMAX; 
    sigev.sigev_value.sival_int = RETRY_ID; 

    if (timer_create(CLOCK_REALTIME, &sigev, &m_RetryTimerId) == 0) 
    { 
     itval.it_value.tv_sec = ConfigureManager_SingleTon::getInstance()->getRetryTime(); 
     itval.it_value.tv_nsec = 0L; 
     itval.it_interval.tv_sec = itval.it_value.tv_sec; 
     itval.it_interval.tv_nsec = itval.it_value.tv_nsec; 

     if (timer_settime(m_RetryTimerId, 0, &itval, &oitval) != 0) 
     { 
      Utility_SingleTon::printLog(LOG_ERROR,"[%s:%d#%s] <<<<time_settime>>>> %s\n", 
           __FILE__, __LINE__,__func__,strerror(errno)); 
      return false; 
     } 
    } 
    else 
    { 
     printLog(LOG_ERROR,"[%s:%d#%s] <<<<timer_create>>>> %s", 
           __FILE__, __LINE__,__func__,strerror(errno)); 
     return false; 
    } 
    return true; 
} 

/** 
* FUNCTION NAME : stopRetryCount 
* @brief stop the retry count 
*/ 
voidstopRetryCount() 
{ 
    if(m_RetryTimerId != NULL) 
    { 
     if(timer_delete(m_RetryTimerId) != 0) 
     { 
      printLog(LOG_ERROR,"[%s:%d#%s] Timer delete error [%d]=%s\n",__FILE__, __LINE__,__func__,errno,strerror(errno)); 
     } 
     m_RetryCount = 0; 
     m_RetryTimerId = NULL; 
     printLog(LOG_INFO,"Retry Timer Stopped!\n"); 
    } 
} 

打印日志:

[src/manager.cpp:686#stopRetryCount] Timer delete error [22]=Invalid argument 

我已经尝试了很多发现是什么在困扰基于ARM的设备,但不幸的是我没有能够解决的问题。任何帮助将不胜感激。

编辑:

为了模拟我的病情,我已经创建示例程序,现在我才知道,在米斯特拉尔SAM-9处理器,定时器和线程结合起来不工作,如果我开始在主线程计时器和如果我试图通过子线程停止该计时器,那么它会给出该错误。这里是sample.cpp的文件来源:

#include "devicetimer.h" 


int DeviceTimer::counter = 0; 

timer_t DeviceTimer::testTimer1Id = 0; 

void DeviceTimer::timer1Stop() 
{ 

    if(testTimer1Id != 0) 
    { 
     if(timer_delete(testTimer1Id) == -1) 
     { 
      printf("Timer Delete Error\nError Number = %d\nError Message = %s\n",errno,strerror(errno)); 
      exit(1); 
     } 
     else 
     { 
      printf("Timer Delete Successfully\n"); 
     }  
    } 
} 

void DeviceTimer::signalHandler(int signo, siginfo_t* info, void* context) 
{ 
    if (signo == SIGTIMER) 
    { 
     printf("counter %d\n\n",++counter); 
    } 
} 

int DeviceTimer::timer1start() 
{ 
    struct sigevent sigev; //signal event struct 
    struct itimerspec itval; 
    struct itimerspec oitval; 
    struct sigaction sigact; 


    sigemptyset(&sigact.sa_mask); 
    sigact.sa_flags = SA_SIGINFO; 
    sigact.sa_sigaction = signalHandler; 

    // set up sigaction to catch signal 
    if (sigaction(SIGTIMER, &sigact, NULL) == -1) 
    { 
     printf("time_settime error \n"); 
     return -1; 
    } 

    //Create the POSIX timer to generate signo 
    sigev.sigev_notify = SIGEV_SIGNAL; 
    sigev.sigev_signo = SIGTIMER; 
    sigev.sigev_value.sival_int = 2; 

    if (timer_create(CLOCK_REALTIME, &sigev, &testTimer1Id) == 0) 
    { 
     itval.it_value.tv_sec = 1; 
     itval.it_value.tv_nsec = 0L; 
     itval.it_interval.tv_sec = itval.it_value.tv_sec; 
     itval.it_interval.tv_nsec = itval.it_value.tv_nsec; 

     if (timer_settime(testTimer1Id, 0, &itval, &oitval) != 0) 
     { 
      printf("Error in set time \n"); 
      return -2; 
     } 
    } 
    else 
    { 
     printf("Error in creating timer \n"); 
     return -3; 
    } 
    return 0; 
} 


void* DeviceTimer::threadFunction(void* data) 
{ 
    DeviceTimer *deviceTimer = (DeviceTimer *) data; 

    while(1) 
    { 
     printf(".\n"); 
     usleep(100000); 
     if(counter > 25) 
     { 
      deviceTimer->timer1Stop(); 
      break; 
     } 
    } 
    return NULL; 
} 


void DeviceTimer::startThread() 
{ 
    if(pthread_create(&m_Thread, NULL, DeviceTimer::threadFunction, this) != 0) 
    { 
     printf("Error in creating Thread\n"); 
     exit(1); 
    } 
} 

int main() 
{ 
    DeviceTimer deviceTimer; 

    deviceTimer.timer1start(); 
    deviceTimer.startThread(); 

    while(1) 
    { 
    } 

    return 0; 
} 

而且下面是输出:

counter 26 
Timer Delete Error 
Error Number = 22 
Error Message = Invalid argument 

如果有人experinced同样的问题的话,请帮我解决这个问题。

感谢& BR, Yuvi

+1

由于有很多地方你可以得到错误,你能告诉_系统调用哪个给出了错误? –

+1

哦..我忘了补充一点,我在delete_timer()和close()中出错。 – Yuvi

+0

更新代码相同 – Yuvi

回答

1

确保您的计时器ID是正确的类型(timer_t)。如果您意外地使用其他类型,则可能会发生类似这样的错误,因为timer_delete()无法识别该ID。

+1

这里是我的声明'timer_t m_RetryTimerId; //重试计时器ID timer' – Yuvi

+0

你能告诉我什么可能是其中delete_timer可以抛出'无效参数Error' – Yuvi

+0

你能告诉这可能是原因,这个代码是另一种情况在Linux x86-64上工作,但不能在arm机器上...... – Yuvi

相关问题