ok here is the code that I'm using but I cannot see the error in
it ..thank for any help..
the base class for my event
class Lock
{
private:
int _ret;
protected:
pthread_mutex_t _m_mutex;
pthread_mutexattr_t _attr;
// Prevent copying or assignment
Lock(const Lock& _arg);
Lock& operator=(const Lock& _rhs);
public:
Lock(){
_ret = pthread_mutexattr_init(&_attr);
_ret = pthread_mutexattr_settype
(&_attr, PTHREAD_MUTEX_NORMAL);
_ret = pthread_mutex_init
(&_m_mutex,&_attr);
if(_ret != 0) throw "Error";
}
~Lock(){
pthread_mutex_destroy(&_m_mutex);
pthread_mutexattr_destroy(&_attr);
}
int lock(){
_ret = pthread_mutex_lock(&_m_mutex);
return _ret;
}
int unlock(){
_ret = pthread_mutex_unlock(&_m_mutex);
return _ret;
}
};
below is my event class..
class CEvent : public Lock
{
private:
struct timespec _ts;
struct timeval _tp;
int _ret;
protected:
pthread_cond_t _event_id;
pthread_condattr_t cattr;
// Prevent copying or assignment
CEvent(const CEvent& _arg);
CEvent& operator=(const CEvent& _rhs);
public:
CEvent(){
pthread_condattr_init(&cattr);
_ret = pthread_condattr_setclock(&cattr,
CLOCK_MONOTONIC);
pthread_cond_init(&_event_id,&cattr);
}
~CEvent(){
pthread_condattr_destroy(&cattr);
pthread_cond_destroy(&_event_id);
}
int wait(){
lock();
_ret = pthread_cond_wait(&_event_id, &_m_mutex);
unlock();
return _ret;
}
int wait_timeout(int delay)
{
struct timespec ts;
clock_gettime(CLOCK_MONOTONIC,&ts);
ts.tv_sec += delay;
lock();
_ret = pthread_cond_timedwait(&_event_id, &_m_mutex, &ts);
unlock();
return _ret;
}
int notify(){
_ret = pthread_cond_signal(&_event_id);
return _ret;
}
};
this is my msg queue..
struct gLog_queue
{
public:
void addMsg(LOGMSG *msg) {
_result = _m_Event.lock();
_queue.push_back(_msg);
_result = _m_Event.notify();
_result = _m_Event.unlock();
}
LOGMSG *getMsg() {
_msg = NULL;
_result = _m_Event.lock();
if(_queue.size() != 0)
{
_msg = _queue.front();
_queue.pop_front();
}
_result = _m_Event.unlock();
return _msg;
}
int wait_for_msg_time(int delay){return _result =
_m_Event.wait_timeout(delay);}
int wait_for_msg(){return _result = _m_Event.wait();}
int getResult(){return _result;}
private:
CEvent _m_Event;
unsigned int _count;
pthread_t _thread_id;
std::list<LOGMSG* > _queue;
int _result;
LOGMSG* _msg;
};
this is the definition for the log queue
extern struct gLog_queue app_log_queue;
and this is my call that return EPERM..
ret = app_log_queue.wait_for_msg_time(delay);
Ps: the wait for message work wait_for_msg_time() it he
wait_for_msg_time_time() does not work..
Thanks again for any help
ephlodur.