if (use_threads && old_pointer != 1) {
SCAN_FATAL(cs); if (use_threads && pointer_mode != 1) {
int scan_for_updates(void) {	int i, tile_count, tile_diffs;	double frac1 = 0.1;   /* tweak parameter to try a 2nd scan_display() */	double frac2 = 0.35;  /* or 3rd */	for (i=0; i < ntiles; i++) {		tile_has_diff[i] = 0;		tile_tried[i] = 0;	}	/*	 * n.b. this program has only been tested so far with	 * tile_x = tile_y = NSCAN = 32!	 */	scan_count++;	scan_count %= NSCAN;	if (scan_count % (NSCAN/4) == 0)  {		/* some periodic maintenance */		if (subwin) {			set_offset();	/* follow the subwindow */		}		if (indexed_colour) {	/* check for changed colormap */			set_colormap();		}	}	/* scan with the initial y to the jitter value from scanlines: */	scan_in_progress = 1;	tile_count = scan_display(scanlines[scan_count], 0);	nap_set(tile_count);	if (fs_factor && frac1 >= fs_frac) {		/* make frac1 < fs_frac if fullscreen updates are enabled */		frac1 = fs_frac/2.0;	}	if (tile_count > frac1 * ntiles) {		/*		 * many tiles have changed, so try a rescan (since it should		 * be short compared to the many upcoming copy_tiles() calls)		 */		/* this check is done to skip the extra scan_display() call */		if (! fs_factor || tile_count <= fs_frac * ntiles) {			int cp, tile_count_old = tile_count;						/* choose a different y shift for the 2nd scan: */			cp = (NSCAN - scan_count) % NSCAN;			tile_count = scan_display(scanlines[cp], 1);			if (tile_count >= (1 + frac2) * tile_count_old) {				/* on a roll... do a 3rd scan */				cp = (NSCAN - scan_count + 7) % NSCAN;				tile_count = scan_display(scanlines[cp], 1);			}		}		scan_in_progress = 0;		/*		 * At some number of changed tiles it is better to just		 * copy the full screen at once.  I.e. time = c1 + m * r1		 * where m is number of tiles, r1 is the copy_tiles()		 * time, and c1 is the scan_display() time: for some m		 * it crosses the full screen update time.		 *		 * We try to predict that crossover with the fs_frac		 * fudge factor... seems to be about 1/2 the total number		 * of tiles.  n.b. this ignores network bandwidth,		 * compression time etc...		 *		 * Use -fs 1.0 to disable on slow links.		 */		if (fs_factor && tile_count > fs_frac * ntiles) {			fb_copy_in_progress = 1;			copy_screen();			fb_copy_in_progress = 0;			if (use_threads && old_pointer != 1) {				pointer(-1, 0, 0, NULL);			}			nap_check(tile_count);			return tile_count;		}	}	scan_in_progress = 0;	/* copy all tiles with differences from display to rfb framebuffer: */	fb_copy_in_progress = 1;	if (single_copytile) {		/*		 * Old way, copy I/O one tile at a time.		 */		tile_diffs = copy_all_tiles();	} else {		/* 		 * New way, does runs of horizontal tiles at once.		 * Note that below, for simplicity, the extra tile finding		 * (e.g. copy_tiles_backward_pass) is done the old way.		 */		tile_diffs = copy_all_tile_runs();	}	/*	 * This backward pass for upward and left tiles complements what	 * was done in copy_all_tiles() for downward and right tiles.	 */	tile_diffs = copy_tiles_backward_pass();	/* Given enough tile diffs, try the islands: */	if (grow_fill && tile_diffs > 4) {		tile_diffs = grow_islands();	}	/* Given enough tile diffs, try the gaps: */	if (gaps_fill && tile_diffs > 4) {		tile_diffs = fill_tile_gaps();	}	fb_copy_in_progress = 0;	if (use_threads && old_pointer != 1) {		/*		 * tell the pointer handler it can process any queued		 * pointer events:		 */		pointer(-1, 0, 0, NULL);	}	if (blackouts) {		/* ignore any diffs in completely covered tiles */		int x, y, n;		for (y=0; y < ntiles_y; y++) {			for (x=0; x < ntiles_x; x++) {				n = x + y * ntiles_x;				if (tile_blackout[n].cover == 2) {					tile_has_diff[n] = 0;				}			}		}	}	hint_updates();	/* use krfb/x0rfbserver hints algorithm */	/* Work around threaded rfbProcessClientMessage() calls timeouts */	if (use_threads) {		ping_clients(tile_diffs);	}	nap_check(tile_diffs);	return tile_diffs;}