Leaked source code of windows server 2003
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.

136 lines
2.3 KiB

  1. /*++
  2. Copyright (c) Microsoft Corporation. All rights reserved.
  3. Module Name:
  4. locks.c
  5. Abstract:
  6. This module contains locking routines used by both cfgmgr32
  7. and umpnpmgr.
  8. InitPrivateResource
  9. DestroyPrivateResource
  10. Author:
  11. Jim Cavalaris (jamesca) 03-15-2001
  12. Environment:
  13. User mode only.
  14. Revision History:
  15. 15-March-2001 jamesca
  16. Creation and initial implementation.
  17. --*/
  18. //
  19. // includes
  20. //
  21. #include "precomp.h"
  22. #pragma hdrstop
  23. #include "umpnplib.h"
  24. //
  25. // Common locking routines, used by client and server.
  26. // (LOCKINFO type definition and inline lock / unlock routines defined in
  27. // umpnplib.h)
  28. //
  29. BOOL
  30. InitPrivateResource(
  31. OUT PLOCKINFO Lock
  32. )
  33. /*++
  34. Routine Description:
  35. Initialize a lock structure to be used with Synchronization routines.
  36. Arguments:
  37. LockHandles - supplies structure to be initialized. This routine creates
  38. the locking event and mutex and places handles in this structure.
  39. Return Value:
  40. TRUE if the lock structure was successfully initialized. FALSE if not.
  41. --*/
  42. {
  43. Lock->LockHandles[DESTROYED_EVENT] = CreateEvent(NULL, TRUE, FALSE, NULL);
  44. if (Lock->LockHandles[DESTROYED_EVENT] != NULL) {
  45. Lock->LockHandles[ACCESS_MUTEX] = CreateMutex(NULL, FALSE, NULL);
  46. if (Lock->LockHandles[ACCESS_MUTEX] != NULL) {
  47. return TRUE;
  48. }
  49. CloseHandle(Lock->LockHandles[DESTROYED_EVENT]);
  50. Lock->LockHandles[DESTROYED_EVENT] = NULL;
  51. }
  52. return FALSE;
  53. } // InitPrivateResource
  54. VOID
  55. DestroyPrivateResource(
  56. IN OUT PLOCKINFO Lock
  57. )
  58. /*++
  59. Routine Description:
  60. Tears down a lock structure created by InitPrivateResource.
  61. ASSUMES THAT THE CALLING ROUTINE HAS ALREADY ACQUIRED THE LOCK!
  62. Arguments:
  63. LockHandle - supplies structure to be torn down. The structure itself
  64. is not freed.
  65. Return Value:
  66. None.
  67. --*/
  68. {
  69. HANDLE h1,h2;
  70. h1 = Lock->LockHandles[DESTROYED_EVENT];
  71. h2 = Lock->LockHandles[ACCESS_MUTEX];
  72. Lock->LockHandles[DESTROYED_EVENT] = NULL;
  73. Lock->LockHandles[ACCESS_MUTEX] = NULL;
  74. CloseHandle(h2);
  75. SetEvent(h1);
  76. CloseHandle(h1);
  77. return;
  78. } // DestroyPrivateResource
  79.