sem4.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. ** Command & Conquer Generals(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef SEM4_HEADER
  19. #define SEM4_HEADER
  20. #include <limits.h>
  21. #ifndef _WINDOWS
  22. #include <unistd.h>
  23. #endif
  24. #include "wstypes.h"
  25. #ifdef _REENTRANT
  26. #ifndef _WINDOWS
  27. #include <semaphore.h>
  28. #else
  29. #include <windows.h>
  30. #endif // _WINDOWS
  31. #endif // _REENTRANT
  32. // Windows headers have a tendency to redefine IN
  33. #ifdef IN
  34. #undef IN
  35. #endif
  36. #define IN const
  37. class Sem4
  38. {
  39. private:
  40. #ifdef _REENTRANT
  41. #ifndef _WINDOWS
  42. sem_t sem;
  43. #else
  44. HANDLE sem;
  45. #endif
  46. #endif
  47. public:
  48. Sem4();
  49. Sem4(uint32 value);
  50. ~Sem4();
  51. sint32 Wait(void) const;
  52. sint32 TryWait(void) const;
  53. sint32 Post(void) const;
  54. sint32 GetValue(int *sval) const;
  55. sint32 Destroy(void);
  56. };
  57. #endif