Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
1.6 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. sem.cxx
  5. Abstract:
  6. This file contains the system dependent mutex class for NT.
  7. Author:
  8. Steven Zeck (stevez) 07/01/90
  9. --*/
  10. #define NULL 0
  11. extern "C" {
  12. #include <nt.h>
  13. #include <ntrtl.h>
  14. #include <nturtl.h>
  15. }
  16. #include "sem.hxx"
  17. MUTEX::MUTEX (
  18. OUT int *Status
  19. )
  20. /*++
  21. Routine Description:
  22. Rather than being the RTL_CRITICAL_SECTION itself, the MUTEX
  23. contains a pointer to the RTL_CRITICAL_SECTION. This isolates the system
  24. dependent code at a small expense in speed.
  25. Arguments:
  26. Status - place to return results, 0 for success.
  27. --*/
  28. {
  29. *Status = 0;
  30. if ((Sem = new RTL_CRITICAL_SECTION))
  31. {
  32. if (NT_ERROR (RtlInitializeCriticalSection((RTL_CRITICAL_SECTION *) Sem)))
  33. {
  34. delete Sem;
  35. *Status = 1;
  36. }
  37. }
  38. }
  39. MUTEX::~MUTEX (
  40. )
  41. /*++
  42. Routine Description:
  43. Delete the NT critical section object and the memory it uses.
  44. --*/
  45. {
  46. NTSTATUS Status;
  47. Status = RtlDeleteCriticalSection((RTL_CRITICAL_SECTION *) Sem);
  48. ASSERT(NT_SUCCESS(Status));
  49. delete Sem;
  50. }
  51. int
  52. MUTEX::Clear (
  53. )
  54. /*++
  55. Routine Description:
  56. Clear the MUTEX indicating that the current thread is done with it.
  57. --*/
  58. {
  59. return(NT_ERROR(RtlLeaveCriticalSection((RTL_CRITICAL_SECTION *) Sem)));
  60. }
  61. int
  62. MUTEX::Request (
  63. )
  64. /*++
  65. Routine Description:
  66. Request exclusive access to the MUTEX. This routine will
  67. not return until the current thread has exclusive access to the
  68. MUTEX.
  69. --*/
  70. {
  71. return(NT_ERROR (RtlEnterCriticalSection((RTL_CRITICAL_SECTION *) Sem)));
  72. }