UPnPsdk 0.1
Universal Plug and Play +, Software Development Kit
 
Loading...
Searching...
No Matches
pthread.cpp
Go to the documentation of this file.
1// Copyright (C) 2025+ GPL 3 and higher by Ingo Höft, <Ingo@Hoeft-online.de>
2// Redistribution only with this Copyright remark. Last modified: 2025-05-19
3
9#include <UPnPsdk/pthread.hpp>
10#include <UPnPsdk/synclog.hpp>
11
13#include <algorithm> // for std::min()
15
16namespace UPnPsdk {
17
18#if defined(_MSC_VER) || defined(__APPLE__) || defined(DOXYGEN_RUN)
19// Special converter for POSIX thread id from pthread_t to uint64_t for output.
20uint64_t pthread_self() {
21 pthread_t ptid = ::pthread_self();
22 uint64_t threadId = 0;
23 memcpy(&threadId, &ptid, std::min(sizeof(threadId), sizeof(ptid)));
24 return threadId;
25}
26#endif
27
28
30 : m_mutex(a_mutex) {
31 TRACE2(this, " Construct CPthread_scoped_lock (lock pthread mutex)")
32 if (::pthread_mutex_lock(&m_mutex) != 0)
33 throw std::runtime_error(UPnPsdk_LOGEXCEPT(
34 "MSG1152") "The mutex has not been properly initialized.\n");
35}
36
38 TRACE2(this, " Destruct CPthread_scoped_lock (unlock pthread mutex)")
39 if (::pthread_mutex_unlock(&m_mutex) != 0)
40 UPnPsdk_LOGCRIT(
41 "MSG1153") "The mutex has not been properly initialized.\n";
42}
43
44} // namespace UPnPsdk
~CPthread_scoped_lock()
Unlock the mutex that was locked by the constructor.
Definition pthread.cpp:37
CPthread_scoped_lock(::pthread_mutex_t &a_mutex)
Locks given POSIX thread mutex.
Definition pthread.cpp:29
Reengineered Object Oriented UPnP+ program code.
UPnPsdk_VIS uint64_t pthread_self()
Get pthread thread id as unsigned integer.
Definition pthread.cpp:20
Additional functions to manage Posix threads with C++ to be portable.
Define macro for synced logging to the console for detailed info and debug.