[Libreoffice-commits] online.git: 5 commits - common/FileUtil.cpp common/Log.cpp common/Util.cpp common/Util.hpp net/Socket.hpp
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Wed Aug 29 18:02:42 UTC 2018
common/FileUtil.cpp | 22 ++++++++++-
common/Log.cpp | 15 ++++++++
common/Util.cpp | 31 +++++++++++++++-
common/Util.hpp | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++
net/Socket.hpp | 20 +++++-----
5 files changed, 168 insertions(+), 16 deletions(-)
New commits:
commit d07f686b281844938db412cfa7c1d77b77087597
Author: Tor Lillqvist <tml at iki.fi>
AuthorDate: Wed Aug 29 18:48:13 2018 +0300
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Aug 29 20:56:59 2018 +0300
Make this file compile for iOS
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 965f08247..5275ec61e 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -33,10 +33,10 @@
#include <thread>
#include <atomic>
-#include "common/Common.hpp"
-#include "common/Log.hpp"
-#include "common/Util.hpp"
-#include "common/SigUtil.hpp"
+#include "Common.hpp"
+#include "Log.hpp"
+#include "Util.hpp"
+#include "SigUtil.hpp"
namespace Poco
{
@@ -262,8 +262,8 @@ public:
{
if (InhibitThreadChecks)
return;
- // 0 owner means detached and can be invoked by any thread.
- const bool sameThread = (_owner == std::thread::id(0) || std::this_thread::get_id() == _owner);
+ // uninitialized owner means detached and can be invoked by any thread.
+ const bool sameThread = (_owner == std::thread::id() || std::this_thread::get_id() == _owner);
if (!sameThread)
LOG_ERR("#" << _fd << " Invoked from foreign thread. Expected: " <<
Log::to_string(_owner) << " but called from " <<
@@ -384,7 +384,7 @@ public:
LOG_DBG("Removing socket #" << socket->getFD() << " from " << _name);
socket->assertCorrectThread();
- socket->setThreadOwner(std::thread::id(0));
+ socket->setThreadOwner(std::thread::id());
_pollSockets.pop_back();
}
@@ -416,8 +416,8 @@ public:
{
if (InhibitThreadChecks)
return;
- // 0 owner means detached and can be invoked by any thread.
- const bool sameThread = (!isAlive() || _owner == std::thread::id(0) || std::this_thread::get_id() == _owner);
+ // uninitialized owner means detached and can be invoked by any thread.
+ const bool sameThread = (!isAlive() || _owner == std::thread::id() || std::this_thread::get_id() == _owner);
if (!sameThread)
LOG_ERR("Incorrect thread affinity for " << _name << ". Expected: " <<
Log::to_string(_owner) << " (" << Util::getThreadId() <<
@@ -564,7 +564,7 @@ public:
std::lock_guard<std::mutex> lock(_mutex);
LOG_DBG("Inserting socket #" << newSocket->getFD() << " into " << _name);
// sockets in transit are un-owned.
- newSocket->setThreadOwner(std::thread::id(0));
+ newSocket->setThreadOwner(std::thread::id());
_newSockets.emplace_back(newSocket);
wakeup();
}
commit 39072dbae5aeee2fc09cb401ec9900b3e7eb7ac5
Author: Tor Lillqvist <tml at iki.fi>
AuthorDate: Wed Aug 29 18:48:00 2018 +0300
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Aug 29 20:41:16 2018 +0300
Make this file compile for iOS
diff --git a/common/Util.hpp b/common/Util.hpp
index afc42dcd0..9233a2142 100644
--- a/common/Util.hpp
+++ b/common/Util.hpp
@@ -23,6 +23,10 @@
#include <memory.h>
+#ifndef __linux
+#include <thread>
+#endif
+
#include <Poco/File.h>
#include <Poco/Path.h>
#include <Poco/Process.h>
@@ -138,7 +142,11 @@ namespace Util
const char *getThreadName();
+#ifdef __linux
pid_t getThreadId();
+#else
+ std::thread::id getThreadId();
+#endif
/// Get version information
void getVersionInfo(std::string& version, std::string& hash);
@@ -354,48 +362,110 @@ namespace Util
case ELOOP: return "ELOOP";
case ENOMSG: return "ENOMSG";
case EIDRM: return "EIDRM";
+#ifdef ECHRNG
case ECHRNG: return "ECHRNG";
+#endif
+#ifdef EL2NSYNC
case EL2NSYNC: return "EL2NSYNC";
+#endif
+#ifdef EL3HLT
case EL3HLT: return "EL3HLT";
+#endif
+#ifdef EL3RST
case EL3RST: return "EL3RST";
+#endif
+#ifdef ELNRNG
case ELNRNG: return "ELNRNG";
+#endif
+#ifdef EUNATCH
case EUNATCH: return "EUNATCH";
+#endif
+#ifdef ENOCSI
case ENOCSI: return "ENOCSI";
+#endif
+#ifdef EL2HLT
case EL2HLT: return "EL2HLT";
+#endif
+#ifdef EBADE
case EBADE: return "EBADE";
+#endif
+#ifdef EBADR
case EBADR: return "EBADR";
+#endif
+#ifdef EXFULL
case EXFULL: return "EXFULL";
+#endif
+#ifdef ENOANO
case ENOANO: return "ENOANO";
+#endif
+#ifdef EBADRQC
case EBADRQC: return "EBADRQC";
+#endif
+#ifdef EBADSLT
case EBADSLT: return "EBADSLT";
+#endif
+#ifdef EBFONT
case EBFONT: return "EBFONT";
+#endif
case ENOSTR: return "ENOSTR";
case ENODATA: return "ENODATA";
case ETIME: return "ETIME";
case ENOSR: return "ENOSR";
+#ifdef ENONET
case ENONET: return "ENONET";
+#endif
+#ifdef ENOPKG
case ENOPKG: return "ENOPKG";
+#endif
case EREMOTE: return "EREMOTE";
case ENOLINK: return "ENOLINK";
+#ifdef EADV
case EADV: return "EADV";
+#endif
+#ifdef ESRMNT
case ESRMNT: return "ESRMNT";
+#endif
+#ifdef ECOMM
case ECOMM: return "ECOMM";
+#endif
case EPROTO: return "EPROTO";
case EMULTIHOP: return "EMULTIHOP";
+#ifdef EDOTDOT
case EDOTDOT: return "EDOTDOT";
+#endif
case EBADMSG: return "EBADMSG";
case EOVERFLOW: return "EOVERFLOW";
+#ifdef ENOTUNIQ
case ENOTUNIQ: return "ENOTUNIQ";
+#endif
+#ifdef EBADFD
case EBADFD: return "EBADFD";
+#endif
+#ifdef EREMCHG
case EREMCHG: return "EREMCHG";
+#endif
+#ifdef ELIBACC
case ELIBACC: return "ELIBACC";
+#endif
+#ifdef ELIBBAD
case ELIBBAD: return "ELIBBAD";
+#endif
+#ifdef ELIBSCN
case ELIBSCN: return "ELIBSCN";
+#endif
+#ifdef ELIBMAX
case ELIBMAX: return "ELIBMAX";
+#endif
+#ifdef ELIBEXEC
case ELIBEXEC: return "ELIBEXEC";
+#endif
case EILSEQ: return "EILSEQ";
+#ifdef ERESTART
case ERESTART: return "ERESTART";
+#endif
+#ifdef ESTRPIPE
case ESTRPIPE: return "ESTRPIPE";
+#endif
case EUSERS: return "EUSERS";
case ENOTSOCK: return "ENOTSOCK";
case EDESTADDRREQ: return "EDESTADDRREQ";
@@ -426,23 +496,49 @@ namespace Util
case EALREADY: return "EALREADY";
case EINPROGRESS: return "EINPROGRESS";
case ESTALE: return "ESTALE";
+#ifdef EUCLEAN
case EUCLEAN: return "EUCLEAN";
+#endif
+#ifdef ENOTNAM
case ENOTNAM: return "ENOTNAM";
+#endif
+#ifdef ENAVAIL
case ENAVAIL: return "ENAVAIL";
+#endif
+#ifdef EISNAM
case EISNAM: return "EISNAM";
+#endif
+#ifdef EREMOTEIO
case EREMOTEIO: return "EREMOTEIO";
+#endif
case EDQUOT: return "EDQUOT";
+#ifdef ENOMEDIUM
case ENOMEDIUM: return "ENOMEDIUM";
+#endif
+#ifdef EMEDIUMTYPE
case EMEDIUMTYPE: return "EMEDIUMTYPE";
+#endif
case ECANCELED: return "ECANCELED";
+#ifdef ENOKEY
case ENOKEY: return "ENOKEY";
+#endif
+#ifdef EKEYEXPIRED
case EKEYEXPIRED: return "EKEYEXPIRED";
+#endif
+#ifdef EKEYREVOKED
case EKEYREVOKED: return "EKEYREVOKED";
+#endif
+#ifdef EKEYREJECTED
case EKEYREJECTED: return "EKEYREJECTED";
+#endif
case EOWNERDEAD: return "EOWNERDEAD";
case ENOTRECOVERABLE: return "ENOTRECOVERABLE";
+#ifdef ERFKILL
case ERFKILL: return "ERFKILL";
+#endif
+#ifdef EHWPOISON
case EHWPOISON: return "EHWPOISON";
+#endif
default: return std::to_string(e);
}
}
commit 7d850bfa6e4ee0edfb479af57024da72ca1b950f
Author: Tor Lillqvist <tml at iki.fi>
AuthorDate: Wed Aug 29 18:47:32 2018 +0300
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Aug 29 20:41:07 2018 +0300
Make this file compile for iOS
Change-Id: I1d82fed408818a6945cbf2b7743ffcdbe67f6079
diff --git a/common/Util.cpp b/common/Util.cpp
index e14412329..f48978f37 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -14,11 +14,15 @@
#include <execinfo.h>
#include <csignal>
#include <sys/poll.h>
+#ifdef __linux
#include <sys/prctl.h>
+#include <sys/syscall.h>
+#include <sys/vfs.h>
+#else
+#import <Foundation/Foundation.h>
+#endif
#include <sys/stat.h>
#include <sys/uio.h>
-#include <sys/vfs.h>
-#include <sys/syscall.h>
#include <sys/types.h>
#include <unistd.h>
#include <dirent.h>
@@ -288,7 +292,7 @@ namespace Util
static const char *startsWith(const char *line, const char *tag)
{
- int len = strlen(tag);
+ size_t len = strlen(tag);
if (!strncmp(line, tag, len))
{
while (!isdigit(line[len]) && line[len] != '\0')
@@ -492,6 +496,7 @@ namespace Util
{
strncpy(ThreadName, s.c_str(), 31);
ThreadName[31] = '\0';
+#ifdef __linux
if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(s.c_str()), 0, 0, 0) != 0)
LOG_SYS("Cannot set thread name of " << getThreadId() << " (" <<
std::this_thread::get_id() << ") to [" << s << "].");
@@ -499,6 +504,12 @@ namespace Util
LOG_INF("Thread " << getThreadId() << " (" <<
std::this_thread::get_id() <<
") is now called [" << s << "].");
+#else
+ [[NSThread currentThread] setName:[NSString stringWithUTF8String:ThreadName]];
+ LOG_INF("Thread " << getThreadId() << " (" <<
+ std::this_thread::get_id() <<
+ ") is now called [" << s << "].");
+#endif
}
const char *getThreadName()
@@ -506,22 +517,36 @@ namespace Util
// Main process and/or not set yet.
if (ThreadName[0] == '\0')
{
+#ifdef __linux
if (prctl(PR_GET_NAME, reinterpret_cast<unsigned long>(ThreadName), 0, 0, 0) != 0)
ThreadName[0] = '\0';
+#else
+ const char *const name = [[[NSThread currentThread] name] UTF8String];
+ strncpy(ThreadName, name, 31);
+ ThreadName[31] = '\0';
+#endif
}
// Avoid so many redundant system calls
return ThreadName;
}
+#ifdef __linux
static __thread pid_t ThreadTid;
pid_t getThreadId()
+#else
+ std::thread::id getThreadId()
+#endif
{
// Avoid so many redundant system calls
+#ifdef __linux
if (!ThreadTid)
ThreadTid = syscall(SYS_gettid);
return ThreadTid;
+#else
+ return std::this_thread::get_id();
+#endif
}
void getVersionInfo(std::string& version, std::string& hash)
commit d3f0179c967612d509b412c7b55590d85d9dfff1
Author: Tor Lillqvist <tml at iki.fi>
AuthorDate: Wed Aug 29 18:47:05 2018 +0300
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Aug 29 20:39:26 2018 +0300
Make this file compile for iOS
diff --git a/common/Log.cpp b/common/Log.cpp
index 6f398a3eb..761cab9f4 100644
--- a/common/Log.cpp
+++ b/common/Log.cpp
@@ -9,8 +9,12 @@
#include <config.h>
+#ifdef __linux
#include <sys/prctl.h>
#include <sys/syscall.h>
+#else
+#import <Foundation/Foundation.h>
+#endif
#include <unistd.h>
#include <atomic>
@@ -93,6 +97,7 @@ namespace Log
char* prefix(char* buffer, const char* level, bool sigSafe)
{
+#ifdef __linux
long osTid;
char procName[32];
const char *threadName = procName;
@@ -117,6 +122,16 @@ namespace Log
time.hour(), time.minute(), time.second(),
time.millisecond() * 1000 + time.microsecond(),
threadName, level);
+#else
+ Poco::DateTime time;
+ const char *threadName = Util::getThreadName();
+ snprintf(buffer, 1023, "%s %.4u-%.2u-%.2u %.2u:%.2u:%.2u.%.6u [ %s ] %s ",
+ (Source.inited ? Source.id.c_str() : "<shutdown>"),
+ time.year(), time.month(), time.day(),
+ time.hour(), time.minute(), time.second(),
+ time.millisecond() * 1000 + time.microsecond(),
+ threadName, level);
+#endif
return buffer;
}
commit 8209d6cd0e60d28d67506791695379dbb3f1babe
Author: Tor Lillqvist <tml at iki.fi>
AuthorDate: Wed Aug 29 18:23:22 2018 +0300
Commit: Tor Lillqvist <tml at collabora.com>
CommitDate: Wed Aug 29 20:38:40 2018 +0300
Make this file compile for iOS
diff --git a/common/FileUtil.cpp b/common/FileUtil.cpp
index ca319173e..22ca87f0a 100644
--- a/common/FileUtil.cpp
+++ b/common/FileUtil.cpp
@@ -13,7 +13,11 @@
#include <ftw.h>
#include <sys/stat.h>
+#ifdef __linux
#include <sys/vfs.h>
+#else
+#import <Foundation/Foundation.h>
+#endif
#include <chrono>
#include <cstdio>
@@ -238,6 +242,10 @@ namespace FileUtil
if (UnitBase::get().filterCheckDiskSpace(path, hookResult))
return hookResult;
+ // we should be able to run just OK with 5GB
+ constexpr int64_t ENOUGH_SPACE = int64_t(5)*1024*1024*1024;
+
+#ifdef __linux
struct statfs sfs;
if (statfs(path.c_str(), &sfs) == -1)
return true;
@@ -247,14 +255,22 @@ namespace FileUtil
LOG_INF("Filesystem [" << path << "] has " << (freeBytes / 1024 / 1024) <<
" MB free (" << (sfs.f_bavail * 100. / sfs.f_blocks) << "%).");
- // we should be able to run just OK with 5GB
- constexpr int64_t ENOUGH_SPACE = int64_t(5)*1024*1024*1024;
-
if (freeBytes > ENOUGH_SPACE)
return true;
if (static_cast<double>(sfs.f_bavail) / sfs.f_blocks <= 0.05)
return false;
+#else
+ NSDictionary *atDict = [[NSFileManager defaultManager] attributesOfFileSystemForPath:@"/" error:NULL];
+ long long freeSpace = [[atDict objectForKey:NSFileSystemFreeSize] longLongValue];
+ long long totalSpace = [[atDict objectForKey:NSFileSystemSize] longLongValue];
+
+ if (freeSpace > ENOUGH_SPACE)
+ return true;
+
+ if (static_cast<double>(freeSpace) / totalSpace <= 0.05)
+ return false;
+#endif
return true;
}
More information about the Libreoffice-commits
mailing list