[glibmm] Threads: Add create(slot, name).
- From: Kjell Ahlstedt <kjellahl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Threads: Add create(slot, name).
- Date: Wed, 12 Dec 2012 14:03:29 +0000 (UTC)
commit 75a912ddf9365db9dafb291d11b5513136a81559
Author: Andrew Potter <agpotter gmail com>
Date: Wed Dec 12 14:59:11 2012 +0100
Threads: Add create(slot, name).
* glib/src/threads.{ccg,hg}: Add a method to create named threads.
Bug #689863.
ChangeLog | 8 ++++++++
glib/src/threads.ccg | 17 ++++++++++++++---
glib/src/threads.hg | 26 ++++++++++++++++++++++++++
3 files changed, 48 insertions(+), 3 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index d63742f..7860a8e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2012-12-12 Andrew Potter <agpotter gmail com>
+
+ Threads: Add create(slot, name).
+
+ * glib/src/threads.{ccg,hg}: Add a method to create named threads.
+
+ Bug #689863.
+
2012-11-20 Andrew Potter <agpotter gmail com>
VariantType: Add create_tuple().
diff --git a/glib/src/threads.ccg b/glib/src/threads.ccg
index eb0c0f5..d417a98 100644
--- a/glib/src/threads.ccg
+++ b/glib/src/threads.ccg
@@ -62,15 +62,20 @@ namespace Threads
/**** Glib::Thread *********************************************************/
// static
-Thread* Thread::create(const sigc::slot<void>& slot)
+Thread* Thread::create(const sigc::slot<void>& slot, const std::string& name)
{
// Make a copy of slot on the heap
sigc::slot_base *const slot_copy = new sigc::slot<void>(slot);
GError* error = 0;
+ GThread* thread;
- GThread *const thread = g_thread_try_new(NULL,
- &call_thread_entry_slot, slot_copy, &error);
+ if (name.size() > 0)
+ thread = g_thread_try_new(name.c_str(), &call_thread_entry_slot,
+ slot_copy, &error);
+ else
+ thread = g_thread_try_new(NULL, &call_thread_entry_slot,
+ slot_copy, &error);
if(error)
{
@@ -82,6 +87,12 @@ Thread* Thread::create(const sigc::slot<void>& slot)
}
// static
+Thread* Thread::create(const sigc::slot<void>& slot)
+{
+ return create(slot, std::string());
+}
+
+// static
Thread* Thread::self()
{
return reinterpret_cast<Thread*>(g_thread_self());
diff --git a/glib/src/threads.hg b/glib/src/threads.hg
index 01de968..c797975 100644
--- a/glib/src/threads.hg
+++ b/glib/src/threads.hg
@@ -89,6 +89,32 @@ public:
*/
static Thread* create(const sigc::slot<void>& slot);
+ // TODO: At next ABI break, remove the single parameter create
+ // method and default name to std::string()
+
+ /** Creates a new named thread.
+ * You can wait for this thread's termination by calling join().
+ *
+ * The new thread executes the function or method @a slot points to. You can
+ * pass additional arguments using sigc::bind(). If the thread was created
+ * successfully, it is returned, otherwise a Threads::ThreadError exception is thrown.
+ *
+ * Because sigc::trackable is not thread safe, if the slot represents a
+ * non-static class method (that is, it is created by sigc::mem_fun()), the
+ * class concerned should not derive from sigc::trackable.
+ *
+ * The @a name can be useful for discriminating threads in a debugger.
+ * Some systems restrict the length of @a name to 16 bytes.
+ *
+ * @param slot A slot to execute in the new thread.
+ * @param name A name for the new thread.
+ * @return The new Thread* on success.
+ * @throw Glib::Threads::ThreadError
+ *
+ * @newin{2,36}
+ */
+ static Thread* create(const sigc::slot<void>& slot, const std::string& name);
+
/** Returns the Thread* corresponding to the calling thread.
* @return The current thread.
*/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]