Barrier 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  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
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. //
  14. // Barrier - C++ barrier class
  15. // ~~~~~~~
  16. //
  17. #ifndef _OPENTHREADS_BARRIER_
  18. #define _OPENTHREADS_BARRIER_
  19. #include <OpenThreads/Exports>
  20. namespace OpenThreads {
  21. /**
  22. * @class Barrier
  23. * @brief This class provides an object-oriented thread barrier interface
  24. *
  25. * @warning It is unwise to use the construct "Barrier barrier" in the
  26. * global namespace on sgi's. The object "barrier"
  27. * will confilict with the c-library sproc function "barrier" and
  28. * unpredictable results may occur. You have been warned.
  29. */
  30. class OPENTHREAD_EXPORT_DIRECTIVE Barrier {
  31. public:
  32. /**
  33. * Constructor
  34. */
  35. Barrier(int numThreads=0);
  36. /**
  37. * Destructor
  38. */
  39. virtual ~Barrier();
  40. /**
  41. * Reset the barrier to it's original state.
  42. */
  43. virtual void reset();
  44. /**
  45. * Block until numThreads threads have entered the barrier.
  46. */
  47. virtual void block(unsigned int numThreads=0);
  48. /**
  49. * Release the barrier, now.
  50. */
  51. virtual void release();
  52. /**
  53. * Return the number of threads currently blocked in the barrier,
  54. * Return -1 if error.
  55. */
  56. virtual int numThreadsCurrentlyBlocked();
  57. void invalidate();
  58. private:
  59. /**
  60. * Private copy constructor, to prevent tampering.
  61. */
  62. Barrier(const Barrier &/*b*/) {};
  63. /**
  64. * Private copy assignment, to prevent tampering.
  65. */
  66. Barrier &operator=(const Barrier &/*b*/) {return *(this);};
  67. /**
  68. * Implementation-specific private data.
  69. */
  70. void *_prvData;
  71. bool _valid;
  72. };
  73. }
  74. #endif // !_OPENTHREADS_BARRIER_