Condition 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. // Condition - C++ condition class
  15. // ~~~~~~~~~
  16. //
  17. #ifndef _OPENTHREADS_CONDITION_
  18. #define _OPENTHREADS_CONDITION_
  19. #include <OpenThreads/Exports>
  20. #include <OpenThreads/Mutex>
  21. namespace OpenThreads {
  22. /**
  23. * @class Condition
  24. * @brief This class provides an object-oriented thread condition interface.
  25. */
  26. class OPENTHREAD_EXPORT_DIRECTIVE Condition {
  27. public:
  28. /**
  29. * Constructor
  30. */
  31. Condition();
  32. /**
  33. * Destructor
  34. */
  35. virtual ~Condition();
  36. /**
  37. * Wait on a mutex.
  38. */
  39. virtual int wait(Mutex *mutex);
  40. /**
  41. * Wait on a mutex for a given amount of time (ms)
  42. *
  43. * @return 0 if normal, -1 if errno set, errno code otherwise.
  44. */
  45. virtual int wait(Mutex *mutex, unsigned long int ms);
  46. /**
  47. * Signal a SINGLE thread to wake if it's waiting.
  48. *
  49. * @return 0 if normal, -1 if errno set, errno code otherwise.
  50. */
  51. virtual int signal();
  52. /**
  53. * Wake all threads waiting on this condition.
  54. *
  55. * @return 0 if normal, -1 if errno set, errno code otherwise.
  56. */
  57. virtual int broadcast();
  58. private:
  59. /**
  60. * Private copy constructor, to prevent tampering.
  61. */
  62. Condition(const Condition &/*c*/) {};
  63. /**
  64. * Private copy assignment, to prevent tampering.
  65. */
  66. Condition &operator=(const Condition &/*c*/) {return *(this);};
  67. /**
  68. * Implementation-specific data
  69. */
  70. void *_prvData;
  71. };
  72. }
  73. #endif // !_OPENTHREADS_CONDITION_