Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ProgressSemaphore.hh
1 /*
2  * This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4  Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10  BIAS is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation; either version 2.1 of the License, or
13  (at your option) any later version.
14 
15  BIAS is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with BIAS; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 #ifndef __ProgressSemaphore_hh__
26 #define __ProgressSemaphore_hh__
27 
28 // includes
29 #include <bias_config.h>
30 #ifdef BIAS_HAVE_PTHREADS
31 #include <pthread.h>
32 #endif
33 
34 namespace BIAS {
35 
36  /** @class ProgressSemaphore
37  @brief this class represents a progress counter which multiple processes
38  can use. It is implemented using locked access to the progress variables
39  using pthread mutexes
40  An example is that one thread starts a progress and has to wait till
41  this progress is done and wants to display a progress bar. In the meanwhile
42  the working progress can update the progress values in the ProgressSemaphore
43  to inform the waiting progress about its progress.
44  @author evers 03/2008 */
45  class BIASCommon_EXPORT ProgressSemaphore
46  {
47  public:
49  /// destructor
51  /** \brief returns current progress state in standard intervall */
52  float GetProgress();
53  /** \brief Set the number of steps to progress will need to complete */
54  void SetNumSteps(unsigned int steps);
55  /** \brief Set the current step */
56  void SetCurrentStep(unsigned int CurrentStep);
57  /** \brief Increment the current step */
58  void IncrementStep();
59  /** \brief Sets a termination flag to inform e.g. another process that
60  * an abort is requested */
61  void SetTerminateFlag();
62  /** \brief Chancels the termination flag */
63  void ResetTerminateFlag();
64  /** \brief Tells whether the termination flag is set.*/
65  bool IsTerminationRequested();
66  /** Resets all values */
67  void Reset();
68 
69  protected:
70 #ifdef BIAS_HAVE_PTHREADS
71  pthread_mutex_t Lock_;
72 #endif
73  unsigned int NumSteps_;
74  unsigned int CurrentStep_;
75  bool Terminate_;
76 
77  }; // class ProgressSemaphore
78 
79 } // namespace
80 
81 #endif // __ProgressSemaphore_hh__
this class represents a progress counter which multiple processes can use.
class BIASCommon_EXPORT ProgressSemaphore