Source code of Windows XP (NT5)
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.

124 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 1995-2001 Microsoft Corporation
  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. #include "umpnplib.h"
  23. //
  24. // Common locking routines, used by client and server.
  25. // (LOCKINFO type definition and inline lock / unlock routines defined in
  26. // umpnplib.h)
  27. //
  28. BOOL
  29. InitPrivateResource(
  30. OUT PLOCKINFO Lock
  31. )
  32. /*++
  33. Routine Description:
  34. Initialize a lock structure to be used with Synchronization routines.
  35. Arguments:
  36. LockHandles - supplies structure to be initialized. This routine creates
  37. the locking event and mutex and places handles in this structure.
  38. Return Value:
  39. TRUE if the lock structure was successfully initialized. FALSE if not.
  40. --*/
  41. {
  42. if(Lock->LockHandles[DESTROYED_EVENT] = CreateEvent(NULL,TRUE,FALSE,NULL)) {
  43. if(Lock->LockHandles[ACCESS_MUTEX] = CreateMutex(NULL,FALSE,NULL)) {
  44. return(TRUE);
  45. }
  46. CloseHandle(Lock->LockHandles[DESTROYED_EVENT]);
  47. }
  48. return(FALSE);
  49. } // InitPrivateResource
  50. VOID
  51. DestroyPrivateResource(
  52. IN OUT PLOCKINFO Lock
  53. )
  54. /*++
  55. Routine Description:
  56. Tears down a lock structure created by InitPrivateResource.
  57. ASSUMES THAT THE CALLING ROUTINE HAS ALREADY ACQUIRED THE LOCK!
  58. Arguments:
  59. LockHandle - supplies structure to be torn down. The structure itself
  60. is not freed.
  61. Return Value:
  62. None.
  63. --*/
  64. {
  65. HANDLE h1,h2;
  66. h1 = Lock->LockHandles[DESTROYED_EVENT];
  67. h2 = Lock->LockHandles[ACCESS_MUTEX];
  68. Lock->LockHandles[DESTROYED_EVENT] = NULL;
  69. Lock->LockHandles[ACCESS_MUTEX] = NULL;
  70. CloseHandle(h2);
  71. SetEvent(h1);
  72. CloseHandle(h1);
  73. } // DestroyPrivateResource
  74.