Browse Source

Lower thread stack to 128k

Georgi Chorbadzhiyski 12 years ago
parent
commit
40a64d59b6
5 changed files with 26 additions and 4 deletions
  1. 1
    1
      camd.c
  2. 8
    0
      data.c
  3. 5
    0
      data.h
  4. 1
    1
      notify.c
  5. 11
    2
      tsdecrypt.c

+ 1
- 1
camd.c View File

296
 		c->req_queue = queue_new();
296
 		c->req_queue = queue_new();
297
 		c->ecm_queue = queue_new();
297
 		c->ecm_queue = queue_new();
298
 		c->emm_queue = queue_new();
298
 		c->emm_queue = queue_new();
299
-		pthread_create(&c->thread, NULL , &camd_thread, ts);
299
+		pthread_create(&c->thread, &ts->thread_attr , &camd_thread, ts);
300
 	}
300
 	}
301
 }
301
 }
302
 
302
 

+ 8
- 0
data.c View File

105
 	ts->write_buf   = cbuf_init((7 * dvbcsa_bs_batch_size() * 188) *  8, "write");  // ~324Kb
105
 	ts->write_buf   = cbuf_init((7 * dvbcsa_bs_batch_size() * 188) *  8, "write");  // ~324Kb
106
 
106
 
107
 	ts->input_buffer= list_new("input");
107
 	ts->input_buffer= list_new("input");
108
+
109
+	pthread_attr_init(&ts->thread_attr);
110
+	size_t stack_size;
111
+	pthread_attr_getstacksize(&ts->thread_attr, &stack_size);
112
+	if (stack_size > THREAD_STACK_SIZE)
113
+		pthread_attr_setstacksize(&ts->thread_attr, THREAD_STACK_SIZE);
108
 }
114
 }
109
 
115
 
110
 void data_free(struct ts *ts) {
116
 void data_free(struct ts *ts) {
143
 	// and in order to avoid leaking 43 bytes of memory on exit which makes valgrind
149
 	// and in order to avoid leaking 43 bytes of memory on exit which makes valgrind
144
 	// unhappy it is a good idea to free the memory (ONCE!).
150
 	// unhappy it is a good idea to free the memory (ONCE!).
145
 	FREE(ts->camd.newcamd.crypt_passwd);
151
 	FREE(ts->camd.newcamd.crypt_passwd);
152
+
153
+	pthread_attr_destroy(&ts->thread_attr);
146
 }
154
 }

+ 5
- 0
data.h View File

42
 #define ECM_QUEUE_HARD_LIMIT 10
42
 #define ECM_QUEUE_HARD_LIMIT 10
43
 #define ECM_QUEUE_SOFT_LIMIT 3
43
 #define ECM_QUEUE_SOFT_LIMIT 3
44
 
44
 
45
+// 64k should be enough for everybody
46
+#define THREAD_STACK_SIZE (64 * 1024)
47
+
45
 struct notify {
48
 struct notify {
46
 	pthread_t	thread;				/* Thread handle */
49
 	pthread_t	thread;				/* Thread handle */
47
 	QUEUE		*notifications;		/* Notification queue */
50
 	QUEUE		*notifications;		/* Notification queue */
273
 
276
 
274
 	int					threaded;
277
 	int					threaded;
275
 
278
 
279
+	pthread_attr_t		thread_attr;
280
+
276
 	int					decode_stop;
281
 	int					decode_stop;
277
 	pthread_t			decode_thread;
282
 	pthread_t			decode_thread;
278
 	CBUF				*decode_buf;
283
 	CBUF				*decode_buf;

+ 1
- 1
notify.c View File

128
 	}
128
 	}
129
 	strncpy(n->program, ts->notify_program, sizeof(n->program) - 1);
129
 	strncpy(n->program, ts->notify_program, sizeof(n->program) - 1);
130
 	n->program[sizeof(n->program) - 1] = '\0';
130
 	n->program[sizeof(n->program) - 1] = '\0';
131
-	pthread_create(&n->thread, NULL , &notify_thread, n);
131
+	pthread_create(&n->thread, &ts->thread_attr , &notify_thread, n);
132
 	return n;
132
 	return n;
133
 }
133
 }
134
 
134
 

+ 11
- 2
tsdecrypt.c View File

25
 #include <fcntl.h>
25
 #include <fcntl.h>
26
 #include <errno.h>
26
 #include <errno.h>
27
 #include <syslog.h>
27
 #include <syslog.h>
28
+#include <sys/resource.h>
28
 
29
 
29
 #include <dvbcsa/dvbcsa.h>
30
 #include <dvbcsa/dvbcsa.h>
30
 #include <openssl/rand.h>
31
 #include <openssl/rand.h>
780
 	int ntimeouts = 0;
781
 	int ntimeouts = 0;
781
 	time_t timeout_start = time(NULL);
782
 	time_t timeout_start = time(NULL);
782
 	int rtp_hdr_pos = 0, num_packets = 0;
783
 	int rtp_hdr_pos = 0, num_packets = 0;
784
+	struct rlimit rl;
785
+
786
+	if (getrlimit(RLIMIT_STACK, &rl) == 0) {
787
+		if (rl.rlim_cur > THREAD_STACK_SIZE) {
788
+			rl.rlim_cur = THREAD_STACK_SIZE;
789
+			setrlimit(RLIMIT_STACK, &rl);
790
+		}
791
+	}
783
 
792
 
784
 	memset(rtp_hdr[0], 0, RTP_HDR_SZ);
793
 	memset(rtp_hdr[0], 0, RTP_HDR_SZ);
785
 	memset(rtp_hdr[1], 0, RTP_HDR_SZ);
794
 	memset(rtp_hdr[1], 0, RTP_HDR_SZ);
820
 	signal(SIGTERM, signal_quit);
829
 	signal(SIGTERM, signal_quit);
821
 
830
 
822
 	if (ts.threaded) {
831
 	if (ts.threaded) {
823
-		pthread_create(&ts.decode_thread, NULL, &decode_thread, &ts);
824
-		pthread_create(&ts.write_thread, NULL , &write_thread , &ts);
832
+		pthread_create(&ts.decode_thread, &ts.thread_attr, &decode_thread, &ts);
833
+		pthread_create(&ts.write_thread , &ts.thread_attr, &write_thread , &ts);
825
 	}
834
 	}
826
 
835
 
827
 	ts.emm_last_report = time(NULL) + FIRST_REPORT_SEC;
836
 	ts.emm_last_report = time(NULL) + FIRST_REPORT_SEC;

Loading…
Cancel
Save