Version: 9.16.0
AlternateThreadPT.hxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
3// This library is free software; you can redistribute it and/or
4// modify it under the terms of the GNU Lesser General Public
5// License as published by the Free Software Foundation; either
6// version 2.1 of the License, or (at your option) any later version.
7//
8// This library is distributed in the hope that it will be useful,
9// but WITHOUT ANY WARRANTY; without even the implied warranty of
10// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11// Lesser General Public License for more details.
12//
13// You should have received a copy of the GNU Lesser General Public
14// License along with this library; if not, write to the Free Software
15// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19#ifndef __ALTERNATETHREADPT_HXX__
20#define __ALTERNATETHREADPT_HXX__
21
22#include <pthread.h>
23
24#include "YACSBasesExport.hxx"
25
26namespace YACS
27{
28 namespace BASES
29 {
31
56 {
57 public:
58 enum ThreadStatus {UNEXISTING, NORMAL_CYCLE, TERMINATION_REQUESTED, READY_TO_JOIN};
59
61 virtual ~AlternateThreadPT();
62
64
68 void start();
69
71 virtual void signalSlaveAndWait();
72
74 void terminateSlaveThread();
75
77 virtual void signalMasterAndWait();
78
80 bool isTerminationRequested() const;
81
83 ThreadStatus getThreadStatus() const;
84
85 protected:
87
94 virtual void run()=0;
95
96 private:
97 void signalAndWait();
98
99 static void * runThread(void * instance);
100 static void threadCleanupFct(void * instance);
101
102 pthread_t _threadId;
104 pthread_cond_t _pingPongCond;
105 pthread_mutex_t _pingPongMutex;
106
107 };
108 }
109}
110
111#endif
#define YACSBASES_EXPORT
This class provides a mechanism to run two threads alternately.
virtual void run()=0
This method must be implemented in subclasses and will be run in the slave thread.