summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Högberg2016-09-09 17:55:24 +0000
committerRobert Högberg2016-09-09 17:55:24 +0000
commit1a4d76347af9440f016d6f1e0dc96f55240aa6fb (patch)
tree156890caa508fef9d2a84b31c27558f9a09d6fe7
parent1f0fb2538ba6fc306198fe2a9a4b976d63adb304 (diff)
downloadtelephony-1a4d76347af9440f016d6f1e0dc96f55240aa6fb.tar.gz
yate: Call pthread_key_create when the key is first accessed
pthread_key_create used to be called when a specific static key object was initialized, but if another static object was initialized earlier and this other object needed the key during its initialization yate would crash. Fixes #99 Signed-off-by: Robert Högberg <robert.hogberg@gmail.com>
-rw-r--r--net/yate/patches/120-create-thread-key-on-access.patch49
1 files changed, 49 insertions, 0 deletions
diff --git a/net/yate/patches/120-create-thread-key-on-access.patch b/net/yate/patches/120-create-thread-key-on-access.patch
new file mode 100644
index 0000000..500dc5a
--- /dev/null
+++ b/net/yate/patches/120-create-thread-key-on-access.patch
@@ -0,0 +1,49 @@
+--- a/engine/Thread.cpp
++++ b/engine/Thread.cpp
+@@ -106,21 +106,18 @@ static DWORD getTls()
+ return tls_index;
+ }
+ #else /* _WINDOWS */
+-static pthread_key_t current_key;
+-
+-class ThreadPrivateKeyAlloc
++static pthread_key_t& current_key()
+ {
+-public:
+- ThreadPrivateKeyAlloc()
+- {
+- if (::pthread_key_create(&current_key,ThreadPrivate::destroyFunc)) {
++ static pthread_key_t* current_key = NULL;
++ if (!current_key) {
++ current_key = new pthread_key_t;
++ if (::pthread_key_create(current_key, ThreadPrivate::destroyFunc)) {
+ abortOnBug(true);
+ Debug(DebugFail,"Failed to create current thread key!");
+ }
+ }
+-};
+-
+-static ThreadPrivateKeyAlloc keyAllocator;
++ return *current_key;
++}
+ #endif /* _WINDOWS */
+
+ static TokenDict s_prio[] = {
+@@ -309,7 +306,7 @@ void ThreadPrivate::run()
+ #ifdef _WINDOWS
+ ::TlsSetValue(getTls(),this);
+ #else
+- ::pthread_setspecific(current_key,this);
++ ::pthread_setspecific(current_key(),this);
+ pthread_cleanup_push(cleanupFunc,this);
+ #ifdef PTHREAD_CANCEL_ASYNCHRONOUS
+ ::pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS,0);
+@@ -421,7 +418,7 @@ ThreadPrivate* ThreadPrivate::current()
+ #ifdef _WINDOWS
+ return reinterpret_cast<ThreadPrivate *>(::TlsGetValue(getTls()));
+ #else
+- return reinterpret_cast<ThreadPrivate *>(::pthread_getspecific(current_key));
++ return reinterpret_cast<ThreadPrivate *>(::pthread_getspecific(current_key()));
+ #endif
+ }
+