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.

69 lines
1.1 KiB

  1. /*++
  2. Copyright (C) 2000-2001 Microsoft Corporation
  3. --*/
  4. #include <windows.h>
  5. #include <stdio.h>
  6. #include <wbemcomn.h>
  7. #include "a51fib.h"
  8. #include <tls.h>
  9. void CALLBACK A51FiberBase(void* p)
  10. {
  11. CFiberTask* pTask = (CFiberTask*)p;
  12. pTask->Execute();
  13. //
  14. // No need to clean up --- it's the job of our caller
  15. //
  16. }
  17. void* CreateFiberForTask(CFiberTask* pTask)
  18. {
  19. //
  20. // For now, just create it
  21. //
  22. void* pFiber = CreateFiber(0, A51FiberBase, pTask);
  23. return pFiber;
  24. }
  25. void ReturnFiber(void* pFiber)
  26. {
  27. //
  28. // For now, just delete it
  29. //
  30. DeleteFiber(pFiber);
  31. }
  32. CTLS g_tlsInit;
  33. void* CreateOrGetCurrentFiber()
  34. {
  35. if(!g_tlsInit.IsValid())
  36. return NULL;
  37. void* pFiber = g_tlsInit.Get();
  38. if(pFiber == NULL)
  39. {
  40. //
  41. // We have never seen this thread before --- convert to fiber
  42. //
  43. pFiber = ConvertThreadToFiber(NULL);
  44. if(pFiber == NULL)
  45. return NULL;
  46. //
  47. // Remember it for the future
  48. //
  49. g_tlsInit.Set(pFiber);
  50. }
  51. return pFiber;
  52. }