1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/**************************************************************************\
*
* This file is part of the Coin 3D visualization library.
* Copyright (C) by Kongsberg Oil & Gas Technologies.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* ("GPL") version 2 as published by the Free Software Foundation.
* See the file LICENSE.GPL at the root directory of this source
* distribution for additional information about the GNU GPL.
*
* For using Coin with software that can not be combined with the GNU
* GPL, and for taking advantage of the additional benefits of our
* support services, please contact Kongsberg Oil & Gas Technologies
* about acquiring a Coin Professional Edition License.
*
* See http://www.coin3d.org/ for more information.
*
* Kongsberg Oil & Gas Technologies, Bygdoy Alle 5, 0257 Oslo, NORWAY.
* http://www.sim.no/ sales@sim.no coin-support@coin3d.org
*
\**************************************************************************/
#include <Inventor/C/threads/condvar.h>
#include <stdlib.h>
#include <assert.h>
#include <errno.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif /* HAVE_SYS_TIME_H */
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif /* HAVE_UNISTD_H */
#include <Inventor/C/threads/mutex.h>
#include <Inventor/C/errors/debugerror.h>
#include "threads/condvarp.h"
/* ********************************************************************** */
#ifdef USE_PTHREAD
#include "condvar_pthread.icc"
#endif /* USE_PTHREAD */
#ifdef USE_W32THREAD
#include "condvar_win32.icc"
#endif /* USE_W32THREAD */
/*
\internal
*/
void
cc_condvar_struct_init(cc_condvar * condvar_struct)
{
int ok;
ok = internal_condvar_struct_init(condvar_struct);
assert(ok == CC_OK);
}
/*
\internal
*/
void
cc_condvar_struct_clean(cc_condvar * condvar_struct)
{
int ok;
assert(condvar_struct != NULL);
ok = internal_condvar_struct_clean(condvar_struct);
assert(ok == CC_OK);
}
/* ********************************************************************** */
/*
*/
cc_condvar *
cc_condvar_construct(void)
{
cc_condvar * condvar;
condvar = (cc_condvar *) malloc(sizeof(cc_condvar));
assert(condvar != NULL);
cc_condvar_struct_init(condvar);
return condvar;
}
/*
*/
void
cc_condvar_destruct(cc_condvar * condvar)
{
assert((condvar != NULL));
cc_condvar_struct_clean(condvar);
free(condvar);
}
/*
*/
int
cc_condvar_wait(cc_condvar * condvar, cc_mutex * mutex)
{
int ok;
assert(condvar != NULL);
ok = internal_condvar_wait(condvar, mutex);
assert(ok == CC_OK);
return ok;
}
/*
*/
int
cc_condvar_timed_wait(cc_condvar * condvar,
cc_mutex * mutex,
cc_time period)
{
int ret;
assert(condvar != NULL);
ret = internal_condvar_timed_wait(condvar, mutex, period);
assert(ret == CC_OK || ret == CC_TIMEOUT);
return ret;
}
/*
*/
void
cc_condvar_wake_one(cc_condvar * condvar)
{
int ok;
assert(condvar != NULL);
ok = internal_condvar_wake_one(condvar);
assert(ok == CC_OK);
}
/*
*/
void
cc_condvar_wake_all(cc_condvar * condvar)
{
int ok;
assert(condvar != NULL);
ok = internal_condvar_wake_all(condvar);
assert(ok == CC_OK);
}
/* ********************************************************************** */
/*!
\class SbCondVar Inventor/threads/SbCondVar.h
\brief A class for synchronizing access to global variables.
\ingroup threads
Condition variables are used to protect global variables in an
environment where multiple threads are running concurrently.
*/
/*!
\fn SbCondVar::SbCondVar(void)
Constructor.
*/
/*!
\fn SbCondVar::~SbCondVar(void)
Destructor.
*/
/*!
\fn SbBool SbCondVar::wait(SbMutex & mutex)
This method blocks the calling thread until another thread calls
wakeOne() or wakeAll() on the SbCondVar object.
*/
/*!
\fn SbBool SbCondVar::timedWait(SbMutex & mutex, SbTime period)
This method blocks the calling thread until another thread calls
wakeOne() or wakeAll() on the object, but if this does not happen
within \c period, the thread is woken again anyways.
\c TRUE is returned when the thread wakes because either wakeOne()
or wakeAll() was called, \c FALSE is returned if the wait times out.
*/
/*!
\fn void SbCondVar::wakeOne(void)
This method wakes up one of the threads waiting on this SbCondVar.
*/
/*!
\fn void SbCondVar::wakeAll(void)
This method wakes up all the threads waiting on this SbCondVar.
*/
/* ********************************************************************** */
|