Browse Source

Fixed a bug with hanging up

Dmitry Yu Okunev 4 years ago
parent
commit
d892ad3abd
1 changed files with 19 additions and 30 deletions
  1. 19 30
      main.c

+ 19 - 30
main.c

@@ -161,7 +161,7 @@ dump_fetch(history_t *p)
 {
 	uint64_t ts_parse;
 	uint64_t ts_device;
-	uint32_t value;
+//	uint32_t value;
 
 	ts_parse  = get_uint64(dump);
 	while (ts_parse < 1437900000000000000 || ts_parse > 1537900000000000000) {
@@ -175,8 +175,8 @@ dump_fetch(history_t *p)
 	int i = 0;
 	while (i < channelsNum) {
 		p->value[i] = get_uint32(dump);
-		while (value < 0 || value > 1024) {
-			printf("dump_fetch() correction 1\n");
+		while (p->value[i] < 0 || p->value[i] > (1 << Y_BITS)) {
+			printf("dump_fetch() correction 1: p->value[%i] == %u\n", i, p->value[i]);
 			p->value[i] = get_uint32(dump);
 		}
 		i++;
@@ -344,6 +344,7 @@ cb_draw (GtkWidget	*area,
          gpointer	*data)
 {
 	int width, height;
+	printf("cb_draw\n");
 
 	GdkWindow *areaGdkWindow = gtk_widget_get_window(area);
 
@@ -365,12 +366,14 @@ cb_draw (GtkWidget	*area,
 
 	if (history_end >= (double)HISTORY_SIZE*x_userdiv) {
 		//printf("%u %u\n", HISTORY_SIZE, history_end);
-		pthread_mutex_lock(&history_mutex);
 		//cairo_set_source_rgba (cr, 0, 0, 0.3, 0.8);
 		//cairo_set_source_rgba (cr, 0.8, 0.8, 1, 0.8);
 		int x;
 		int y;
 
+		pthread_mutex_lock(&history_mutex);
+		printf("cb_draw: lock()-ed\n");
+
 		//int history_start = history_end - HISTORY_SIZE;
 		int history_start_initial = history_end - (double)HISTORY_SIZE*x_userdiv;
 		int history_start = history_start_initial;
@@ -436,8 +439,9 @@ cb_draw (GtkWidget	*area,
 			}
 
 			if (history_start >= history_end) {
-				printf("Unable to sync end\n");
 				history_end = history_end_initial;
+				printf("Unable to sync end; %u %u\n", history_start, history_end);
+				break;
 			}
 
 			//printf("H: %u %u\n", history_start, history_end);
@@ -511,6 +515,7 @@ cb_draw (GtkWidget	*area,
 
 			chan++;
 		}
+
 		pthread_mutex_unlock(&history_mutex);
 	}
 
@@ -523,26 +528,11 @@ cb_draw (GtkWidget	*area,
 	return TRUE;
 }
 
-void *
-update (void *arg)
-{
-	GtkWidget *area = arg;
-
-	while (running) {
-		printf("update\n");
-		gtk_widget_queue_draw(area);
-		usleep(AUTOUPDATE_USECS);
-	}
-
-	return NULL;
-}
-
 int
 main (int    argc,
       char **argv)
 {
 	pthread_t thread_fetcher;
-	pthread_t thread_autoupdate;
 	char *dumppath = NULL;
 	char tailonly = 0;
 	//sensor_open();
@@ -624,11 +614,6 @@ main (int    argc,
 	                          G_CALLBACK (gtk_widget_queue_draw), area);
 	gtk_widget_show_all (main_window);
 
-	if (pthread_create(&thread_autoupdate, NULL, update, area)) {
-		fprintf(stderr, "Error creating thread\n");
-		return 1;
-	}
-
 	line_colors[0][0] = 1;
 	line_colors[0][1] = 0;
 	line_colors[0][2] = 0;
@@ -726,14 +711,18 @@ main (int    argc,
 
 	arrange_widgets();
 
-	gtk_main ();
+	//gtk_main ();
+
+	while (running) {
+		printf("update %p\n", area);
+		gtk_widget_queue_draw(area);
+		while (gtk_events_pending ())
+			gtk_main_iteration();
+		usleep(AUTOUPDATE_USECS);
+	}
 
 	running = 0;
 
-	if (pthread_join(thread_autoupdate, NULL)) {
-		fprintf(stderr, "Error joining thread\n");
-		return 2;
-	}
 	if (pthread_join(thread_fetcher, NULL)) {
 		fprintf(stderr, "Error joining thread\n");
 		return 2;