2006-09-03 10:39:10 +03:00
|
|
|
/*
|
2008-07-10 12:56:42 +03:00
|
|
|
Copyright (C) 2004-2008 Grame
|
2006-09-03 10:39:10 +03:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
2008-07-10 12:56:42 +03:00
|
|
|
it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version.
|
2006-09-03 10:39:10 +03:00
|
|
|
|
2008-07-10 12:56:42 +03:00
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU Lesser General Public License for more details.
|
2006-09-03 10:39:10 +03:00
|
|
|
|
2008-07-10 12:56:42 +03:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2011-08-26 15:08:20 +03:00
|
|
|
along with this program; if not, write to the Free Software
|
2008-07-10 12:56:42 +03:00
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2006-09-03 10:39:10 +03:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2012-01-27 13:36:20 +02:00
|
|
|
#ifndef __JackPosixProcessSync__
|
|
|
|
#define __JackPosixProcessSync__
|
2006-09-03 10:39:10 +03:00
|
|
|
|
2009-02-17 10:14:11 +02:00
|
|
|
#include "JackPosixMutex.h"
|
2011-08-26 15:08:20 +03:00
|
|
|
#include "JackException.h"
|
2006-09-03 10:39:10 +03:00
|
|
|
#include <sys/time.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
namespace Jack
|
|
|
|
{
|
|
|
|
|
|
|
|
/*!
|
2012-01-27 13:36:20 +02:00
|
|
|
\brief A synchronization primitive built using a condition variable.
|
2006-09-03 10:39:10 +03:00
|
|
|
*/
|
|
|
|
|
2012-01-27 13:36:20 +02:00
|
|
|
class JackPosixProcessSync : public JackBasePosixMutex
|
2006-09-03 10:39:10 +03:00
|
|
|
{
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
pthread_cond_t fCond; // Condition variable
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2012-01-27 18:53:05 +02:00
|
|
|
JackPosixProcessSync(const char* name = NULL):JackBasePosixMutex()
|
2006-09-03 10:39:10 +03:00
|
|
|
{
|
2011-08-26 15:08:20 +03:00
|
|
|
int res = pthread_cond_init(&fCond, NULL);
|
|
|
|
ThrowIf(res != 0, JackException("JackBasePosixMutex: could not init the cond variable"));
|
2006-09-03 10:39:10 +03:00
|
|
|
}
|
2008-06-03 11:48:09 +03:00
|
|
|
|
2012-01-27 13:36:20 +02:00
|
|
|
virtual ~JackPosixProcessSync()
|
2006-09-03 10:39:10 +03:00
|
|
|
{
|
|
|
|
pthread_cond_destroy(&fCond);
|
|
|
|
}
|
|
|
|
|
2008-05-26 12:49:27 +03:00
|
|
|
bool TimedWait(long usec);
|
2009-02-17 10:14:11 +02:00
|
|
|
bool LockedTimedWait(long usec);
|
2011-08-26 15:08:20 +03:00
|
|
|
|
2009-02-17 10:14:11 +02:00
|
|
|
void Wait();
|
|
|
|
void LockedWait();
|
2011-08-26 15:08:20 +03:00
|
|
|
|
2009-02-17 10:14:11 +02:00
|
|
|
void Signal();
|
|
|
|
void LockedSignal();
|
2011-08-26 15:08:20 +03:00
|
|
|
|
2009-02-17 10:14:11 +02:00
|
|
|
void SignalAll();
|
|
|
|
void LockedSignalAll();
|
2011-08-26 15:08:20 +03:00
|
|
|
|
2006-09-03 10:39:10 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // end of namespace
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|