|
Packit Service |
310c69 |
/*
|
|
Packit Service |
310c69 |
* Copyright (c) 2020 Red Hat, Inc.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is free software; you can redistribute it and/or
|
|
Packit Service |
310c69 |
* modify it under the terms of the GNU General Public License
|
|
Packit Service |
310c69 |
* as published by the Free Software Foundation; either version 2
|
|
Packit Service |
310c69 |
* of the License, or (at your option) any later version.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* This program is distributed in the hope that it will be useful,
|
|
Packit Service |
310c69 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
310c69 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
310c69 |
* GNU General Public License for more details.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* You should have received a copy of the GNU General Public License
|
|
Packit Service |
310c69 |
* along with this program; if not, write to the Free Software
|
|
Packit Service |
310c69 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
Packit Service |
310c69 |
* 02110-1301, USA.
|
|
Packit Service |
310c69 |
*
|
|
Packit Service |
310c69 |
* $Id: //eng/uds-releases/jasper/kernelLinux/uds/threadCondVarLinuxKernel.c#2 $
|
|
Packit Service |
310c69 |
*/
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
#include "threads.h"
|
|
Packit Service |
310c69 |
#include "timeUtils.h"
|
|
Packit Service |
310c69 |
#include "uds-error.h"
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int initCond(CondVar *cv)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
cv->eventCount = NULL;
|
|
Packit Service |
310c69 |
return makeEventCount(&cv->eventCount);
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int signalCond(CondVar *cv)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
eventCountBroadcast(cv->eventCount);
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int broadcastCond(CondVar *cv)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
eventCountBroadcast(cv->eventCount);
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int waitCond(CondVar *cv, Mutex *mutex)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
EventToken token = eventCountPrepare(cv->eventCount);
|
|
Packit Service |
310c69 |
unlockMutex(mutex);
|
|
Packit Service |
310c69 |
eventCountWait(cv->eventCount, token, NULL);
|
|
Packit Service |
310c69 |
lockMutex(mutex);
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int timedWaitCond(CondVar *cv, Mutex *mutex, RelTime timeout)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
EventToken token = eventCountPrepare(cv->eventCount);
|
|
Packit Service |
310c69 |
unlockMutex(mutex);
|
|
Packit Service |
310c69 |
bool happened = eventCountWait(cv->eventCount, token, &timeout);
|
|
Packit Service |
310c69 |
lockMutex(mutex);
|
|
Packit Service |
310c69 |
return happened ? UDS_SUCCESS : ETIMEDOUT;
|
|
Packit Service |
310c69 |
}
|
|
Packit Service |
310c69 |
|
|
Packit Service |
310c69 |
/**********************************************************************/
|
|
Packit Service |
310c69 |
int destroyCond(CondVar *cv)
|
|
Packit Service |
310c69 |
{
|
|
Packit Service |
310c69 |
freeEventCount(cv->eventCount);
|
|
Packit Service |
310c69 |
cv->eventCount = NULL;
|
|
Packit Service |
310c69 |
return UDS_SUCCESS;
|
|
Packit Service |
310c69 |
}
|