void initialize_comunicadors (int n_ptasks) { int ii; unsigned jj; /* Init intra-communicator */ INIT_QUEUE (&comunicadors); #if defined(DEBUG_COMMUNICATORS) fprintf (stderr, "DEBUG: Initializing communicators\n"); #endif alies_comunicadors = (CommAliasInfo_t **) malloc (n_ptasks * sizeof (CommAliasInfo_t *)); ASSERT(alies_comunicadors!=NULL, "Not enough memory for intra-communicators alias"); for (ii = 0; ii < n_ptasks; ii++) { ptask_t *ptask_info = GET_PTASK_INFO(ii+1); alies_comunicadors[ii] = (CommAliasInfo_t *) malloc (ptask_info->ntasks * sizeof (CommAliasInfo_t)); ASSERT(alies_comunicadors[ii]!=NULL, "Not enough memory for intra-communicators alias"); } /* Init inter-communicator */ Intercomm_ptask_task = (InterCommInfoAlias_t ***) malloc (n_ptasks * sizeof (InterCommInfoAlias_t **)); ASSERT(Intercomm_ptask_task!=NULL, "Not enough memory for inter-communicators alias"); num_InterCommunicatorAlias = (unsigned **) malloc (n_ptasks * sizeof (unsigned *)); ASSERT(num_InterCommunicatorAlias!=NULL, "Not enough memory for inter-communicators alias"); for (ii = 0; ii < n_ptasks; ii++) { ptask_t *ptask_info = GET_PTASK_INFO(ii+1); Intercomm_ptask_task[ii] = (InterCommInfoAlias_t**) malloc (ptask_info->ntasks * sizeof (InterCommInfoAlias_t *)); ASSERT(Intercomm_ptask_task[ii]!=NULL, "Not enough memory for inter-communicators alias"); memset (Intercomm_ptask_task[ii], 0, ptask_info->ntasks*sizeof(InterCommInfoAlias_t*)); num_InterCommunicatorAlias[ii] = (unsigned*) malloc (ptask_info->ntasks * sizeof(unsigned)); ASSERT(num_InterCommunicatorAlias[ii]!=NULL, "Not enough memory for inter-communicators alias"); memset (num_InterCommunicatorAlias[ii], 0, ptask_info->ntasks*sizeof(unsigned)); } for (ii = 0; ii < n_ptasks; ii++) { ptask_t *ptask_info = GET_PTASK_INFO(ii+1); for (jj = 0; jj < ptask_info->ntasks; jj++) INIT_QUEUE (&(alies_comunicadors[ii][jj])); } }
static void init(ID3ASFilterContext *context, AVDictionary *codec_options) { codec_t *this = context->priv_data; this->threads = (thread_struct *) malloc(sizeof(thread_struct) * context->num_downstream_filters); for (int i = 0; i < context->num_downstream_filters; i++) { this->threads[i].thread_id = thread_id++; this->threads[i].context = context; this->threads[i].downstream_filter = context->downstream_filters[i]; this->threads[i].codec_t = this; pthread_cond_init(&this->threads[i].complete, NULL); pthread_mutex_init(&this->threads[i].complete_mutex, NULL); pthread_mutex_lock(&this->threads[i].complete_mutex); INIT_QUEUE(this->threads[i].inbound_frame_queue); pthread_create(&this->threads[i].thread, NULL, &thread_proc, &this->threads[i]); } }
/****************************************************************************** *** InitializeObjectTable ******************************************************************************/ void InitializeObjectTable (unsigned num_appl, struct input_t * files, unsigned long nfiles) { unsigned int ptask, task, thread, i, j; unsigned int ntasks[num_appl], **nthreads = NULL; /* First step, collect number of applications, number of tasks per application and number of threads per task within an app */ for (i = 0; i < num_appl; i++) ntasks[i] = 0; for (i = 0; i < nfiles; i++) ntasks[files[i].ptask-1] = MAX(files[i].task, ntasks[files[i].ptask-1]); nthreads = (unsigned**) malloc (num_appl*sizeof(unsigned*)); ASSERT(nthreads!=NULL, "Cannot allocate memory to store nthreads for whole applications"); for (i = 0; i < num_appl; i++) { nthreads[i] = (unsigned*) malloc (ntasks[i]*sizeof(unsigned)); ASSERT(nthreads[i]!=NULL, "Cannot allocate memory to store nthreads for application"); for (j = 0; j < ntasks[i]; j++) nthreads[i][j] = 0; } for (i = 0; i < nfiles; i++) nthreads[files[i].ptask-1][files[i].task-1] = MAX(files[i].thread, nthreads[files[i].ptask-1][files[i].task-1]); /* Second step, allocate structures respecting the number of apps, tasks and threads found */ ApplicationTable.nptasks = num_appl; ApplicationTable.ptasks = (ptask_t*) malloc (sizeof(ptask_t)*num_appl); ASSERT(ApplicationTable.ptasks!=NULL, "Unable to allocate memory for ptasks"); for (i = 0; i < ApplicationTable.nptasks; i++) { /* Allocate per task information within each ptask */ ApplicationTable.ptasks[i].ntasks = ntasks[i]; ApplicationTable.ptasks[i].tasks = (task_t*) malloc (sizeof(task_t)*ntasks[i]); ASSERT(ApplicationTable.ptasks[i].tasks!=NULL, "Unable to allocate memory for tasks"); for (j = 0; j < ApplicationTable.ptasks[i].ntasks; j++) { /* Initialize pending communication queues for each task */ CommunicationQueues_Init ( &(ApplicationTable.ptasks[i].tasks[j].send_queue), &(ApplicationTable.ptasks[i].tasks[j].recv_queue)); /* Allocate per thread information within each task */ ApplicationTable.ptasks[i].tasks[j].threads = (thread_t*) malloc (sizeof(thread_t)*nthreads[i][j]); ASSERT(ApplicationTable.ptasks[i].tasks[j].threads!=NULL,"Unable to allocate memory for threads"); } } #if USE_HARDWARE_COUNTERS || defined(HETEROGENEOUS_SUPPORT) INIT_QUEUE (&CountersTraced); #endif /* 3rd step, Initialize the object table structure */ for (ptask = 0; ptask < ApplicationTable.nptasks; ptask++) for (task = 0; task < ApplicationTable.ptasks[ptask].ntasks; task++) { task_t *task_info = GET_TASK_INFO(ptask+1,task+1); task_info->tracing_disabled = FALSE; task_info->nthreads = nthreads[ptask][task]; task_info->num_virtual_threads = nthreads[ptask][task]; task_info->num_binary_objects = 0; task_info->binary_objects = NULL; for (thread = 0; thread < nthreads[ptask][task]; thread++) { thread_t *thread_info = GET_THREAD_INFO(ptask+1,task+1,thread+1); /* Look for the appropriate CPU for this ptask, task, thread */ for (i = 0; i < nfiles; i++) if (files[i].ptask == ptask+1 && files[i].task == task+1 && files[i].thread == thread+1) { thread_info->cpu = files[i].cpu; break; } thread_info->dimemas_size = 0; thread_info->virtual_thread = thread+1; thread_info->nStates = 0; thread_info->First_Event = TRUE; thread_info->HWCChange_count = 0; thread_info->MatchingComms = TRUE; #if USE_HARDWARE_COUNTERS || defined(HETEROGENEOUS_SUPPORT) thread_info->HWCSets = NULL; thread_info->HWCSets_types = NULL; thread_info->num_HWCSets = 0; thread_info->current_HWCSet = 0; #endif } } /* 4th step Assign the node ID */ for (i = 0; i < nfiles; i++) { task_t *task_info = GET_TASK_INFO(files[i].ptask, files[i].task); task_info->nodeid = files[i].nodeid; } /* This is needed for get_option_merge_NanosTaskView() == FALSE */ for (ptask = 0; ptask < ApplicationTable.nptasks; ptask++) for (task = 0; task < ApplicationTable.ptasks[ptask].ntasks; task++) { task_t *task_info = GET_TASK_INFO(ptask+1, task+1); task_info->num_active_task_threads = 0; task_info->active_task_threads = NULL; } /* Clean up */ if (nthreads != NULL) { for (i = 0; i < num_appl; i++) if (nthreads[i] != NULL) free (nthreads[i]); free (nthreads); } }
void PR_queue_init (PR_Queue_t * cua) { INIT_QUEUE (cua); }
/* **++ ** ROUTINE: main ** ** FUNCTIONAL DESCRIPTION: ** ** Main program. Fetches the command from the command line, ** uses CLI$ routines to parse it, then starts the build process. ** ** RETURNS: cond_value, longword (unsigned), write only, by value ** ** PROTOTYPE: ** ** main ** ** IMPLICIT INPUTS: See global definitions at module head. ** ** IMPLICIT OUTPUTS: See global definitions at module head. ** ** COMPLETION CODES: ** ** SS$_NORMAL, MMK__ALLOK : normal successful completion. ** ** SIDE EFFECTS: None. ** **-- */ unsigned int main (void) { DESCRIP cmdstr; char Output_File[256], tmp[256]; $DESCRIPTOR(cmdname, "MMKC "); unsigned int status; int i; /* ** Initialize the globals */ temporary_symbols = 0; for (i = 0; i < MMK_K_SYMTABLE_SIZE; i++) { INIT_QUEUE(global_symbols.symlist[i]); INIT_QUEUE(local_symbols.symlist[i]); INIT_QUEUE(cmdline_symbols.symlist[i]); INIT_QUEUE(builtin_symbols.symlist[i]); } INIT_QUEUE(rules); INIT_QUEUE(dependencies); INIT_QUEUE(dep_internal); INIT_QUEUE(dep_deferred); INIT_QUEUE(suffixes); INIT_QUEUE(do_first); INIT_QUEUE(do_last); exit_status = SS$_NORMAL; ignore = override_silent = override_ignore = symbol_override = 0; skip_intermediates = 0; /* ** Fetch and parse command string */ INIT_DYNDESC(cmdstr); status = lib$get_foreign(&cmdstr); str$prefix(&cmdstr, &cmdname); status = cli$dcl_parse(&cmdstr, MMK_COMPILE_RULES_CLD, lib$get_input, lib$get_input); if (!OK(status)) return (status | STS$M_INHIB_MSG); /* ** Get the command parameters and qualifiers */ Output_File[0] = '\0'; if (cli_present("OUTPUT") == CLI$_PRESENT) { cli_get_value("OUTPUT", Output_File, sizeof(Output_File)); } status = cli_get_value("RULES_FILE", tmp, sizeof(tmp)); if (!OK(status)) return status | STS$M_INHIB_MSG; Read_Description(tmp, "SYS$DISK:[].MMS", 1); if (OK(exit_status)) Generate_Structures(tmp, Output_File); return exit_status | STS$M_INHIB_MSG; }
/* **++ ** ROUTINE: netlib___dns_init ** ** FUNCTIONAL DESCRIPTION: ** ** Initializes an internal DNS resolver context. ** ** RETURNS: cond_value, longword (unsigned), write only, by value ** ** PROTOTYPE: ** ** netlib___dns_init(struct CTX *ctx) ** ** ctx: NETLIB context, modify, by reference. ** ** IMPLICIT INPUTS: None. ** ** IMPLICIT OUTPUTS: None. ** ** COMPLETION CODES: See code. ** ** SIDE EFFECTS: None. ** **-- */ unsigned int netlib___dns_init (struct CTX *ctx) { struct DOMAIN *dom; unsigned int status; ITMLST lnmlst[3]; int i, maxidx; unsigned int size; unsigned short buflen; char buf[256]; int did_tmo; static unsigned int socktype = NETLIB_K_TYPE_DGRAM; static unsigned int ctxsize = sizeof(struct DNSCTX); static $DESCRIPTOR(tabnam, "LNM$FILE_DEV"); static $DESCRIPTOR(lognam, "NETLIB_SEARCH_DOMAIN"); static $DESCRIPTOR(tmolnm, "NETLIB_DNS_QUERY_TIMEOUT"); /* ** Allocate the DNS resolver context */ status = lib$get_vm(&ctxsize, &ctx->dnsctx); if (!OK(status)) return status; INIT_QUEUE(ctx->dnsctx->nsq); INIT_QUEUE(ctx->dnsctx->domq); /* ** Get the list of name servers we're supposed to contact */ if (netlib___get_nameservers(&ctx->dnsctx->nsq) == 0) { lib$free_vm(&ctxsize, &ctx->dnsctx); ctx->dnsctx = 0; ctx->flags |= CTX_M_NO_DNS; return SS$_UNSUPPORTED; } /* ** Get the list of NETLIB search domains, or the package-specific ** ones. */ ITMLST_INIT(lnmlst[0], LNM$_MAX_INDEX, sizeof(maxidx), &maxidx, 0); ITMLST_INIT(lnmlst[1], 0, 0, 0, 0); if (OK(sys$trnlnm(0, &tabnam, &lognam, 0, lnmlst))) { ITMLST_INIT(lnmlst[0], LNM$_INDEX, sizeof(i), &i, 0); ITMLST_INIT(lnmlst[1], LNM$_STRING, sizeof(buf), buf, &buflen); ITMLST_INIT(lnmlst[2], 0, 0, 0, 0); for (i = 0; i <= maxidx; i++) { if (OK(sys$trnlnm(0, &tabnam, &lognam, 0, lnmlst)) && buflen != 0) { size = buflen + sizeof(struct DOMAIN); if (OK(lib$get_vm(&size, &dom))) { dom->length = buflen; memcpy(dom->name, buf, buflen); dom->name[buflen] = '\0'; queue_insert(dom, ctx->dnsctx->domq.tail); } } } } else if (netlib___get_domain(buf, sizeof(buf), &buflen)) { char *cp, *cp1; int remain; cp = buf; remain = buflen; /* ** A search domain must have at least two parts, to avoid the ".com.edu" ** problem, which is why we check to make sure that the remaining domain ** string has at least one dot. */ while (remain > 0) { cp1 = memchr(cp, '.', remain); if (cp1 == 0) break; size = remain + sizeof(struct DOMAIN); if (OK(lib$get_vm(&size, &dom))) { dom->length = remain; memcpy(dom->name, cp, remain); dom->name[remain] = '\0'; queue_insert(dom, ctx->dnsctx->domq.tail); } remain -= (cp1 - cp) + 1; cp = cp1 + 1; } } did_tmo = 0; ITMLST_INIT(lnmlst[0], LNM$_STRING, sizeof(buf), buf, &buflen); ITMLST_INIT(lnmlst[1], 0, 0, 0, 0); if (OK(sys$trnlnm(0, &tabnam, &tmolnm, 0, lnmlst))) { struct dsc$descriptor dsc; INIT_SDESC(dsc, buflen, buf); /* * Make sure it's a delta time value */ if (OK(sys$bintim(&dsc, &ctx->dnsctx->timeout))) did_tmo = (int) ctx->dnsctx->timeout.long2 < 0; } if (!did_tmo) sys$bintim(&default_timeout, &ctx->dnsctx->timeout); ctx->dnsctx->retry_count = 4; return SS$_NORMAL; } /* netlib___dns_init */