llcorehttpreplyqueue.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /**
  2. * @file llcorehttpreplyqueue.cpp
  3. * @brief Internal definitions for the operation reply queue
  4. *
  5. * $LicenseInfo:firstyear=2012&license=viewerlgpl$
  6. * Second Life Viewer Source Code
  7. * Copyright (C) 2012, Linden Research, Inc.
  8. *
  9. * This library is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation;
  12. * version 2.1 of the License only.
  13. *
  14. * This library is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with this library; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. *
  23. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  24. * $/LicenseInfo$
  25. */
  26. #include "linden_common.h"
  27. #include "llcorehttpreplyqueue.h"
  28. #include "llcorehttpoperation.h"
  29. #include "llcoremutex.h"
  30. using namespace LLCoreInt;
  31. namespace LLCore
  32. {
  33. HttpReplyQueue::HttpReplyQueue()
  34. {
  35. }
  36. HttpReplyQueue::~HttpReplyQueue()
  37. {
  38. HttpScopedLock lock(mQueueMutex);
  39. if (!mQueue.empty())
  40. {
  41. llwarns << "Queue not empty on destruction. Emptying now..." << llendl;
  42. mQueue.clear();
  43. }
  44. }
  45. void HttpReplyQueue::addOp(const HttpReplyQueue::opPtr_t& op)
  46. {
  47. HttpScopedLock lock(mQueueMutex);
  48. mQueue.push_back(op);
  49. }
  50. HttpReplyQueue::opPtr_t HttpReplyQueue::fetchOp()
  51. {
  52. HttpOperation::ptr_t result;
  53. {
  54. HttpScopedLock lock(mQueueMutex);
  55. if (mQueue.empty())
  56. {
  57. return opPtr_t();
  58. }
  59. result = mQueue.front();
  60. mQueue.erase(mQueue.begin());
  61. }
  62. // Caller also acquires the reference count
  63. return result;
  64. }
  65. void HttpReplyQueue::fetchAll(OpContainer& ops)
  66. {
  67. // It is not allowed to put something back into the queue...
  68. llassert_always(ops.empty());
  69. {
  70. HttpScopedLock lock(mQueueMutex);
  71. if (!mQueue.empty())
  72. {
  73. mQueue.swap(ops);
  74. }
  75. }
  76. }
  77. } // End namespace LLCore