ThreadsafePacketLogger.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Copyright (c) 2014, Oculus VR, Inc.
  3. * All rights reserved.
  4. *
  5. * This source code is licensed under the BSD-style license found in the
  6. * LICENSE file in the root directory of this source tree. An additional grant
  7. * of patent rights can be found in the PATENTS file in the same directory.
  8. *
  9. */
  10. #include "NativeFeatureIncludes.h"
  11. #if _RAKNET_SUPPORT_PacketLogger==1
  12. #include "ThreadsafePacketLogger.h"
  13. #include <string.h>
  14. using namespace RakNet;
  15. ThreadsafePacketLogger::ThreadsafePacketLogger()
  16. {
  17. }
  18. ThreadsafePacketLogger::~ThreadsafePacketLogger()
  19. {
  20. char **msg;
  21. while ((msg = logMessages.ReadLock()) != 0)
  22. {
  23. rakFree_Ex((*msg), _FILE_AND_LINE_ );
  24. }
  25. }
  26. void ThreadsafePacketLogger::Update(void)
  27. {
  28. char **msg;
  29. while ((msg = logMessages.ReadLock()) != 0)
  30. {
  31. WriteLog(*msg);
  32. rakFree_Ex((*msg), _FILE_AND_LINE_ );
  33. }
  34. }
  35. void ThreadsafePacketLogger::AddToLog(const char *str)
  36. {
  37. char **msg = logMessages.WriteLock();
  38. *msg = (char*) rakMalloc_Ex( strlen(str)+1, _FILE_AND_LINE_ );
  39. strcpy(*msg, str);
  40. logMessages.WriteUnlock();
  41. }
  42. #endif // _RAKNET_SUPPORT_*
粤ICP备19079148号