Commit 226274b2 authored by Oliver Heidmann's avatar Oliver Heidmann
Browse files

moved thread creation from pstreamOpenReadPipe into its own function

parent 0dcc5586
......@@ -285,6 +285,50 @@ int pstreamIsPipe(int pstreamID)
return pstreamptr->ispipe;
}
static void createPipeName(char *pipename, int pnlen){
snprintf(pipename, pnlen, "(pipe%d.%d)", processSelf() + 1, processInqChildNum() + 1);
}
static int pCreateReadThread(char *newarg, argument_t *argument, const char *operatorName){
pthread_attr_t attr;
int status = pthread_attr_init(&attr);
if ( status ) SysError("pthread_attr_init failed for '%s'", newarg+1);
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
if ( status ) SysError("pthread_attr_setdetachstate failed for '%s'", newarg+1);
/*
param.sched_priority = 0;
status = pthread_attr_setschedparam(&attr, &param);
if ( status ) SysError("pthread_attr_setschedparam failed for '%s'", newarg+1);
*/
/* status = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); */
/* if ( status ) SysError("pthread_attr_setinheritsched failed for '%s'", newarg+1); */
pthread_attr_getscope(&attr, &pthreadScope);
/* status = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); */
/* if ( status ) SysError("pthread_attr_setscope failed for '%s'", newarg+1); */
/* If system scheduling scope is specified, then the thread is scheduled against all threads in the system */
/* pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); */
size_t stacksize = 0;
status = pthread_attr_getstacksize(&attr, &stacksize);
if ( stacksize < 2097152 )
{
stacksize = 2097152;
pthread_attr_setstacksize(&attr, stacksize);
}
pthread_t thrID;
int rval = pthread_create(&thrID, &attr, operatorModule(operatorName), argument);
if ( rval != 0 )
{
errno = rval;
SysError("pthread_create failed for '%s'", newarg+1);
}
return thrID;
}
static
void pstreamOpenReadPipe(const argument_t *argument, pstream_t *pstreamptr)
{
......@@ -306,7 +350,7 @@ void pstreamOpenReadPipe(const argument_t *argument, pstream_t *pstreamptr)
size_t len = strlen(argument->args);
char *newarg = (char*) Malloc(len+pnlen);
strcpy(newarg, argument->args);
snprintf(pipename, pnlen, "(pipe%d.%d)", processSelf() + 1, processInqChildNum() + 1);
createPipeName(pipename, pnlen);
newarg[len] = ' ';
strcpy(&newarg[len+1], pipename);
......@@ -323,45 +367,10 @@ void pstreamOpenReadPipe(const argument_t *argument, pstream_t *pstreamptr)
pstreamptr->pipe = pipeNew();
pstreamptr->argument = (void *) newargument;
if ( ! cdoSilentMode )
if ( ! cdoSilentMode ){
cdoPrint("Started child process \"%s\".", newarg+1);
pthread_attr_t attr;
int status = pthread_attr_init(&attr);
if ( status ) SysError("pthread_attr_init failed for '%s'", newarg+1);
status = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
if ( status ) SysError("pthread_attr_setdetachstate failed for '%s'", newarg+1);
/*
param.sched_priority = 0;
status = pthread_attr_setschedparam(&attr, &param);
if ( status ) SysError("pthread_attr_setschedparam failed for '%s'", newarg+1);
*/
/* status = pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); */
/* if ( status ) SysError("pthread_attr_setinheritsched failed for '%s'", newarg+1); */
pthread_attr_getscope(&attr, &pthreadScope);
/* status = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); */
/* if ( status ) SysError("pthread_attr_setscope failed for '%s'", newarg+1); */
/* If system scheduling scope is specified, then the thread is scheduled against all threads in the system */
/* pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); */
size_t stacksize = 0;
status = pthread_attr_getstacksize(&attr, &stacksize);
if ( stacksize < 2097152 )
{
stacksize = 2097152;
pthread_attr_setstacksize(&attr, stacksize);
}
pthread_t thrID;
int rval = pthread_create(&thrID, &attr, operatorModule(operatorName), newargument);
if ( rval != 0 )
{
errno = rval;
SysError("pthread_create failed for '%s'", newarg+1);
}
pCreateReadThread(newarg, newargument, operatorName);
/* Free(operatorName); */
processAddStream(pstreamID);
/* pipeInqInfo(pstreamID); */
......@@ -369,6 +378,7 @@ void pstreamOpenReadPipe(const argument_t *argument, pstream_t *pstreamptr)
#else
cdoAbort("Cannot use pipes, pthread support not compiled in!");
#endif
}
static
......@@ -396,11 +406,14 @@ void pstreamCreateFilelist(const argument_t *argument, pstream_t *pstreamptr)
char line[4096];
FILE *fp, *fp2;
fp = fopen(pch, "r");
if ( fp == NULL ) cdoAbort("Open failed on %s", pch);
if ( fp == NULL )
{
cdoAbort("Open failed on %s", pch);
}
if ( cdoVerbose )
{
cdoPrint("Reading file names from %s", pch);
}
/* find number of files */
nfiles = 0;
while ( readline(fp, line, 4096) )
......@@ -442,8 +455,13 @@ void pstreamCreateFilelist(const argument_t *argument, pstream_t *pstreamptr)
pstreamptr->mfnames = (char **) Malloc(nfiles*sizeof(char *));
strcpy(line, pch);
for ( i = 0; i < len; i++ ) if ( line[i] == ',' ) line[i] = 0;
for ( i = 0; i < len; i++ )
{
if ( line[i] == ',' )
{
line[i] = 0;
}
}
i = 0;
for ( j = 0; j < nfiles; j++ )
{
......@@ -1699,7 +1717,6 @@ void cdoFinish(void)
if ( ! cdoSilentMode )
fprintf(stderr, " ( %.2fs )\n", c_cputime);
}
if ( cdoBenchmark && processID == 0 )
fprintf(stderr, "total: user %.2fs sys %.2fs cpu %.2fs mem%s\n",
p_usertime, p_systime, p_cputime, memstring);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment