Fixed Windows build
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 @@
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());
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 @@
}
+#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 @@
#endif
}
+#endif