Ales Lacen(deleted)
|
pthread_cond_timewait returns errorcode EBUSY
|
Ales Lacen(deleted)
08/13/2010 2:44 AM
post62906
|
pthread_cond_timewait returns errorcode EBUSY
Hello,
I have some applications, which return at call of pthread_cond_timewait the errorcode 16 (EBUSY).
In the manual its written, that this errorcode is for this function not possible.
The case is, when I call pthread_cond_wait() instead of pthread_cond_timewait() than everything is fine.
So I would think, the condition variable and mutex variable, would be passed wright.
And the third parameter (abstime) I exemined by call of pthread_cond_timewait looks well either.
Could anyone give me tip?
here the code snipped:
static OS_ErrorCode os_waitForCondition(OS_Event* ev, OS_NanoSec durationTime)
{
//neu:
pthread_mutex_lock(&waitMutexLock);
volatile int err;
struct timespec spec;
OS_NanoSec targetTime;
if (!ev)
{
tPrintf(TRC_FAULT | TRC_COSA, "%s: Invalid parameter", __FUNCTION__);
//neu:
pthread_mutex_unlock(&waitMutexLock);
return OS_InvalidParam;
}
pthread_mutex_lock((pthread_mutex_t*) &(ev->mutex));
if (ev->signaled)
{
if (!ev->manualReset)
ev->signaled = OS_FALSE;
pthread_mutex_unlock(&ev->mutex);
//neu:
pthread_mutex_unlock(&waitMutexLock);
return OS_Success;
}
if (durationTime != OS_INFINITE)
{
OS_ErrorCode r = os_getCurrentTime(&targetTime);
if (r != OS_Success)
{
pthread_mutex_unlock(&ev->mutex);
//neu:
pthread_mutex_unlock(&waitMutexLock);
return r;
}
targetTime += durationTime;
if(targetTime > 1000000000ULL)
spec.tv_sec = /*(time_t)*/ (targetTime / 1000000000ULL);
else
spec.tv_sec = 0;
spec.tv_nsec = (long) (targetTime % 1000000000ULL);
/* clock_gettime(CLOCK_REALTIME, &spec);
spec.tv_sec += 5;
spec.tv_nsec = 0;
*/
err = pthread_cond_timedwait((pthread_cond_t *)&(ev->cond), (pthread_mutex_t *)&(ev->mutex), (const struct timespec*)&spec);
}
else
err = pthread_cond_wait(&ev->cond, &ev->mutex);
switch (err)
{
case 0:
if (!ev->manualReset)
ev->signaled = OS_FALSE;
pthread_mutex_unlock((pthread_mutex_t*) &ev->mutex);
//neu:
pthread_mutex_unlock(&waitMutexLock);
return OS_Success;//signaled!
case ETIMEDOUT:
pthread_mutex_unlock((pthread_mutex_t*) &ev->mutex);
//neu:
pthread_mutex_unlock(&waitMutexLock);
return OS_Timeout;
default:
tError(TRC_FAULT | TRC_COSA, err, "%s", __FUNCTION__);
break;
}
pthread_mutex_unlock((pthread_mutex_t*) &ev->mutex);
//neu:
pthread_mutex_unlock(&waitMutexLock);
return OS_Error;
}
With best regards
|
|
|