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.

113 lines
2.3 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. callid.cxx
  5. Abstract:
  6. Implements a cache of callids used for running down OIDs
  7. This is almost twice as fast as UuidCreate() but that doesn't
  8. mean much. UuidCreate takes 3 microseconds, this 1.4 (hit) or
  9. 4.2 (miss) on a P90.
  10. This codes real advantage would be on MP machines. But it is
  11. not performance critical and is probably overkill.
  12. Author:
  13. Mario Goertzel [MarioGo]
  14. Revision History:
  15. MarioGo 1/18/1996 Bits 'n pieces
  16. --*/
  17. #include <or.hxx>
  18. enum CacheState { CallidEmpty = 0,
  19. CallidAllocated = 1,
  20. CallidFree = -1 };
  21. struct CacheElement
  22. {
  23. CacheState _state;
  24. UUID _callid;
  25. };
  26. CacheElement CallidCache[4] = { CallidEmpty, {0},
  27. CallidEmpty, {0},
  28. CallidEmpty, {0},
  29. CallidEmpty, {0} };
  30. INT
  31. AllocateCallId(
  32. OUT UUID &Callid
  33. )
  34. {
  35. INT i;
  36. LONG l;
  37. RPC_STATUS status;
  38. for (i = 0; i < 4; i++)
  39. {
  40. if (CallidCache[i]._state != CallidAllocated)
  41. {
  42. l = InterlockedExchange((PLONG)&CallidCache[i]._state, CallidAllocated);
  43. switch(l)
  44. {
  45. case CallidAllocated:
  46. continue;
  47. case CallidFree:
  48. Callid = CallidCache[i]._callid;
  49. return(i);
  50. case CallidEmpty:
  51. status = UuidCreate(&Callid);
  52. VALIDATE((status, RPC_S_UUID_LOCAL_ONLY, RPC_S_OK, 0));
  53. CallidCache[i]._callid = Callid;
  54. return(i);
  55. }
  56. }
  57. }
  58. status = UuidCreate(&Callid);
  59. VALIDATE((status, RPC_S_UUID_LOCAL_ONLY, RPC_S_OK, 0));
  60. return(-1);
  61. }
  62. void
  63. FreeCallId(
  64. IN INT hint
  65. )
  66. /*++
  67. Routine Description:
  68. Frees a callid previously allcoated with AllocateCallId().
  69. Arguments:
  70. hint - The hint value returned by the previous call to AllocateCallId().
  71. Return Value:
  72. None
  73. --*/
  74. {
  75. ASSERT((hint > -2) && (hint < 4));
  76. if (hint >= 0)
  77. {
  78. CallidCache[hint]._state = CallidFree;;
  79. }
  80. }