Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TPosixCondition.cxx
Go to the documentation of this file.
1// @(#)root/thread:$Id$
2// Author: Fons Rademakers 01/07/97
3
4/*************************************************************************
5 * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12//////////////////////////////////////////////////////////////////////////
13// //
14// TPosixCondition //
15// //
16// This class provides an interface to the posix condition variable //
17// routines. //
18// //
19//////////////////////////////////////////////////////////////////////////
20
21#include "TPosixCondition.h"
22#include "TPosixMutex.h"
23#include "PosixThreadInc.h"
24
25#include <cerrno>
26
27
28
29////////////////////////////////////////////////////////////////////////////////
30/// Create Condition variable. Ctor must be given a pointer to an
31/// existing mutex. The condition variable is then linked to the mutex,
32/// so that there is an implicit unlock and lock around Wait() and
33/// TimedWait().
34
36{
37 fMutex = (TPosixMutex *) m;
38
39 int rc = pthread_cond_init(&fCond, nullptr);
40
41 if (rc)
42 SysError("TPosixCondition", "pthread_cond_init error");
43}
44
45////////////////////////////////////////////////////////////////////////////////
46/// TCondition dtor.
47
49{
51
52 if (rc)
53 SysError("~TPosixCondition", "pthread_cond_destroy error");
54}
55
56////////////////////////////////////////////////////////////////////////////////
57/// Wait for the condition variable to be signalled. The mutex is
58/// implicitely released before waiting and locked again after waking up.
59/// If Wait() is called by multiple threads, a signal may wake up more
60/// than one thread. See POSIX threads documentation for details.
61
66
67////////////////////////////////////////////////////////////////////////////////
68/// TimedWait() is given an absolute time to wait until. To wait for a
69/// relative time from now, use TThread::GetTime(). See POSIX threads
70/// documentation for why absolute times are better than relative.
71/// Returns 0 if successfully signalled, 1 if time expired.
72
84
85////////////////////////////////////////////////////////////////////////////////
86/// If one or more threads have called Wait(), Signal() wakes up at least
87/// one of them, possibly more. See POSIX threads documentation for details.
88
93
94
95////////////////////////////////////////////////////////////////////////////////
96/// Broadcast is like signal but wakes all threads which have called Wait().
97
unsigned long ULong_t
Unsigned long integer 4 bytes (unsigned long). Size depends on architecture.
Definition RtypesCore.h:69
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
Definition RtypesCore.h:68
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
virtual void SysError(const char *method, const char *msgfmt,...) const
Issue system error message.
Definition TObject.cxx:1085
virtual ~TPosixCondition()
TCondition dtor.
Int_t Wait() override
Wait for the condition variable to be signalled.
Int_t Signal() override
If one or more threads have called Wait(), Signal() wakes up at least one of them,...
TPosixCondition(TMutexImp *m)
Create Condition variable.
pthread_cond_t fCond
Int_t TimedWait(ULong_t secs, ULong_t nanoSecs=0) override
TimedWait() is given an absolute time to wait until.
Int_t Broadcast() override
Broadcast is like signal but wakes all threads which have called Wait().
TPosixMutex * fMutex
pthread_mutex_t fMutex
Definition TPosixMutex.h:33
TMarker m
Definition textangle.C:8