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.

79 lines
1.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1996 - 1999
  3. Module Name:
  4. hndlcach.cxx
  5. Abstract:
  6. The handle cache.
  7. Author:
  8. Kamen Moutafov [KamenM]
  9. Revision History:
  10. --*/
  11. #include <precomp.hxx>
  12. HandleCache::~HandleCache(void)
  13. {
  14. int i;
  15. BOOL b;
  16. for (i = 0; i < DEFAULT_CACHE_SIZE; i ++)
  17. {
  18. if (cacheSlots[i] == NULL)
  19. {
  20. b = CloseHandle(cacheSlots[i]);
  21. ASSERT(b);
  22. cacheSlots[i] = NULL;
  23. }
  24. }
  25. }
  26. HANDLE HandleCache::CheckOutHandle(void)
  27. {
  28. int i;
  29. HANDLE h;
  30. for (i = 0; i < DEFAULT_CACHE_SIZE; i++)
  31. {
  32. if (cacheSlots[i] != NULL)
  33. {
  34. h = cacheSlots[i];
  35. cacheSlots[i] = NULL;
  36. return h;
  37. }
  38. }
  39. return NULL;
  40. }
  41. void HandleCache::CheckinHandle(HANDLE *ph)
  42. {
  43. int i;
  44. for (i = 0; i < DEFAULT_CACHE_SIZE; i++)
  45. {
  46. if ( NULL == InterlockedCompareExchangePointer(&cacheSlots[i],
  47. *ph, NULL) )
  48. {
  49. *ph = NULL;
  50. break;
  51. }
  52. }
  53. }
  54. #if defined(DBG) || defined(_DEBUG)
  55. BOOL HandleCache::IsSecondHandleUsed(void)
  56. {
  57. ASSERT (DEFAULT_CACHE_SIZE >= 2);
  58. return (cacheSlots[1] != NULL);
  59. }
  60. #endif