mirror of
https://git.FreeBSD.org/ports.git
synced 2025-01-05 06:27:37 +00:00
Improve pthread cancellation and update comments.
This commit is contained in:
parent
8240947413
commit
773071c6f0
Notes:
svn2git
2021-03-31 03:12:20 +00:00
svn path=/head/; revision=261751
@ -4,21 +4,23 @@ This patch works around POSIX thread implementation differences between
|
||||
FreeBSD's libthr and Linux's NPTL:
|
||||
|
||||
- We do not support static allocations of mutex and condition variable.
|
||||
Thus, we must initialize them explicitly with pthread_mutex_init(3) and
|
||||
pthread_cond_init(3), respectively.
|
||||
Instead, they are allocated dynamically when they are used for the first
|
||||
time if they are properly initialized with PTHREAD_MUTEX_INITIALIZER and
|
||||
PTHREAD_COND_INITIALIZER. Thus, we explicitly initialize and destroy
|
||||
them to be safer.
|
||||
|
||||
- We must initialize mutex before calling pthread_cond_wait(3). Otherwise,
|
||||
it fails with EINVAL.
|
||||
|
||||
- We must lock mutex before calling pthread_cond_wait(3). Otherwise, it
|
||||
fails with EPERM.
|
||||
fails with EPERM. This is a POSIX requirement.
|
||||
|
||||
- We must join threads via pthread_join(3) after calling pthread_cancel(3).
|
||||
Otherwise, we may destroy mutex or condition variable in use.
|
||||
|
||||
--- icedtea6-1.9/plugin/icedteanp/IcedTeaNPPlugin.cc.orig 2010-09-23 09:40:49.000000000 -0400
|
||||
+++ icedtea6-1.9/plugin/icedteanp/IcedTeaNPPlugin.cc 2010-09-23 15:31:27.000000000 -0400
|
||||
@@ -2369,6 +2369,10 @@ NP_Shutdown (void)
|
||||
--- icedtea6-1.9/plugin/icedteanp/IcedTeaNPPlugin.cc.orig 2010-08-06 07:05:21.916103000 -0400
|
||||
+++ icedtea6-1.9/plugin/icedteanp/IcedTeaNPPlugin.cc 2010-09-23 21:52:17.000000000 -0400
|
||||
@@ -2355,6 +2355,10 @@ NP_Shutdown (void)
|
||||
pthread_cancel(plugin_request_processor_thread2);
|
||||
pthread_cancel(plugin_request_processor_thread3);
|
||||
|
||||
@ -29,8 +31,8 @@ Otherwise, we may destroy mutex or condition variable in use.
|
||||
java_to_plugin_bus->unSubscribe(plugin_req_proc);
|
||||
plugin_to_java_bus->unSubscribe(java_req_proc);
|
||||
//internal_bus->unSubscribe(java_req_proc);
|
||||
--- icedtea6-1.9/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc.orig 2010-09-23 09:40:49.000000000 -0400
|
||||
+++ icedtea6-1.9/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc 2010-09-23 15:36:38.000000000 -0400
|
||||
--- icedtea6-1.9/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc.orig 2010-08-06 07:05:21.996828000 -0400
|
||||
+++ icedtea6-1.9/plugin/icedteanp/IcedTeaPluginRequestProcessor.cc 2010-09-23 22:01:37.000000000 -0400
|
||||
@@ -63,6 +63,12 @@ PluginRequestProcessor::PluginRequestPro
|
||||
this->pendingRequests = new std::map<pthread_t, uintmax_t>();
|
||||
|
||||
@ -57,7 +59,22 @@ Otherwise, we may destroy mutex or condition variable in use.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -709,10 +721,12 @@ queue_processor(void* data)
|
||||
@@ -701,6 +713,14 @@ PluginRequestProcessor::finalize(std::ve
|
||||
plugin_to_java_bus->post(response.c_str());
|
||||
}
|
||||
|
||||
+static void
|
||||
+queue_cleanup(void* data)
|
||||
+{
|
||||
+
|
||||
+ pthread_mutex_destroy((pthread_mutex_t*) data);
|
||||
+
|
||||
+ PLUGIN_DEBUG("Queue processing stopped.\n");
|
||||
+}
|
||||
|
||||
void*
|
||||
queue_processor(void* data)
|
||||
@@ -709,10 +729,14 @@ queue_processor(void* data)
|
||||
PluginRequestProcessor* processor = (PluginRequestProcessor*) data;
|
||||
std::vector<std::string*>* message_parts = NULL;
|
||||
std::string command;
|
||||
@ -67,11 +84,13 @@ Otherwise, we may destroy mutex or condition variable in use.
|
||||
PLUGIN_DEBUG("Queue processor initialized. Queue = %p\n", message_queue);
|
||||
|
||||
+ pthread_mutex_init(&wait_mutex, NULL);
|
||||
+
|
||||
+ pthread_cleanup_push(queue_cleanup, (void*) &wait_mutex);
|
||||
+
|
||||
while (true)
|
||||
{
|
||||
pthread_mutex_lock(&message_queue_mutex);
|
||||
@@ -780,13 +794,17 @@ queue_processor(void* data)
|
||||
@@ -780,14 +804,17 @@ queue_processor(void* data)
|
||||
|
||||
} else
|
||||
{
|
||||
@ -80,14 +99,15 @@ Otherwise, we may destroy mutex or condition variable in use.
|
||||
+ pthread_mutex_lock(&wait_mutex);
|
||||
+ pthread_cond_wait(&cond_message_available, &wait_mutex);
|
||||
+ pthread_mutex_unlock(&wait_mutex);
|
||||
+ pthread_testcancel();
|
||||
}
|
||||
|
||||
message_parts = NULL;
|
||||
+
|
||||
+ pthread_testcancel();
|
||||
}
|
||||
|
||||
+ pthread_mutex_destroy(&wait_mutex);
|
||||
+
|
||||
PLUGIN_DEBUG("Queue processing stopped.\n");
|
||||
- PLUGIN_DEBUG("Queue processing stopped.\n");
|
||||
+ pthread_cleanup_pop(1);
|
||||
}
|
||||
|
||||
/******************************************
|
||||
|
Loading…
Reference in New Issue
Block a user