Beispiel #1
0
int thzclos(Process *proc, port_ent *peptr, int elem_no)
{
	//Process *sptr;
	cp *cpp;
	//Cnxt *cnp;
	//IPh   *IPptr;
	//IPh   *nextIP;

	cpp = (cp *)peptr -> cpptr;
	if (peptr -> ret_code == 2)
		return(2);     

	if (cpp -> elem_list[elem_no].closed)
		return(1);

	if (proc->trace) MSG1("%s Close\n",proc -> procname);

	thziclos(proc, cpp, elem_no);

	
	cpp -> elem_list[elem_no].closed = TRUE;

	if (proc->trace) MSG1("%s Close end\n", proc -> procname);
	return(0);
}
Beispiel #2
0
void Process::run() {

	//proc -> status = ACTIVE;

	/*
	run_test() returns 0 if data waiting
	1 if no data waiting, but not all upstream connections are closed
	2 if no input ports or input ports are only IIP ports or all input ports closed
	*/

	for( ; ; ) {
		if (2 == run_test()  && ! must_run && ! self_starting) 
			break;
		Port * cpp = in_ports;
		while (cpp != 0) {	       
			for (int i = 0; i < cpp -> elem_count; i++) {
				if (cpp -> elem_list[i].gen.connxn == 0)
					continue;
				if (! cpp -> elem_list[i].is_IIP)
					cpp -> elem_list[i].closed = FALSE;	
			}
			cpp = cpp -> succ;
		}
		//
		// execute component code!
		value =
			faddr (proc_anchor);	
		// component code returns

		if (value > 0)
			printf ("Process %s returned with value %d\n",
			procname, value); 
		if (owned_IPs > 0)
			printf("%s Deactivated with %d IPs not disposed of\n",
			procname, owned_IPs);

		cpp = in_ports;
		while (cpp != 0)
		{
			for (int i = 0; i < cpp -> elem_count; i++) {
				Cnxt * cnp = cpp -> elem_list[i].gen.connxn;
				if (cnp == 0)
					continue;
				if (cpp -> elem_list[i].is_IIP) 
					cpp -> elem_list[i].closed = TRUE;	
			}
			cpp = cpp -> succ;
		}
		if (trace)
			printf("%s Deactivated with retcode %d\n",
			procname, value);

		if (value > 4) {
			//proc -> terminating = TRUE;
			break;
		}

		int res;
		/* res =  0 if data in cnxt; 1 if upstream not closed;
		2 if upstream closed */

		res = run_test();

		if (res == 2) break;
		if (res == 0) continue;

		dormwait();
	}



	/*
	Process * lpProc;
	// This should only be done at termination time!
	if (lpProc -> end_port != 0) {
	lpProc -> value = thzcrep(lpProc,
	&lpProc -> int_ptr, 0, "\0");
	lpProc -> int_pe.cpptr = lpProc -> end_port;
	lpProc -> value = thzsend(lpProc,
	&lpProc -> int_ptr, &lpProc -> int_pe, 0);
	if (lpProc -> value > 0)
	lpProc -> value = thzdrop(lpProc,
	&lpProc -> int_ptr);
	//break;
	}

	*/
	//close_outputPorts(proc);


	Port * cpp = out_ports;
	while (cpp != 0)
	{
		for (int i = 0; i < cpp -> elem_count; i++) {
			if (cpp -> elem_list[i].gen.connxn == 0)
				continue;
			/*value = */ thziclos(this, cpp, i);
		}
		cpp = cpp -> succ;
	}

	//close_inputPorts(proc);
	cpp = in_ports;
	while (cpp != 0)
	{
		for (int i = 0; i < cpp -> elem_count; i++) {
			if (cpp -> elem_list[i].gen.connxn == 0)
				continue;
			if (! cpp -> elem_list[i].is_IIP)
				thziclos(this, cpp, i);
		}
		cpp = cpp -> succ;
	}
	//printf("Terminated %s\n", proc -> procname);
	status = TERMINATED;
	if (trace)
		printf("%s Terminated with retcode %d\n",
		procname, value);
	//proc -> thread.join();
	network -> latch -> count_down();
}