Esempio n. 1
0
static int main_loop_threaded( allpairs_compare_t funcptr, struct text_list *seta, struct text_list *setb )
{
	int x,i,j,c;

	char *xname[block_size];
	char *xdata[block_size];
	int xdata_length[block_size];

	char *yname[num_cores];
	char *ydata[num_cores];
	int ydata_length[num_cores];

	struct thread_args args[num_cores];
	pthread_t thread[num_cores];

	/* for each block sized vertical stripe... */
	for(x=0;x<text_list_size(seta);x+=block_size) {

		/* load the horizontal members of the stripe */
		for(i=0;i<block_size;i++) {
			xname[i] = text_list_get(seta,x+i);
			xdata[i] = load_one_file(text_list_get(seta,x+i),&xdata_length[i]);
		}

		/* for each row in the stripe ... */
		for(j=0;j<text_list_size(setb);j+=num_cores) {

			/* don't start more threads than rows remaining. */
			int n = MIN(num_cores,text_list_size(setb)-j);

			/* start one thread working on a whole row. */
			for(c=0;c<n;c++) {
				yname[c] = text_list_get(setb,j+c);
				ydata[c] = load_one_file(text_list_get(setb,j+c),&ydata_length[c]);

				args[c].func         = funcptr;
				args[c].xname        = xname;
				args[c].xdata        = xdata;
				args[c].xdata_length = xdata_length;
				args[c].yname	     = yname[c];
				args[c].ydata        = ydata[c];
				args[c].ydata_length = ydata_length[c];
				pthread_create(&thread[c],0,row_loop_threaded,&args[c]);
			}

			/* wait for each one to finish */
			for(c=0;c<n;c++) {
				pthread_join(thread[c],0);
				free(ydata[c]);
			}
		}

		for(i=0;i<block_size;i++) {
			free(xdata[i]);
		}
	}

	return 0;
}
Esempio n. 2
0
static
int load_file(const char *name_) {
    char *name, *slash, *destname;

    /* Get a writable copy of the name */
    name     = alloca(strlen(name_)+1);
    strcpy(name, name_);
    sanitize_filename(name);

    destname = strchr(name, '>');
    if (destname) {
	*destname = 0;
	destname++;
    } else {
	destname = name;
    }

    /* Store the path up to the destination name...  This kinda needs
     * to exist on the front end as well at this point */
    slash = strchr(destname+1, '/'); /* skip leading slash */
    while (slash) {
	*slash = 0;
	if (load_one_file(destname, destname))
	    return -1;
	/* If that one was a symlink, we need to start over again with
	 * the path resulting from following the symlink.  Also, note
	 * that we always follow symlinks embedded in paths. */
	if (load_file_follow_symlink(destname))
	    return -1;
	*slash = '/';
	slash = strchr(slash+1, '/');
    }
    if (load_one_file(name, destname))
	return -1;
    if (follow_symlink && load_file_follow_symlink(destname))
	return -1;
    return 0;
}