You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by ts...@apache.org on 2018/08/22 15:15:15 UTC

logging-log4cxx git commit: Fixed Windows build

Repository: logging-log4cxx
Updated Branches:
  refs/heads/LOGCXX-500 6c4d91263 -> 21f4e3d9d


Fixed Windows build


Project: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/commit/21f4e3d9
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/tree/21f4e3d9
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4cxx/diff/21f4e3d9

Branch: refs/heads/LOGCXX-500
Commit: 21f4e3d9d82995f434e6c2cd760df794d8e0bf70
Parents: 6c4d912
Author: Denys Smolianiuk <De...@harmonicinc.com>
Authored: Wed Aug 22 17:25:40 2018 +0300
Committer: Denys Smolianiuk <De...@harmonicinc.com>
Committed: Wed Aug 22 17:25:40 2018 +0300

----------------------------------------------------------------------
 src/main/cpp/asyncappender.cpp |  8 ++---
 src/main/cpp/mutex.cpp         | 71 +++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4cxx/blob/21f4e3d9/src/main/cpp/asyncappender.cpp
----------------------------------------------------------------------
diff --git a/src/main/cpp/asyncappender.cpp b/src/main/cpp/asyncappender.cpp
index b7a4292..0484136 100644
--- a/src/main/cpp/asyncappender.cpp
+++ b/src/main/cpp/asyncappender.cpp
@@ -325,12 +325,12 @@ LoggingEventPtr AsyncAppender::DiscardSummary::createEvent(Pool& p) {
 AsyncAppender::DiscardSummary::createEvent(::log4cxx::helpers::Pool& p,
                                            unsigned discardedCount)
 {
-    char msg[128];
-
-    snprintf(msg, 128, LOG4CXX_STR("Discarded %u messages due to a full event buffer."), discardedCount);
+	LogString msg(LOG4CXX_STR("Discarded "));
+	StringHelper::toString(discardedCount, p, msg);
+	msg.append(LOG4CXX_STR(" messages due to a full event buffer"));
 
     return new LoggingEvent(
-              "",
+		      LOG4CXX_STR(""),
               log4cxx::Level::getError(),
               msg,
               LocationInfo::getLocationUnavailable());

http://git-wip-us.apache.org/repos/asf/logging-log4cxx/blob/21f4e3d9/src/main/cpp/mutex.cpp
----------------------------------------------------------------------
diff --git a/src/main/cpp/mutex.cpp b/src/main/cpp/mutex.cpp
index 2a1f79d..b57595d 100755
--- a/src/main/cpp/mutex.cpp
+++ b/src/main/cpp/mutex.cpp
@@ -27,7 +27,12 @@
 #endif
 #include <log4cxx/helpers/aprinitializer.h>
 
+#if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
+#include <windows.h>
+#else
+// POSIX
 #include <semaphore.h>
+#endif
 
 using namespace log4cxx::helpers;
 using namespace log4cxx;
@@ -148,7 +153,72 @@ void RWMutex::wrUnlock() const
 }
 
 
+#if defined(WIN32) || defined(_WIN32) || defined(_WIN64)
+
+namespace log4cxx {
+	namespace helpers {
+		struct SemaphoreImpl
+		{
+			HANDLE semaphore;
+		};
+	}
+}
+
+static const LONG cMax = 10;
+
+Semaphore::Semaphore(log4cxx::helpers::Pool& p)
+	: impl(nullptr)
+{
+#if APR_HAS_THREADS
+	impl = (SemaphoreImpl*)p.palloc(sizeof(SemaphoreImpl));
+	if (nullptr == impl) {
+		throw MutexException(APR_ENOMEM);
+	}
+
+	impl->semaphore = CreateSemaphore(
+		NULL,  // default security attributes
+		0,     // initial count
+		cMax,  // maximum count
+		NULL); // unnamed semaphore
 
+	if (impl->semaphore == NULL) {
+		throw MutexException(APR_ENOSHMAVAIL);
+	}
+#endif
+}
+
+Semaphore::~Semaphore()
+{
+#if APR_HAS_THREADS
+	if (impl && impl->semaphore)
+	{
+		CloseHandle(impl->semaphore);
+	}
+#endif
+}
+
+void Semaphore::await() const
+{
+#if APR_HAS_THREADS
+	DWORD dwWaitResult = WaitForSingleObject(impl->semaphore, INFINITE);
+	if (stat != 0) {
+		throw MutexException(1);
+	}
+#endif
+}
+
+void Semaphore::signalAll() const
+{
+#if APR_HAS_THREADS
+	BOOL stat = ReleaseSemaphore(impl->semaphore, 1, NULL);
+	if (!stat) {
+		throw MutexException(stat);
+	}
+#endif
+}
+
+#else
+// POSIX
 
 namespace log4cxx {
     namespace helpers {
@@ -205,3 +275,4 @@ void Semaphore::signalAll() const
 #endif
 }
 
+#endif