public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
* [ECOS] Posix Thread name
@ 2004-05-04  3:14 Tony Butt
  2004-05-13 14:00 ` Andrew Lunn
  0 siblings, 1 reply; 6+ messages in thread
From: Tony Butt @ 2004-05-04  3:14 UTC (permalink / raw)
  To: ecos-discuss

[-- Attachment #1: Type: text/plain, Size: 554 bytes --]

I had a requirement to be able to explicitly set the name of a posix thread,
made some simple changes to posix/current/src/pthread.cxx and
posix/current/include/types.h, and can now optionally set the name of a
posix thread created using pthread_create.

The name is set by assigning a value to pthread_attr.name before calling
pthread_create().

A patch to do this is attached. If this should be sent anywhere else, please
let me know...

Tony Butt
Software Engineer
CEA Technologies

tjb@cea.com.au
Ph:  02 62130195 
Fax: 02 62130013

[-- Attachment #2: pthread_name.diff --]
[-- Type: application/octet-stream, Size: 1891 bytes --]

--- ecos-2.0/packages/compat/posix/current/include/types.h	2004-05-04 11:56:10.902735600 +1000
+++ ecos-2.0.old/packages/compat/posix/current/include/types.h	2002-05-24 08:59:58.000000000 +1000
@@ -93,7 +93,6 @@
     struct sched_param  schedparam;
     void                *stackaddr;
     size_t              stacksize;
-    char *		name;
 } pthread_attr_t;
 
 // Values for detachstate
--- ecos-2.0/packages/compat/posix/current/src/pthread.cxx	2004-05-04 12:04:38.193725400 +1000
+++ ecos-2.0.old/packages/compat/posix/current/src/pthread.cxx	2004-04-02 13:35:05.000000000 +1000
@@ -594,27 +594,18 @@
     // generate a name for this thread
 
     char *name = nthread->name;
-    if (use_attr.name) {
-	int i;
-	for (i = 0 ; use_attr.name[i] && (i < 16) ; i++)
-	    name[i] = use_attr.name[i];
-	name[i] = '\0'; // Null terminate the name...
-    }
-    else {
-	static char *name_template = "pthread.00000000";
-	pthread_t id = nthread->id;
-	int i;
-    
-	for( i = 0; name_template[i]; i++ ) name[i] = name_template[i];
-	name[i] = '\0'; // Null terminate the name...
-
-	// dump the id, in hex into the name.
-	for( i = 15; i >= 8; i-- )
-	    {
-		name[i] = "0123456789ABCDEF"[id&0xF];
-		id >>= 4;
-	    }
+    static char *name_template = "pthread.00000000";
+    pthread_t id = nthread->id;
+    
+    for( int i = 0; name_template[i]; i++ ) name[i] = name_template[i];
+
+    // dump the id, in hex into the name.
+    for( int i = 15; i >= 8; i-- )
+    {
+        name[i] = "0123456789ABCDEF"[id&0xF];
+        id >>= 4;
     }
+
 #endif
 
     // Initialize the joiner condition variable
@@ -969,7 +960,6 @@
     attr->stackaddr                   = NULL;
     attr->stacksize_valid             = 0;    
     attr->stacksize                   = 0;
-    attr->name			      = NULL;
     
     PTHREAD_RETURN(0);
 }


[-- Attachment #3: Type: text/plain, Size: 148 bytes --]

-- 
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-05-17  4:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-04  3:14 [ECOS] Posix Thread name Tony Butt
2004-05-13 14:00 ` Andrew Lunn
2004-05-13 14:08   ` Tim Sohacki
2004-05-13 21:02     ` Dan Jakubiec
2004-05-17  9:41   ` Tony Butt
2004-05-17 11:06     ` Tony Butt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).