Browse Source

Set thread names under Linux.

Georgi Chorbadzhiyski 12 years ago
parent
commit
03a3b7538d
6 changed files with 30 additions and 0 deletions
  1. 1
    0
      ChangeLog
  2. 3
    0
      camd.c
  3. 3
    0
      notify.c
  4. 5
    0
      process.c
  5. 17
    0
      util.c
  6. 1
    0
      util.h

+ 1
- 0
ChangeLog View File

@@ -1,4 +1,5 @@
1 1
 xxxx-xx-xx : Version -next
2
+ * Set thread names under Linux.
2 3
  * notify: Added no_code_word/code_word_ok events.
3 4
  * notify: Added input_timeout/input_ok events.
4 5
  * notify: Added start/stop events.

+ 3
- 0
camd.c View File

@@ -338,6 +338,9 @@ void camd_msg_free(struct camd_msg **pmsg) {
338 338
 
339 339
 static void *camd_thread(void *in_ts) {
340 340
 	struct ts *ts = in_ts;
341
+
342
+	set_thread_name("tsdec-camd");
343
+
341 344
 	while (1) {
342 345
 		struct camd_msg *msg;
343 346
 		void *req = queue_get(ts->camd35.req_queue); // Waits...

+ 3
- 0
notify.c View File

@@ -33,6 +33,7 @@
33 33
 #include "libfuncs/queue.h"
34 34
 
35 35
 #include "notify.h"
36
+#include "util.h"
36 37
 
37 38
 struct npriv {
38 39
 	char	ident[512];
@@ -88,6 +89,8 @@ OUT:
88 89
 static void *notify_thread(void *data) {
89 90
 	struct notify *n = data;
90 91
 
92
+	set_thread_name("tsdec-notify");
93
+
91 94
 	while (1) {
92 95
 		struct npriv *np = queue_get(n->notifications); // Waits...
93 96
 		if (!np)

+ 5
- 0
process.c View File

@@ -20,6 +20,7 @@
20 20
 
21 21
 #include "data.h"
22 22
 #include "tables.h"
23
+#include "util.h"
23 24
 
24 25
 static unsigned long ts_pack;
25 26
 static int ts_pack_shown;
@@ -178,6 +179,8 @@ void *decode_thread(void *_ts) {
178 179
 	int data_size;
179 180
 	int req_size = 188 * dvbcsa_bs_batch_size();
180 181
 
182
+	set_thread_name("tsdec-decode");
183
+
181 184
 	while (!ts->decode_stop) {
182 185
 		data = cbuf_peek(ts->decode_buf, req_size, &data_size);
183 186
 		if (data_size < req_size) {
@@ -203,6 +206,8 @@ void *write_thread(void *_ts) {
203 206
 	uint8_t *data;
204 207
 	int data_size;
205 208
 
209
+	set_thread_name("tsdec-write");
210
+
206 211
 	while (!ts->write_stop) {
207 212
 		data_size = 0;
208 213
 		data = cbuf_peek(ts->write_buf, FRAME_SIZE, &data_size);

+ 17
- 0
util.c View File

@@ -15,6 +15,9 @@
15 15
  * along with this program; if not, write to the Free Software
16 16
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
17 17
  */
18
+
19
+#include <string.h>
20
+
18 21
 #include "util.h"
19 22
 
20 23
 static unsigned long crc_table[256] = {
@@ -118,3 +121,17 @@ uint8_t *init_2b(uint32_t val, uint8_t *b) {
118 121
 	b[1] = (val     ) & 0xff;
119 122
 	return b;
120 123
 }
124
+
125
+#ifdef __linux__
126
+#include <sys/prctl.h>
127
+
128
+void set_thread_name(char *thread_name) {
129
+	prctl(PR_SET_NAME, thread_name, NULL, NULL, NULL);
130
+}
131
+
132
+#else
133
+void set_thread_name(char *thread_name) {
134
+    (void)thread_name;
135
+}
136
+
137
+#endif

+ 1
- 0
util.h View File

@@ -25,5 +25,6 @@ int32_t boundary(int32_t exp, int32_t n);
25 25
 uint8_t *init_4b(uint32_t val, uint8_t *b);
26 26
 uint8_t *init_4l(uint32_t val, uint8_t *b);
27 27
 uint8_t *init_2b(uint32_t val, uint8_t *b);
28
+void set_thread_name(char *thread_name);
28 29
 
29 30
 #endif

Loading…
Cancel
Save