EventLoopGroup.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/crt/io/EventLoopGroup.h>
  6. #include <iostream>
  7. namespace Aws
  8. {
  9. namespace Crt
  10. {
  11. namespace Io
  12. {
  13. EventLoopGroup::EventLoopGroup(uint16_t threadCount, Allocator *allocator) noexcept
  14. : m_eventLoopGroup(nullptr), m_lastError(AWS_ERROR_SUCCESS)
  15. {
  16. m_eventLoopGroup = aws_event_loop_group_new_default(allocator, threadCount, NULL);
  17. if (m_eventLoopGroup == nullptr)
  18. {
  19. m_lastError = aws_last_error();
  20. }
  21. }
  22. EventLoopGroup::EventLoopGroup(uint16_t cpuGroup, uint16_t threadCount, Allocator *allocator) noexcept
  23. : m_eventLoopGroup(nullptr), m_lastError(AWS_ERROR_SUCCESS)
  24. {
  25. m_eventLoopGroup =
  26. aws_event_loop_group_new_default_pinned_to_cpu_group(allocator, threadCount, cpuGroup, NULL);
  27. if (m_eventLoopGroup == nullptr)
  28. {
  29. m_lastError = aws_last_error();
  30. }
  31. }
  32. EventLoopGroup::~EventLoopGroup() { aws_event_loop_group_release(m_eventLoopGroup); }
  33. EventLoopGroup::EventLoopGroup(EventLoopGroup &&toMove) noexcept
  34. : m_eventLoopGroup(toMove.m_eventLoopGroup), m_lastError(toMove.m_lastError)
  35. {
  36. toMove.m_lastError = AWS_ERROR_UNKNOWN;
  37. toMove.m_eventLoopGroup = nullptr;
  38. }
  39. EventLoopGroup &EventLoopGroup::operator=(EventLoopGroup &&toMove) noexcept
  40. {
  41. m_eventLoopGroup = toMove.m_eventLoopGroup;
  42. m_lastError = toMove.m_lastError;
  43. toMove.m_lastError = AWS_ERROR_UNKNOWN;
  44. toMove.m_eventLoopGroup = nullptr;
  45. return *this;
  46. }
  47. int EventLoopGroup::LastError() const { return m_lastError; }
  48. EventLoopGroup::operator bool() const { return m_lastError == AWS_ERROR_SUCCESS; }
  49. aws_event_loop_group *EventLoopGroup::GetUnderlyingHandle() noexcept
  50. {
  51. if (*this)
  52. {
  53. return m_eventLoopGroup;
  54. }
  55. return nullptr;
  56. }
  57. } // namespace Io
  58. } // namespace Crt
  59. } // namespace Aws