1
0

nxcondition.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include "nxcondition.h"
  2. #include "foundation/error.h"
  3. int NXConditionInitialize(nx_condition_t condition)
  4. {
  5. if (condition == 0)
  6. return NErr_NullPointer;
  7. InitializeCriticalSection(&condition->mutex);
  8. InitializeConditionVariable(&condition->condition);
  9. return NErr_Success;
  10. }
  11. int NXConditionDestroy(nx_condition_t condition)
  12. {
  13. if (condition == 0)
  14. return NErr_NullPointer;
  15. DeleteCriticalSection(&condition->mutex);
  16. return NErr_Success;
  17. }
  18. int NXConditionLock(nx_condition_t condition)
  19. {
  20. if (condition == 0)
  21. return NErr_NullPointer;
  22. EnterCriticalSection(&condition->mutex);
  23. return NErr_Success;
  24. }
  25. int NXConditionUnlock(nx_condition_t condition)
  26. {
  27. if (condition == 0)
  28. return NErr_NullPointer;
  29. LeaveCriticalSection(&condition->mutex);
  30. return NErr_Success;
  31. }
  32. int NXConditionWait(nx_condition_t condition)
  33. {
  34. if (condition == 0)
  35. return NErr_NullPointer;
  36. SleepConditionVariableCS(&condition->condition, &condition->mutex, INFINITE);
  37. return NErr_Success;
  38. }
  39. int NXConditionTimedWait(nx_condition_t condition, unsigned int milliseconds)
  40. {
  41. if (condition == 0)
  42. return NErr_NullPointer;
  43. SleepConditionVariableCS(&condition->condition, &condition->mutex, milliseconds);
  44. return NErr_Success;
  45. }
  46. int NXConditionSignal(nx_condition_t condition)
  47. {
  48. if (condition == 0)
  49. return NErr_NullPointer;
  50. WakeConditionVariable(&condition->condition);
  51. return NErr_Success;
  52. }