mirror of
https://github.com/pocoproject/poco.git
synced 2025-01-19 08:46:41 +01:00
fix: aix build #4742
This commit is contained in:
parent
c735162abc
commit
82c17ea813
@ -160,8 +160,10 @@ else()
|
||||
target_compile_definitions(Foundation PUBLIC POCO_HAVE_FD_POLL)
|
||||
target_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt)
|
||||
elseif("${CMAKE_SYSTEM_NAME}" STREQUAL "AIX" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "GNU")
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_compile_definitions(Foundation PUBLIC _XOPEN_SOURCE=500 POCO_HAVE_FD_POLL)
|
||||
target_link_libraries(Foundation PUBLIC pthread ${CMAKE_DL_LIBS} rt)
|
||||
target_link_libraries(Foundation PUBLIC ${CMAKE_DL_LIBS} rt Threads::Threads)
|
||||
else()
|
||||
target_compile_definitions(Foundation PUBLIC _XOPEN_SOURCE=500 POCO_HAVE_FD_EPOLL)
|
||||
target_link_libraries(Foundation PUBLIC pthread atomic ${CMAKE_DL_LIBS} rt)
|
||||
@ -206,6 +208,11 @@ if(${CMAKE_CXX_COMPILER_ID} MATCHES "SunPro")
|
||||
target_compile_options(Foundation PUBLIC -library=stlport4)
|
||||
endif()
|
||||
|
||||
# AIX
|
||||
if("${CMAKE_SYSTEM_NAME}" STREQUAL "AIX")
|
||||
target_compile_definitions(Foundation PUBLIC POCO_NO_THREADNAME)
|
||||
endif()
|
||||
|
||||
# iOS
|
||||
if(IOS)
|
||||
target_compile_definitions(Foundation
|
||||
|
@ -64,10 +64,12 @@ public:
|
||||
TIDImpl tidImpl() const;
|
||||
void setNameImpl(const std::string& threadName);
|
||||
std::string getNameImpl() const;
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
std::string getOSThreadNameImpl();
|
||||
/// Returns the thread's name, expressed as an operating system
|
||||
/// specific name value. Return empty string if thread is not running.
|
||||
/// For test used only.
|
||||
#endif
|
||||
void setPriorityImpl(int prio);
|
||||
int getPriorityImpl() const;
|
||||
void setOSPriorityImpl(int prio, int policy = SCHED_OTHER);
|
||||
|
@ -91,6 +91,7 @@ namespace
|
||||
return name;
|
||||
}
|
||||
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
void setThreadName(const std::string& threadName)
|
||||
/// Sets thread name. Support for this feature varies
|
||||
/// on platforms. Any errors are ignored.
|
||||
@ -134,6 +135,7 @@ namespace
|
||||
#endif
|
||||
return name;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -191,10 +193,12 @@ std::string ThreadImpl::getNameImpl() const
|
||||
}
|
||||
|
||||
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
std::string ThreadImpl::getOSThreadNameImpl()
|
||||
{
|
||||
return isRunningImpl() ? getThreadName() : "";
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void ThreadImpl::setPriorityImpl(int prio)
|
||||
@ -430,13 +434,17 @@ void* ThreadImpl::runnableEntry(void* pThread)
|
||||
#endif
|
||||
|
||||
ThreadImpl* pThreadImpl = reinterpret_cast<ThreadImpl*>(pThread);
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
setThreadName(reinterpret_cast<Thread*>(pThread)->getName());
|
||||
#endif
|
||||
AutoPtr<ThreadData> pData = pThreadImpl->_pData;
|
||||
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
{
|
||||
FastMutex::ScopedLock lock(pData->mutex);
|
||||
setThreadName(pData->name);
|
||||
}
|
||||
#endif
|
||||
|
||||
try
|
||||
{
|
||||
|
@ -43,8 +43,10 @@ public:
|
||||
if (pThread)
|
||||
{
|
||||
_threadName = pThread->name();
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
auto *pThreadImpl = reinterpret_cast<Poco::ThreadImpl *>(pThread);
|
||||
_osThreadName = pThreadImpl->getOSThreadNameImpl();
|
||||
#endif
|
||||
}
|
||||
_ran = true;
|
||||
_event.wait();
|
||||
@ -60,10 +62,12 @@ public:
|
||||
return _threadName;
|
||||
}
|
||||
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
const std::string& osThreadName() const
|
||||
{
|
||||
return _osThreadName;
|
||||
}
|
||||
#endif
|
||||
|
||||
void notify()
|
||||
{
|
||||
@ -80,7 +84,9 @@ public:
|
||||
private:
|
||||
bool _ran;
|
||||
std::string _threadName;
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
std::string _osThreadName;
|
||||
#endif
|
||||
Event _event;
|
||||
};
|
||||
|
||||
@ -209,7 +215,9 @@ void ThreadTest::testThread()
|
||||
assertTrue (!thread.isRunning());
|
||||
assertTrue (r.ran());
|
||||
assertTrue (!r.threadName().empty());
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
assertTrue (!r.osThreadName().empty());
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -222,7 +230,9 @@ void ThreadTest::testNamedThread()
|
||||
thread.join();
|
||||
assertTrue (r.ran());
|
||||
assertTrue (r.threadName() == "MyThread");
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
assertTrue (r.osThreadName() == r.threadName());
|
||||
#endif
|
||||
|
||||
// name len > POCO_MAX_THREAD_NAME_LEN
|
||||
Thread thread2("0123456789aaaaaaaaaa9876543210");
|
||||
@ -231,7 +241,9 @@ void ThreadTest::testNamedThread()
|
||||
r2.notify();
|
||||
thread2.join();
|
||||
assertTrue (r2.ran());
|
||||
#ifndef POCO_NO_THREADNAME
|
||||
assertTrue (r2.osThreadName() == r2.threadName());
|
||||
#endif
|
||||
assertTrue (r2.threadName().length() <= POCO_MAX_THREAD_NAME_LEN);
|
||||
assertTrue (std::string(r2.threadName(), 0, 7) == "0123456");
|
||||
assertTrue (std::string(r2.threadName(), r2.threadName().size() - 7) == "6543210");
|
||||
|
@ -1440,7 +1440,11 @@ Int64 SocketImpl::sendFile(FileInputStream &fileInputStream, UInt64 offset)
|
||||
UInt64 fileSize = fileInputStream.size();
|
||||
std::streamoff sentSize = fileSize - offset;
|
||||
Int64 sent = 0;
|
||||
sighandler_t sigPrev = signal(SIGPIPE, SIG_IGN);
|
||||
struct sigaction sa, old_sa;
|
||||
sa.sa_handler = SIG_IGN;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
sa.sa_flags = 0;
|
||||
sigaction(SIGPIPE, &sa, &old_sa);
|
||||
while (sent == 0)
|
||||
{
|
||||
errno = 0;
|
||||
@ -1450,7 +1454,11 @@ Int64 SocketImpl::sendFile(FileInputStream &fileInputStream, UInt64 offset)
|
||||
error(errno, std::string("[sendfile error]") + Error::getMessage(errno));
|
||||
}
|
||||
}
|
||||
signal(SIGPIPE, sigPrev != SIG_ERR ? sigPrev : SIG_DFL);
|
||||
if(old_sa.sa_handler == SIG_ERR)
|
||||
{
|
||||
old_sa.sa_handler = SIG_DFL;
|
||||
}
|
||||
sigaction(SIGPIPE, &old_sa, nullptr);
|
||||
return sent;
|
||||
}
|
||||
#endif // POCO_OS_FAMILY_WINDOWS
|
||||
|
Loading…
x
Reference in New Issue
Block a user