This is Unofficial EPICS BASE Doxygen Site
osdThreadExtra.c
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * Copyright (c) 2012 ITER Organization
7 * EPICS BASE is distributed subject to a Software License Agreement found
8 * in file LICENSE that is included with this distribution.
9 \*************************************************************************/
10 
11 /* Author: Marty Kraimer Date: 18JAN2000 */
12 
13 /* This differs from the posix implementation of epicsThread by:
14  * - printing the Linux LWP ID instead of the POSIX thread ID in the show routines
15  * - installing a default thread start hook, that sets the Linux thread name to the
16  * EPICS thread name to make it visible on OS level, and discovers the LWP ID */
17 
18 #include <unistd.h>
19 #include <signal.h>
20 #include <string.h>
21 #include <sys/syscall.h>
22 #include <sys/types.h>
23 #include <sys/prctl.h>
24 
25 #include "epicsStdio.h"
26 #include "ellLib.h"
27 #include "epicsEvent.h"
28 #include "epicsThread.h"
29 
30 void epicsThreadShowInfo(epicsThreadId pthreadInfo, unsigned int level)
31 {
32  if (!pthreadInfo) {
33  fprintf(epicsGetStdout(), " NAME EPICS ID "
34  "LWP ID OSIPRI OSSPRI STATE\n");
35  } else {
36  struct sched_param param;
37  int priority = 0;
38 
39  if (pthreadInfo->tid) {
40  int policy;
41  int status = pthread_getschedparam(pthreadInfo->tid, &policy,
42  &param);
43 
44  if (!status)
45  priority = param.sched_priority;
46  }
47  fprintf(epicsGetStdout(),"%16.16s %14p %8lu %3d%8d %8.8s\n",
48  pthreadInfo->name,(void *)
49  pthreadInfo,(unsigned long)pthreadInfo->lwpId,
50  pthreadInfo->osiPriority,priority,
51  pthreadInfo->isSuspended ? "SUSPEND" : "OK");
52  }
53 }
54 
55 static void thread_hook(epicsThreadId pthreadInfo)
56 {
57  /* Set the name of the thread's process. Limited to 16 characters. */
58  char comm[16];
59 
60  if (strcmp(pthreadInfo->name, "_main_")) {
61  snprintf(comm, sizeof(comm), "%s", pthreadInfo->name);
62  prctl(PR_SET_NAME, comm, 0l, 0l, 0l);
63  }
64  pthreadInfo->lwpId = syscall(SYS_gettid);
65 }
66 
pthread_t tid
Definition: osdThread.h:26
unsigned int osiPriority
Definition: osdThread.h:38
pvd::Status status
EPICS_THREAD_HOOK_ROUTINE epicsThreadHookMain
void(* EPICS_THREAD_HOOK_ROUTINE)(epicsThreadId id)
Definition: epicsThread.h:302
A doubly-linked list library.
FILE *epicsStdCall epicsGetStdout(void)
Definition: epicsStdio.c:47
APIs for the epicsEvent binary semaphore.
EPICS_THREAD_HOOK_ROUTINE epicsThreadHookDefault
char name[1]
Definition: osdThread.h:40
int snprintf(char *str, size_t size, const char *format,...)
C++ and C descriptions for a thread.
void epicsThreadShowInfo(epicsThreadId pthreadInfo, unsigned int level)