* by counting up threads starting at 3, we seem to get what top shows in the LWPID...
authorWilfried Göesgens <willi@citadel.org>
Mon, 7 Jun 2010 21:08:46 +0000 (21:08 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 7 Jun 2010 21:08:46 +0000 (21:08 +0000)
why isn't there always a ct?

citadel/include/ctdl_module.h
citadel/sysdep.c
citadel/threads.c
citadel/threads.h

index 0db356a6ff458356849d397f99929e0e7081265d..21550ed872be44eaa9f0487e28b72a4ffbb17cbc 100644 (file)
@@ -185,6 +185,7 @@ void CtdlThreadAllocTSD(void);
 #define MYCURSORS      (((ThreadTSD*)pthread_getspecific(ThreadKey))->cursors)
 #define MYTID          (((ThreadTSD*)pthread_getspecific(ThreadKey))->tid)
 #define CT             (((ThreadTSD*)pthread_getspecific(ThreadKey))->self)
+#define CTP            ((ThreadTSD*)pthread_getspecific(ThreadKey))
 
 /** return the current context list as an array and do it in a safe manner
  * The returned data is a copy so only reading is useful
index deb7f91826729ffa3c38790c1753a5f048f92d23..a935c410b00cb38125697616b80fa8fc21467ab9 100644 (file)
@@ -122,7 +122,17 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                time_t unixtime;
                StrBuf *lBuf;
                CitContext *CCC = CC;
-               
+               ThreadTSD *cTSD = CTP;
+               CtdlThreadNode *node = NULL;
+               long lwpid = 0;
+
+               if (cTSD != NULL) 
+                       node = cTSD->self;
+               if ((node != NULL) && (node->reltid != 0))
+               {
+                       lwpid = node->pid + node->reltid;
+               }
+
                gettimeofday(&tv, NULL);
                /* Promote to time_t; types differ on some OSes (like darwin) */
                unixtime = tv.tv_sec;
@@ -159,6 +169,12 @@ void vCtdlLogPrintf(enum LogLevel loglevel, const char *format, va_list arg_ptr)
                                     tim.tm_year + 1900, tim.tm_mon + 1,
                                     tim.tm_mday, tim.tm_hour, tim.tm_min,
                                     tim.tm_sec, (long)tv.tv_usec);
+
+                       
+                       if (lwpid != 0)
+                               StrBufAppendPrintf(lBuf,
+                                                  "[LWP:%d] ",
+                                                  lwpid);
                                
                        if (CCC != NULL) {
                                if (CCC->cs_pid != 0)
index fb854bf575280c9a75b47e6e1b0f38ec0d546fcf..f6221019a9e95377935d181d87defa955ad85150 100644 (file)
@@ -58,6 +58,7 @@
  * remove the need for the calls to eCrashRegisterThread and friends
  */
 
+static int next_tid = 3;                        /* offset LWPID to PID */
 static int num_threads = 0;                    /* Current number of threads */
 static int num_workers = 0;                    /* Current number of worker threads */
 long statcount = 0;            /* are we doing a stats check? */
@@ -989,7 +990,8 @@ CtdlThreadNode *ctdl_internal_create_thread(char *name, long flags, void *(*thre
                free(this_thread);
                return NULL;
        }
-       
+       this_thread->reltid = next_tid;
+       next_tid++;
        num_threads++;  // Increase the count of threads in the system.
        if(this_thread->flags & CTDLTHREAD_WORKER)
                num_workers++;
index 4f4830639fd8d3fb05940521d17283a82cbedc07..4103466f5b861d3222b8b2d620c451f705e12024 100644 (file)
@@ -87,6 +87,7 @@ typedef struct CtdlThreadNode CtdlThreadNode;
 struct CtdlThreadNode{
        citthread_t tid;                                /* id as returned by citthread_create() */
        pid_t pid;                              /* pid, as best the OS will let us determine */
+       long reltid;                            /* counting from start... */
        time_t when;                            /* When to start a scheduled thread */
        struct CitContext *Context;             /* The session context that this thread mught be working on or NULL if none */
        long number;                            /* A unigue number for this thread (not implimented yet) */