当前位置: 首页>>代码示例>>C++>>正文


C++ Signal函数代码示例

本文整理汇总了C++中Signal函数的典型用法代码示例。如果您正苦于以下问题:C++ Signal函数的具体用法?C++ Signal怎么用?C++ Signal使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Signal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: check_mem

/*{{{  main memory checking */
static void check_mem(void)
{ int	 size;
  int	 i;
  char	*buf;
  int	*wbuf;
  int	 checksum;
  int	 tmp;
  int	 failures	= 0;
  int	 iterations	= 0;

	/* Before allocating memory it is necessary to wait for the	*/
	/* various other threads to allocate their buffers.		*/
  for (i = 1; i < NumberThreads; i++)
   Wait(&ThreadsReady);

	/* Now examine the free pool to determine the amount of memory	*/
	/* to get. The system is left with 50K of memory for buffering	*/
	/* etc.								*/
  size	 = GetRoot()->FreePool->Size;
  size	-= (50 * 1024);
  size	 = (size + 1023) & ~1023;

	/* If the TFM is running on this processor reduce the memory	*/
	/* size. The TFM may need more memory as well as the kernel and	*/
	/* Processor Manager.						*/
  { Object	*tmp = Locate(NULL, "/loader/tfm");
    if (tmp != NULL)
     { size -= (50 * 1024); Close(tmp); }
    tmp = Locate(NULL, "/loader/netserv");
    if (tmp != NULL)
     { size -= (50 * 1024); Close(tmp); }
  }
    
	/* Now try to get hold of a suitable buffer. The memory may	*/
	/* be fragmented so it is necessary to try smaller and smaller	*/
	/* mallocs.							*/
  for (buf = NULL; (buf == NULL) && (size > 0); size -= (10 * 1024))
   buf = malloc(size);

  if (buf == NULL)
   { Report("main memory checker, failed to allocate a buffer");
     Wait(&ResultsLock);
     Results.OffchipMemory	= 0;
     Results.OffchipFailures	= 0;
     Signal(&ResultsLock);
     Signal(&ResultsReady);
     return;
   }

	/* Fill the buffer with random data and calculate the checksum	*/
  wbuf = (int *) buf;
  for (i = 0, checksum = 0; i < (size / sizeof(int)); i++)
   { wbuf[i]	 = hw_rand();
     checksum	+= wbuf[i];
   }

  for (iterations = 0; ; iterations++)
   { for (i = 0; (i < MemoryInterval) && !Finished; i++)
      Delay(OneSec);
     if (Finished) break;

     for (i = 0, tmp = 0; i < (size / sizeof(int)); i++)
      tmp += wbuf[i];

     if (tmp != checksum)
      { checksum = tmp; failures++; }
   }

  Wait(&ResultsLock);
  Results.OffchipMemory		= size / 1024;
  Results.OffchipFailures	= failures;
  Results.OffchipIterations	= iterations;
  Signal(&ResultsLock);
  Signal(&ResultsReady);
}
开发者ID:jamjr,项目名称:Helios-NG,代码行数:76,代码来源:hwtest.c

示例2: baggingFn

void baggingFn(int j, int bagTokenNo)						/*j is the index of the Bagger, i.e. OT[j]*/
{
    int i;							/*For the index of the Customer, i.e. C[i]*/
    int x;

    for ( x=0; x<noCustomers; x++)

        /*TO GO part*/
        if (C[x].toGoWaiting == 1 && C[x].custDoA == 1 && C[x].orderType==1)
        {

            Acquire(waitToGoLock[x]);			/*Bagger acquires the lock of Customer C[i] for the Bagger -*/

        }



    i=tokenToId[bagTokenNo];				/*Obtained Customer ID from the Bag Token No*/


    OT[j].otBagTokenNo=bagTokenNo;


    /*	while (sixBurgerAvailable < C[i].sixBurger || threeBurgerAvailable < C[i].threeBurger || veggieBurgerAvailable < C[i].veggieBurger || frenchFriesAvailable < C[i].frenchFries) currentThread -> Yield();*/

    Acquire(cookedLock);
    sixBurgerAvailable-=C[i].sixBurger;			/*The amount of food item of each type available*/
    threeBurgerAvailable-=C[i].threeBurger;			/*on its respective shelf is decremented by the number*/
    veggieBurgerAvailable-=C[i].veggieBurger;		/*of items of that type ordered by the Customer C[i]*/
    frenchFriesAvailable-=C[i].frenchFries;
    Release(cookedLock);



    if (C[i].orderType == 1)
    {

        /* *****		Monitor for TO GO Customers Begins	***** */

        if (M.mID==j) {
            Print("\nManager packed the food for Customer %d", i,0, 0);
            Print("\nManager gives food to Customer %d", i,0, 0);
            Print("\nCustomer %d receives food from the Manager\n", i, 0,0);
            Print("\nCustomer %d is leaving the restaurant after Manager packed the food\n", i, 0,0);
            Acquire(customerCounterLock);
            customerCounter++;
            Release(customerCounterLock);

        }
        else
        {
            Print("\nOrderTaker %d packed the food for Customer %d", j, i,0);
            Print("\nOrderTaker %d gives food to Customer %d", j, i,0);
            Print("\nCustomer %d receives food from the OrderTaker %d\n", i, j,0);
            Print("\nCustomer %d is leaving the restaurant after OrderTaker %d packed the food\n", i, j,0);

            Acquire(customerCounterLock);
            customerCounter++;
            Release(customerCounterLock);


        }


        if (C[i].toGoWaiting==1);
        {
            Signal(waitToGoCV[i], waitToGoLock[i]);

        }

        for (x=0; x < noCustomers; x++)			/*For each Customer*/
        {
            /*	if(waitToGoLock[x]->isHeldByCurrentThread() && x!=i)*/
            if (x !=i)
            {
                Release(waitToGoLock[x]);
            }
        }


        Wait(waitToGoCV[i], waitToGoLock[i]);
        Release(waitToGoLock[i]);


        return;							/*Exits fn*/
    }




    /* *****		Monitor for TO GO Customers Ends	***** */


    else
    {
        /*If the control reaches here, the order is Eat in type. Therefore, the Token No is appended to the waiterQueue
        	For Eat In Customers
        */

        Print("\nOrderTaker %d gives token number %d to Customer %d", C[i].myOrderTaker, C[i].custTokenNo, i);
//.........这里部分代码省略.........
开发者ID:aitbayev,项目名称:Nachos-402-OS,代码行数:101,代码来源:manager.c

示例3: read_from_file

 WORD read_from_file(WORD pos, WORD size, char *buf, FileInfo *info)
{ int to_read;
  int sector,	  /* no of sector to read */
      first_clus, /* 1st cluster to read */
      num, 	  /* no of cluster */
      begin, 	  /* pos of 1st byte in 1st cluster */
      i,
      nb_clus, 	  /* no total of cluster to read */
      reste,
      e;

  Wait( &Var_access );
    
#ifdef debug
    IOdebug("msdosfs : read_from_file(%s), %dbytes",info->Name,size);
#endif

  if( size == 0 ) 
  {
    Signal( &Var_access );
    return 0;
  }

  first_clus = pos / Cluster_byte;
  begin      = pos % Cluster_byte;
  num        = info->Cluster;

 		/* get cluster in chain */
  
  for(i = 0; i < first_clus; i++)
  {
	num = get_fat_entry(num);
	if(num < 0)
	   goto error;
	if( num >= 0xff8 )
	{
#ifdef debugE
	   IOdebug("msdosfs ERROR : read_from_file : eof unexpected");
#endif
	   goto error;
	}
  }

		/* read up to boundary of next cluster */

  to_read = (size > (Cluster_byte - begin)) ? Cluster_byte - begin : size;
  sector = (num - 2)*Cluster_size + Dir_start + Dir_size;
  e = flop_read(sector, Cluster_byte, buf);
  for(i = 0 ; i < to_read ; i++)
	buf[i] = buf[begin + i];
  if( e < to_read )
     goto error;
  buf += to_read;

		/* read full clusters */

  nb_clus = (size-to_read)/Cluster_byte;
  for(i=0; i<nb_clus; i++)
  {
	num = get_fat_entry(num);
	if( num<0 || num>=0xff8 ) goto error;
  	sector = (num - 2)*Cluster_size + Dir_start + Dir_size;
  	if(flop_read(sector, Cluster_byte, buf) < Cluster_byte ) 
	{
          Signal( &Var_access );
	  return (i*Cluster_byte + to_read);
        }
	buf += Cluster_byte;
  }

		/* read last cluster */

  reste = size - to_read - nb_clus*Cluster_byte;
  if(reste>0)
  {
        char *freeloc;
	char *tbuff=Malloc(Cluster_byte);
	if(tbuff == NULL)
		goto error;
	freeloc = tbuff;
	num = get_fat_entry(num);
	if( num<0 || num>=0xff8 )
		{
		Free(freeloc);
		goto error;
		}
  	sector = (num - 2)*Cluster_size + Dir_start + Dir_size;
  	e = flop_read(sector, Cluster_byte, tbuff);
  	for(i = 0 ; i < reste ; i++)
		*buf++ = *tbuff++;
	Free(freeloc);
  	if( e < reste ) 
	{
          Signal( &Var_access );
	  return (nb_clus*Cluster_byte + to_read);
	}
  }

  Signal( &Var_access );
  return(size);
//.........这里部分代码省略.........
开发者ID:jamjr,项目名称:Helios-NG,代码行数:101,代码来源:read.c

示例4: main

int
main(int argc, char **argv)
{
	int			listenfd, i, navail, maxfd, nsel, connfd, rc;
	void		sig_int(int);
	pid_t		child_make(int, int, int);
	ssize_t		n;
	fd_set		rset, masterset;
	socklen_t	addrlen, clilen;
	struct sockaddr	*cliaddr;

	if (argc == 3)
		listenfd = Tcp_listen(NULL, argv[1], &addrlen);
	else if (argc == 4)
		listenfd = Tcp_listen(argv[1], argv[2], &addrlen);
	else
		err_quit("usage: serv05 [ <host> ] <port#> <#children>");

	FD_ZERO(&masterset);
	FD_SET(listenfd, &masterset);
	maxfd = listenfd;
	cliaddr = Malloc(addrlen);

	nchildren = atoi(argv[argc-1]);
	navail = nchildren;
	cptr = Calloc(nchildren, sizeof(Child));

		/* 4prefork all the children */
	for (i = 0; i < nchildren; i++) {
		child_make(i, listenfd, addrlen);	/* parent returns */
		FD_SET(cptr[i].child_pipefd, &masterset);
		maxfd = max(maxfd, cptr[i].child_pipefd);
	}

	Signal(SIGINT, sig_int);

	for ( ; ; ) {
		rset = masterset;
		if (navail <= 0)
			FD_CLR(listenfd, &rset);	/* turn off if no available children */
		nsel = Select(maxfd, &rset, NULL, NULL, NULL);

			/* 4check for new connections */
		if (FD_ISSET(listenfd, &rset)) {
			clilen = addrlen;
			connfd = Accept(listenfd, cliaddr, &clilen);

			for (i = 0; i < nchildren; i++)
				if (cptr[i].child_status == 0)
					break;				/* available */

			if (i == nchildren)
				err_quit("no available children");
			cptr[i].child_status = 1;	/* mark child as busy */
			cptr[i].child_count++;
			navail--;

			n = Write_fd(cptr[i].child_pipefd, "", 1, connfd);
			Close(connfd);
			if (--nsel == 0)
				continue;	/* all done with select() results */
		}

			/* 4find any newly-available children */
		for (i = 0; i < nchildren; i++) {
			if (FD_ISSET(cptr[i].child_pipefd, &rset)) {
				if ( (n = Read(cptr[i].child_pipefd, &rc, 1)) == 0)
					err_quit("child %d terminated unexpectedly", i);
				cptr[i].child_status = 0;
				navail++;
				if (--nsel == 0)
					break;	/* all done with select() results */
			}
		}
	}
}
开发者ID:rkks,项目名称:refer,代码行数:76,代码来源:serv05.c

示例5: meetCashier

void meetCashier(int* isCashCleared, int* cash, int socialNumber) {
	int i, currentClerkIndex;

	currentClerkIndex = -1;
	while (currentClerkIndex == -1) {
		for (i = 0; i < cashierAmount; i++) {
			Acquire(cashierLocks[i]);
			if (GetMonitor(cashierClerkState[i]) == AVAILABLE) {
				currentClerkIndex = i;
				/* set clerk to busy, helping us now */
				SetMonitor(cashierClerkState[i], BUSY);
				break;
			} else { /* either on break or busy, can't do anything with this clerk atm */
				Release(cashierLocks[i]);
			}
		}
		if (currentClerkIndex == -1) {
			punish(10,100); /* wait a little bit, someone will be available soon */
		}
	}
	
	Write("Senator ", 8, ConsoleOutput);
	WriteInt(socialNumber);
	Write(" has gotten in regular line for CashierClerk ", sizeof(" has gotten in regular line for CashierClerk "), ConsoleOutput);
	WriteInt(currentClerkIndex);
	Write("\n", 1, ConsoleOutput);

	/* customer is at cashier now */
	SetMonitor(cashierDB[currentClerkIndex], socialNumber);

	Write("Senator ", 8, ConsoleOutput);
	WriteInt(socialNumber);
	Write(" has given SSN ", sizeof(" has given SSN "), ConsoleOutput);
	WriteInt(socialNumber);
	Write(" to cashier ", sizeof(" to cashier "), ConsoleOutput);
	WriteInt(currentClerkIndex);
	Write("\n", 1, ConsoleOutput);

	Signal(cashierCV[currentClerkIndex], cashierLocks[currentClerkIndex]);
	Wait(cashierCV[currentClerkIndex], cashierLocks[currentClerkIndex]);

	if (GetMonitor(cashierDBCleared[currentClerkIndex])){
		/* that means cashier is notified that the previous */
		/* requirements have been completed and is cleared to continue */
		/* for user to pay and get checked off */
		
		Write("Senator ", 8, ConsoleOutput);
		WriteInt(socialNumber);
		Write(" has given Cashier ", sizeof(" has given Cashier "), ConsoleOutput);
		WriteInt(currentClerkIndex);
		Write(" $100", sizeof(" $100"), ConsoleOutput);
		Write("\n", 1, ConsoleOutput);

		*cash -= 100;
		*isCashCleared = TRUE;
		Release(cashierLocks[currentClerkIndex]);
	} else {
		/* customer should NOT be here, punish the user */		
		Write("Senator ", 8, ConsoleOutput);
		WriteInt(socialNumber);
		Write(" has gone to Cashier ", sizeof(" has gone to Cashier "), ConsoleOutput);
		WriteInt(currentClerkIndex);
		Write(" too soon. They are going to the back of the line.", sizeof(" too soon. They are going to the back of the line."), ConsoleOutput);
		Write("\n", 1, ConsoleOutput);

		Release(cashierLocks[currentClerkIndex]);
		punish(100, 1000);
	}
}
开发者ID:bryan,项目名称:nachos,代码行数:69,代码来源:senator.c

示例6: net_func


//.........这里部分代码省略.........
	}
	opened = true;

	// Is it Ethernet?
	control_io->ios2_Req.io_Command = S2_DEVICEQUERY;
	control_io->ios2_StatData = (void *)&query_data;
	DoIO((struct IORequest *)control_io);
	if (control_io->ios2_Req.io_Error)
		goto quit;
	if (query_data.HardwareType != S2WireType_Ethernet) {
		WarningAlert(GetString(STR_NOT_ETHERNET_WARN));
		goto quit;
	}

	// Yes, create IORequest for writing
	write_io = (struct IOSana2Req *)CreateIORequest(write_port, sizeof(struct IOSana2Req));
	if (write_io == NULL)
		goto quit;
	memcpy(write_io, control_io, sizeof(struct IOSana2Req));
	write_io->ios2_Req.io_Message.mn_Node.ln_Type = 0;	// Avoid CheckIO() bug
	write_io->ios2_Req.io_Message.mn_ReplyPort = write_port;

	// Configure Ethernet
	control_io->ios2_Req.io_Command = S2_GETSTATIONADDRESS;
	DoIO((struct IORequest *)control_io);
	memcpy(ether_addr, control_io->ios2_DstAddr, 6);
	memcpy(control_io->ios2_SrcAddr, control_io->ios2_DstAddr, 6);
	control_io->ios2_Req.io_Command = S2_CONFIGINTERFACE;
	DoIO((struct IORequest *)control_io);
	D(bug("Ethernet address %08lx %08lx\n", *(uint32 *)ether_addr, *(uint16 *)(ether_addr + 4)));

	// Initialization went well, inform main task
	proc_error = false;
	Signal(MainTask, SIGF_SINGLE);

	// Main loop
	for (;;) {

		// Wait for I/O and messages (CTRL_C is used for quitting the task)
		ULONG sig = Wait(proc_port_mask | read_mask | write_mask | SIGBREAKF_CTRL_C);

		// Main task wants to quit us
		if (sig & SIGBREAKF_CTRL_C)
			break;

		// Main task sent a command to us
		if (sig & proc_port_mask) {
			struct NetMessage *msg;
			while (msg = (NetMessage *)GetMsg(proc_port)) {
				D(bug("net_proc received %08lx\n", msg->what));
				switch (msg->what) {
					case MSG_CLEANUP:
						remove_all_protocols();
						break;

					case MSG_ADD_MULTI:
						control_io->ios2_Req.io_Command = S2_ADDMULTICASTADDRESS;
						Mac2Host_memcpy(control_io->ios2_SrcAddr, msg->pointer + eMultiAddr, 6);
						DoIO((struct IORequest *)control_io);
						if (control_io->ios2_Req.io_Error == S2ERR_NOT_SUPPORTED) {
							WarningAlert(GetString(STR_NO_MULTICAST_WARN));
							msg->result = noErr;
						} else if (control_io->ios2_Req.io_Error)
							msg->result = eMultiErr;
						else
							msg->result = noErr;
开发者ID:AlexandreCo,项目名称:macemu,代码行数:67,代码来源:ether_amiga.cpp

示例7: startManager

void startManager() {
#define cis Airlines[i]._cis[j]
	int i, j; /* for-loop iterator */
	while (true) {
		int numReadyAirlines = 0;
		/*
			Check-in Staff 
		*/
		if (!Manager._allCISDone) {
			int numDoneAirline = 0;
			for (i = 0; i < NUM_AIRLINES; ++i) {
				if (!Airlines[i]._CISclosed) {
					Acquire(Airlines[i]._lock);
					if (Airlines[i]._numCheckedinPassengers == Airlines[i]._numExpectedPassengers){
						if (Airlines[i]._numOnBreakCIS == NUM_CIS_PER_AIRLINE) {
							/* All Passenger have JUST went through, send CIS home */
							Release(Airlines[i]._lock); /* TODO is this necessary? */
							numDoneAirline++;
							for (j = 0; j < NUM_CIS_PER_AIRLINE; ++j) {
								/*Acquire(cis._lock);*/
								cis._done = true;
								Signal(Airlines[i]._lock, cis._commCV);
								/*Release(cis._lock);*/
							}
							Airlines[i]._CISclosed = true;
						} else {
							Release(Airlines[i]._lock); /* TODO is this necessary? */
						}
					} else {
						/* There are still passengers to serve */
						Release(Airlines[i]._lock);/* TODO is this necessary? */
						for (j = 0; j < NUM_CIS_PER_AIRLINE; ++j) {
							Acquire(Airlines[i]._cisLineLock);
							Acquire(Airlines[i]._execLineLock);
							Acquire(cis._lock);
							if ((!queue_empty(&Airlines[i]._execQueue) || cis._lineSize) && cis._state == ONBREAK) {
/*								Signal(cis._lock, cis._commCV);*/
								Signal(Airlines[i]._lock, cis._commCV);
							}
							Release(cis._lock);
							Release(Airlines[i]._execLineLock);
							Release(Airlines[i]._cisLineLock);
						}
					}
				} else {
					numDoneAirline++;
				}	
			}
			if (numDoneAirline == NUM_AIRLINES) {
				Manager._allCISDone = true;
				/* Exit all Liaisons too! */
				/* If all CIS are done, so are all Liaisons */
				Manager._allLiaisonsDone = true;
				for(i = 0; i < NUM_LIASONS; ++i) {
					Signal(Liaisons[i]._lock, Liaisons[i]._commCV);
				}
			} else {
				Manager._allCISDone = false;
			}
		} /* end if(!_allCISDone) */
#undef cis
		/* end CIS */

		/*
			Check Conveyor Belt - Cargo Handlers
		*/
		if (!Manager._allCargoDone) {
			int numDone = 0;
			bool msgToCargo = true;

			Acquire(ConveyorLock);
			for (i = 0; i < NUM_AIRLINES; ++i) {
/*Printf1("Number loaded: %d, number expected: %d\n", sizeof("Number loaded: %d, number expected: %d\n"), concat2Num(Airlines[i]._numExpectedBaggages, Airlines[i]._numLoadedBaggages));*/
				if (Airlines[i]._numExpectedBaggages == Airlines[i]._numLoadedBaggages) {
					numDone++;
				}
			}
			if (numDone == NUM_AIRLINES) {
/*Printf0("All Cargo Handlers done!\n", sizeof("All Cargo Handlers done!\n"));*/
				Manager._allCargoDone = true;
				for (i = 0; i < NUM_CARGO_HANDLERS; ++i) {
					Signal(ConveyorLock, CargoHandlers[i]._commCV);
				}
			}
			for (i = 0; i < NUM_CARGO_HANDLERS; ++i) {
				if (!queue_empty(&ConveyorBelt) && CargoHandlers[i]._state == ONBREAK) {
					Signal(ConveyorLock, CargoHandlers[i]._commCV);

					if (msgToCargo) {
						Printf0("Airport manager calls back all the cargo handlers from break\n",
							sizeof("Airport manager calls back all the cargo handlers from break\n"));
						msgToCargo = false;
					}
				}
			}
			Release(ConveyorLock);
		}
		/* end Conveyor Belt / Cargo Handlers */

		/*
//.........这里部分代码省略.........
开发者ID:kyuhyunc,项目名称:csci350,代码行数:101,代码来源:airportsim.c

示例8: startScreeningOfficer

void startScreeningOfficer() {
	#define mySO ScreeningOfficers[_myIndex]
	int _myIndex;
	/* Claim my screening officer */
	Acquire(GlobalDataLock);
    _myIndex = NumActiveScreeningOfficers++;
    Release(GlobalDataLock);

    /* Get to work! */
	while (true) {
		int suspicionLevel = false;
		int shortestLineIndex = -1; /* impossible value */
		int i; /* iterator */
		Acquire(OfficersLineLock);
		if (queue_empty(&OfficersLine)) {
			mySO._state = ONBREAK;
/*Printf1("SO %d is going to sleep\n", sizeof("SO %d is going to sleep\n"), _myIndex);*/
			/* Done? */
			if (Manager._allSODone) {
				Release(OfficersLineLock);
				break;
			}
			Wait(OfficersLineLock, mySO._commCV); /* Wait for a passenger */
			/* Done? */
			if (Manager._allSODone) {
				Release(OfficersLineLock);
				break;
			}
/*Printf1("SO %d is waking up\n", sizeof("SO %d is waking up\n"), _myIndex);*/
		}
		if (!queue_empty(&OfficersLine)) {
			Acquire(mySO._lock);
			mySO._state = BUSY;
			mySO._currentPassenger = queue_pop(&OfficersLine);
			Passengers[mySO._currentPassenger]._officerID = _myIndex;
			Signal(OfficersLineLock, OfficersLineCV); /* Wake up passenger */
			Release(OfficersLineLock);
			Wait(mySO._lock, mySO._commCV); /* Wait for passenger to approach */
			/* Generate PASS/FAIL Results */
			suspicionLevel = (17 * mySO._currentPassenger) % 10; /* PSUEDO rand() */
			SecurityFailResults[mySO._currentPassenger] = suspicionLevel > 8;
			if (SecurityFailResults[mySO._currentPassenger]) { /* FAIL */
				Printf1("Screening officer %d is suspicious of the hand luggage of passenger %d\n",
					sizeof("Screening officer %d is suspicious of the hand luggage of passenger %d\n"),
					concat2Num(_myIndex, mySO._currentPassenger));
			} else { /* PASS */
				Printf1("Screening officer %d is not suspicious of the hand luggage of passenger %d\n",
					sizeof("Screening officer %d is not suspicious of the hand luggage of passenger %d\n"),
					concat2Num(_myIndex, mySO._currentPassenger));
			}
			/* Find an Available Security Inspector */
			while (shortestLineIndex == -1) {
/*Printf1("SO %d is trying to find SI\n", sizeof("SO %d is trying to find SI\n"), _myIndex);*/
				#define inspector SecurityInspectors[i]
				Acquire(InspectorLineLock);	
/*Printf1("SO %d acquired InspectorLineLock\n", sizeof("SO %d acquired InspectorLineLock\n"), _myIndex);*/
				for (i = 0; i < NUM_SECURITY_INSPECTORS; ++i) {
					Acquire(inspector._lock);
/*Printf1("SO %d is checking SI %d\n", sizeof("SO %d is checking SI %d\n"), concat2Num(_myIndex, i));*/
					if (inspector._state == AVAIL && inspector._newPassenger == -1) {
						/* Found an inspector! */
						shortestLineIndex = inspector._id;
						inspector._newPassenger = mySO._currentPassenger;
						Release(inspector._lock);
						break;
					}
					Release(inspector._lock);
				}
				Release(InspectorLineLock);
				if (shortestLineIndex == -1) {
Printf1("SO %d is about to Yield\n", sizeof("SO %d is about to Yield\n"), _myIndex);
					Yield();
				}
				#undef inspector
/*				Wait(mySO._lock, mySO._commCV);*/
			}
			/* Found an inspetor for the passenger */
			Passengers[mySO._currentPassenger]._inspectorID = shortestLineIndex;
			Printf1("Screening officer %d directs passenger %d to security inspector %d\n",
				sizeof("Screening officer %d directs passenger %d to security inspector %d\n"),
				concat3Num(_myIndex, mySO._currentPassenger, shortestLineIndex));
			Signal(mySO._lock, mySO._commCV);
			Release(mySO._lock);
		} else {
			Release(OfficersLineLock);
		}
	}
	Exit(0);
}
开发者ID:kyuhyunc,项目名称:csci350,代码行数:89,代码来源:airportsim.c

示例9: startSecurityInspector

void startSecurityInspector() {
	#define mySI SecurityInspectors[_myIndex]
	int _myIndex;
	/* Claim my security insepctor */
	Acquire(GlobalDataLock);
/*    _myIndex = NumActiveScreeningOfficers++;*/
	_myIndex = NumActiveSecurityInspectors++;
    Release(GlobalDataLock);

    /* Start work */
    while (true) {
    	bool suspicious, guilty;
    	Acquire(mySI._lock);
/*Printf1("SI %d has _newPassenger", sizeof("SI %d has _newPassneger"), _myIndex);
Printf1("%d\n", sizeof("%d\n"), mySI._newPassenger);*/
    	if (mySI._rtnPassSize == 0 && mySI._newPassenger == -1) {
    		mySI._state = AVAIL;
			/* Done? */
			if (Manager._allSIDone) {
				Release(mySI._lock);
				break;
			}
    		Wait(mySI._lock, mySI._commCV); /* Wait for Passenger to come */
			/* Done? */
			if (Manager._allSIDone) {
				Release(mySI._lock);
				break;
			}
    		mySI._state = BUSY;
    	}
    	if (mySI._rtnPassSize > 0) { /* priority to returning passengers */
    		while (mySI._rtnPassSize > 0) {
    			Signal(mySI._lock, mySI._rtnPassCV); /* Wake up passener */
    			Wait(mySI._lock, mySI._rtnPassCV); /* Wait on passenger */
    			Printf1("Security inspector %d permits returning passenger %d to board\n",
    				sizeof("Security inspector %d permits returning passenger %d to board\n"),
    				concat2Num(_myIndex, mySI._rtnPassenger));
    			mySI._passCount++;
/*    			mySI._rtnPassenger--;*/
				mySI._rtnPassSize--;
    			Signal(mySI._lock, mySI._rtnPassCV);
    		}
    		mySI._rtnPassenger = -1;
    	}
    	if (mySI._newPassenger != -1) { /* I have a new passenger to help */ 
    		suspicious = (mySI._newPassenger * 23) % 10 > 7; /* Psuedo Random */
    		guilty = suspicious || SecurityFailResults[mySI._newPassenger];
    		if (suspicious) {
    			Printf1("Security Inspector %d is suspicious of the hand luggage of passenger %d\n",
    				sizeof("Security Inspector %d is suspicious of the hand luggage of passenger %d\n"),
    				concat2Num(_myIndex, mySI._newPassenger));
    		} else {
    			Printf1("Security Inspector %d is not suspicious of the hand luggage of passenger %d\n",
    				sizeof("Security Inspector %d is not suspicious of the hand luggage of passenger %d\n"),
    				concat2Num(_myIndex, mySI._newPassenger));
    		}
    		if (guilty) {
				Passengers[mySI._newPassenger]._furtherQuestioning = true;
    			Printf1("Security inspector %d asks passenger %d to go for further examination\n", 
    				sizeof("Security inspector %d asks passenger %d to go for further examination\n"),
    				concat2Num(_myIndex, mySI._newPassenger));
    		} else {
    			Printf1("Security inspector %d allows passenger %d to board \n",
    				sizeof("Security inspector %d allows passenger %d to board \n"),
    				concat2Num(_myIndex, mySI._newPassenger));
    			mySI._passCount++;
    		}
    		mySI._newPassenger = -1;
    		Signal(mySI._lock, mySI._newPassCV);
    	}
    	Release(mySI._lock);
    }
    #undef mySI
	Exit(0);
}
开发者ID:kyuhyunc,项目名称:csci350,代码行数:75,代码来源:airportsim.c

示例10: startCheckInStaff

void startCheckInStaff() {
#define myAirline Airlines[_myAirline]
#define my myAirline._cis[_myIndex]
#define passenger Passengers[my._currentPassenger]
	/* Claim my CIS */
	int _myAirline;
	int _myIndex; /* ID for currentThread */
    Acquire(GlobalDataLock);
	_myIndex = NumActiveCIS % NUM_CIS_PER_AIRLINE;
	_myAirline = NumActiveCIS / NUM_CIS_PER_AIRLINE;
    NumActiveCIS++;
    Release(GlobalDataLock);

    while (true) {
		/* Check lines */
		Acquire(myAirline._lock);
		if (my._lineSize == 0 && queue_empty(&myAirline._execQueue)) {
			/*Printf0("1\n", sizeof("1\n"));*/
			my._state = ONBREAK;
			/* 'Clock Out' for Break */
			myAirline._numOnBreakCIS++;
/*Printf1("Cis %d going to sleep\n", sizeof("Cis %d going to sleep\n"), _myIndex);*/
			Wait(myAirline._lock, my._commCV); /* Wait on Manager */ /* TODO - make sure okay to wait on aiport lock... maybe better? */
/*Printf1("Cis %d woke up by manager\n", sizeof("Cis %d woke up by manager\n"), _myIndex);*/
			/* Time to go home! TGIF! */
			if (my._done) {
				Printf1("Airline check-in staff %d of airline %d is closing the counter\n",
					sizeof("Airline check-in staff %d of airline %d is closing the counter\n"),
					concat2Num(_myIndex, _myAirline));
/*				Acquire(my._lock);*/
				Release(myAirline._lock);
/*				Wait(my._lock, my._commCV); *//* Wait forever, basically */
/*				Release(my._lock); *//* Never reaches here, but whatever... */
				break;
			}
			myAirline._numOnBreakCIS--;
		}
		/* Start helping a passenger */
		my._state = BUSY;
		Acquire(myAirline._cisLineLock);
		Acquire(myAirline._execLineLock);
		if (queue_size(&myAirline._execQueue) > 0) {
			my._currentPassenger = queue_pop(&myAirline._execQueue);
			passenger._cisID = _myIndex;
			Printf1("Airline check-in staff %d of airline %d serves an executive class passenger and economy line length = %d\n",
				sizeof("Airline check-in staff %d of airline %d serves an executive class passenger and economy line length = %d\n"),
				concat3Num(_myIndex, _myAirline, my._lineSize));
			Signal(myAirline._execLineLock, myAirline._execLineCV); /* Signal Passenger */
		} else if (my._lineSize > 0) {
			Printf1("Airline check-in staff %d of airline %d serves an economy class passenger and executive class line length = %d\n",
				sizeof("Airline check-in staff %d of airline %d serves an economy class passenger and executive class line length = %d\n"),
				concat3Num(_myIndex, _myAirline, queue_size(&myAirline._execQueue)));
			Signal(myAirline._cisLineLock, my._lineCV);
/*Printf1("Cis %d of airline %d wakes up passenger\n", sizeof("Cis %d of airline %d wakes up passenger\n"), _myIndex*1000+_myAirline);*/
		}
		/* Interact with Passenger */
		Acquire(my._lock);
		Release(myAirline._cisLineLock);
		Release(myAirline._execLineLock);
		Release(myAirline._lock);
		if (my._lineSize > 0 || my._currentPassenger != -1) {
/*Printf1("Cis %d of airline %d goes to sleep\n", sizeof("Cis %d of airline %d goes to sleep\n"), _myIndex*1000+_myAirline);*/
			Wait(my._lock, my._commCV); 
		} /* Otherwise, Manager woke you up for no reason */
		if (my._currentPassenger != -1) {
			int i;
			/* Assign seat number */
			Acquire(myAirline._lock);
			passenger._ticket._seat = myAirline._numCheckedinPassengers;
			myAirline._numCheckedinPassengers++;
			Release(myAirline._lock);
			/* Deal with baggage */
			Acquire(ConveyorLock);
			for (i = 0; i < passenger._numBaggages; ++i) {
				/*Printf0("3\n", sizeof("1\n"));*/
/*				#define bIndex (passenger._id * 3) + i
				#define bag Baggages[bIndex]*/
				#define bag Baggages[(passenger._id*3)+i]
				bag._airline = _myAirline; /* Tag the bag */
/*				queue_insert(&ConveyorBelt, bIndex);*/
				queue_insert(&ConveyorBelt, passenger._id*3+i);
				Printf1("Airline check-in staff %d of airline %d dropped bags to the conveyor system \n",
					sizeof("Airline check-in staff %d of airline %d dropped bags to the conveyor system \n"),
					concat2Num(_myIndex, _myAirline));
/*				myAirline._numExpectedBaggages++;*/
				my._weightCount += bag._weight;
				#undef bag
/*				#undef bIndex*/
			}
			Release(ConveyorLock);
			/* Direct Passenger to Airline */
			if (passenger._ticket._executive) {
				Printf2("Airline check-in staff %d of airline %d informs executive class passenger %d to board at gate %d\n",
					sizeof("Airline check-in staff %d of airline %d informs executive class passenger %d to board at gate %d\n"),
/*					concat3Num(_myAirline, my._currentPassenger, _myAirline), _myIndex);*/
					concat3Num(_myIndex, _myAirline, my._currentPassenger), _myAirline);
			} else {
				Printf2("Airline check-in staff %d of airline %d informs economy class passenger %d to board at gate %d\n",
					sizeof("Airline check-in staff %d of airline %d informs economy class passenger %d to board at gate %d\n"),
/*					concat3Num(_myAirline, my._currentPassenger, _myAirline), _myIndex);*/
//.........这里部分代码省略.........
开发者ID:kyuhyunc,项目名称:csci350,代码行数:101,代码来源:airportsim.c

示例11: Fork

/*
	Start Functions - functions called by Fork() syscall.
*/
void startPassenger() {    
#define my Passengers[_myIndex]
#define liaison Liaisons[my._liaisonID]
	/* Claim my Passenger */
	int i, j; /* for-loop iterators */
	int _myIndex; /* ID for currentThread */
	int _minLineSize;

    Acquire(GlobalDataLock);
    _myIndex = NumActivePassengers++;
    Release(GlobalDataLock);

    /*
		Liaison Interaction
    */
	Acquire(LiaisonLineLock);
	_minLineSize = Liaisons[0]._lineSize;
	/* Find shortest line */
	for (i = 1; i < NUM_LIASONS; i++) {
		if (Liaisons[i]._lineSize < _minLineSize) {
			_minLineSize = Liaisons[i]._lineSize;
			my._liaisonID = i;
		}
	}

	Printf1("Passenger %d chose Liaison %d with a line length %d\n", 
		sizeof("Passenger %d chose Liaison %d with a line length %d\n"), 
		concat3Num(_myIndex, my._liaisonID, liaison._lineSize));
	/* Get in line? */
	if (liaison._state == BUSY) {
/*		Printf0("Passenger says liaison is BUSY\n", 
			sizeof("Passenger says liaison is BUSY\n"));
		Printf1("Passenger's liaison id: %d\n", 
			sizeof("Passenger's liaison id: %d\n"),
			_myIndex);*/
		liaison._lineSize++;
		Wait(LiaisonLineLock, liaison._lineCV);
		liaison._lineSize--;
	}
	Printf1("Passenger %d is moving along...\n", sizeof("Passenger %d is moving along...\n"), _myIndex);
	/* Go to Liaison */
	Acquire(liaison._lock);
	Release(LiaisonLineLock);
	/* Give Liaison my Passenger info */
	liaison._passCount[my._ticket._airline]++;
	liaison._bagCount[my._ticket._airline] += my._numBaggages;
	liaison._currentPassenger = _myIndex;
	Signal(liaison._lock, liaison._commCV); /* Signal Liaison */
	Wait(liaison._lock, liaison._commCV); /* Wait for Liaison */
	Printf1("Passenger %d of Airline %d is directed to the check-in counter\n", 
		sizeof("Passenger %d of Airline %d is directed to the check-in counter\n"),
		concat2Num(_myIndex, my._ticket._airline));
	Signal(liaison._lock, liaison._commCV);
	Release(liaison._lock);
#undef liaison
	/* end Liaison Interaction */

	/*
		Check-in Staff Interaction
	*/
#define myAirline Airlines[my._ticket._airline]
#define myCIS myAirline._cis[my._cisID]
	if (my._ticket._executive) {
		Acquire(myAirline._execLineLock);
		queue_insert(&myAirline._execQueue, _myIndex);
		Printf1("Passenger %d of Airline %d is waiting in the executive class line\n", 
			sizeof("Passenger %d of Airline %d is waiting in the executive class line\n"),
			concat2Num(_myIndex, my._ticket._airline));
/*		Wait(myAirline._execLineLock, myAirline._execLineLock); *//* Wait on CIS */
		Wait(myAirline._execLineLock, myAirline._execLineCV); /* Wait on CIS */
	} else { /* Economy */
		Acquire(myAirline._cisLineLock);
		/* Find shortest line */
		_minLineSize = myAirline._cis[0]._lineSize; /* declare at top of startPassenger */
		my._cisID = 0;
		for (i = 0; i < NUM_CIS_PER_AIRLINE; ++i) {
			if (myAirline._cis[i]._lineSize < _minLineSize) {
				_minLineSize = myAirline._cis[i]._lineSize;
				my._cisID = i;
			}
		}
		Printf2("Passenger %d of Airline %d chose Airline Check-In staff %d with a line length %d\n", 
			sizeof("Passenger %d of Airline %d chose Airline Check-In staff %d with a line length %d\n"),
			concat3Num(_myIndex, my._ticket._airline, my._cisID), _minLineSize);
			myCIS._lineSize++;
/*Printf1("Passenger %d of Airline %d is going to sleep and should be woken up by cis %d\n", sizeof("Passenger %d of Airline %d is going to sleep and should be woken up by cis %d\n"), concat3Num(_myIndex, my._ticket._airline, my._cisID));*/
		Wait(myAirline._cisLineLock, myCIS._lineCV);
/*Printf1("Passenger %d of Airline %d is woken up by cis %d\n", sizeof("Passenger %d of Airline %d is woken up by cis %d\n"), concat3Num(_myIndex, my._ticket._airline, my._cisID));*/
	}
	Acquire(myCIS._lock);
	if (my._ticket._executive) {
		Release(myAirline._execLineLock);
	} else {
		myCIS._lineSize--;
		Release(myAirline._cisLineLock);
	}
	/* Give baggage to CIS */
//.........这里部分代码省略.........
开发者ID:kyuhyunc,项目名称:csci350,代码行数:101,代码来源:airportsim.c

示例12: controller_routine

/*}}}*/
static void controller_routine(char *arg)
{ int		 number_workers;
  int		 first_channel;
  int		 i;
  char		*buf;
  int		*wbuf;
  int		 endtime;
  int		 size;
  int		 checksum;
  int		 worker;
  FullStats	 stats;

#define to_worker(i)   (first_channel + i + i + 1)
#define from_worker(i) (first_channel + i + i)

/*{{{  initialise */
  if (sscanf(arg, "%d.%d", &number_workers, &first_channel) != 2)
   Fatal("controller routine, invalid argument %s", arg);

  logname = getenv("HWTEST_LOGFILE");
  if (logname == NULL)
   logname = "/helios/local/tests/hwtest/hwtest.log";

  buf = malloc(MaxCommsTransfer);
  if (buf == NULL)
   Fatal("controller routine, out of memory.");
  wbuf = (int *) buf;

  for (worker = 0; worker < number_workers; worker++)
   { if (write(to_worker(worker), buf, sizeof(int)) != sizeof(int))
      Fatal("controller routine, failed to send initial data to worker %d", worker);
     if (full_read(from_worker(worker), buf, sizeof(int)) != sizeof(int))
      Fatal("controller routine, failed to receive initial data from worker %d", worker);
   }

	/* The main memory tester can now allocate its buffers.		*/
  Signal(&ThreadsReady);

  endtime  = ((((24 * Days) + Hours) * 60) + Minutes) * 60;
  endtime += time(NULL);
/*}}}*/
/*{{{  communication with workers */
  while (endtime > time(NULL))
   { 
     if (!ExtraComms)
      { Delay(5 * OneSec); continue; }

     for (size = 32; size <= MaxCommsTransfer; size *= 2)
      {		/* initialise the buffer with random data.		*/
	wbuf[0] = 0;	/* checksum */
	for (i = 1; i < (size / sizeof(int)); i++)
	 { wbuf[i] = hw_rand();
	   wbuf[0] += wbuf[i];
         }

	for (worker = 0; worker < number_workers; worker++)
	 { if (write(to_worker(worker), (char *) &size, sizeof(int)) != sizeof(int))
	   	Fatal("controller routine failed to send size %d to worker %d", size, worker);
	   if (write(to_worker(worker), buf, size) != size)
	   	Fatal("controller routine failed to write block of %d bytes to worker %d", size, worker);
	   if (full_read(from_worker(worker), buf, size) != size)
		Fatal("controller routine, failed to read back buffer of %d bytes from worker %d", size, worker);
	   for (i = 1, checksum = 0; i < (size / sizeof(int)); i++)
	    checksum += wbuf[i];
	   if (checksum != wbuf[0])
	    { Report("controller routine, corruption in buffer of %d bytes read back from worker %d",
	 		size, worker);
	      wbuf[0] = checksum;
	    }
         }	/* for all the workers		*/

        if (endtime < time(NULL))
	  break;
      }		/* sizes loop			*/
   }		/* while (endtime > time())	*/
/*}}}*/
/*{{{  terminating the workers */
	/* At this point the runtime has expired and it is necessary	*/
	/* to send a terminate message to all the workers. Also the	*/
	/* Finished flag should be set so that the testing going on	*/
	/* within the controller will stop.				*/
  Finished = TRUE;
  size     = 0;
  for (worker = 0; worker < number_workers; worker++)
   if (write(to_worker(worker), (char *) &size, sizeof(int)) != sizeof(int))
    Fatal("controller routine, failed to send terminate request to worker %d", worker);
/*}}}*/
/*{{{  collecting the stats */
	/* Now collect together the results from all the workers.	*/
  TotalStats.OffchipMemoryG	=
  TotalStats.OffchipMemoryM	=
  TotalStats.OffchipMemoryK	=
  TotalStats.OffchipFailures	=
  TotalStats.OnchipMemoryG	=
  TotalStats.OnchipMemoryM	=
  TotalStats.OnchipMemoryK	=
  TotalStats.OnchipFailures	=
  TotalStats.LinkG		=
  TotalStats.LinkM		=
//.........这里部分代码省略.........
开发者ID:jamjr,项目名称:Helios-NG,代码行数:101,代码来源:hwtest.c

示例13: netexec

/* Run the given command line as if with exec. What we actually do is fork the
   command line as a subprocess, then loop, relaying data between the socket and
   the subprocess. This allows Ncat to handle SSL from the socket and give plain
   text to the subprocess, and also allows things like logging and line delays.
   Never returns. */
void netexec(struct fdinfo *info, char *cmdexec)
{
    int child_stdin[2];
    int child_stdout[2];
    int pid;
    int crlf_state;

    char buf[DEFAULT_TCP_BUF_LEN];
    int maxfd;

    if (o.debug) {
        switch (o.execmode) {
        case EXEC_SHELL:
            logdebug("Executing with shell: %s\n", cmdexec);
            break;
#ifdef HAVE_LUA
        case EXEC_LUA:
            logdebug("Executing as lua script: %s\n", cmdexec);
            break;
#endif
        default:
            logdebug("Executing: %s\n", cmdexec);
            break;
        }
    }

    if (pipe(child_stdin) == -1 || pipe(child_stdout) == -1)
        bye("Can't create child pipes: %s", strerror(errno));

    pid = fork();
    if (pid == -1)
        bye("Error in fork: %s", strerror(errno));
    if (pid == 0) {
        /* This is the child process. Exec the command. */
        close(child_stdin[1]);
        close(child_stdout[0]);

        /* We might have turned off SIGPIPE handling in ncat_listen.c. Since
           the child process SIGPIPE might mean that the connection got broken,
           ignoring it could result in an infinite loop if the code here
           ignores the error codes of read()/write() calls. So, just in case,
           let's restore SIGPIPE so that writing to a broken pipe results in
           killing the child process. */
        Signal(SIGPIPE, SIG_DFL);

        /* rearrange stdin and stdout */
        Dup2(child_stdin[0], STDIN_FILENO);
        Dup2(child_stdout[1], STDOUT_FILENO);

        setup_environment(info);

        switch (o.execmode) {
        char **cmdargs;

        case EXEC_SHELL:
            execl("/bin/sh", "sh", "-c", cmdexec, (void *) NULL);
            break;
#ifdef HAVE_LUA
        case EXEC_LUA:
            lua_run();
            break;
#endif
        default:
            cmdargs = cmdline_split(cmdexec);
            execv(cmdargs[0], cmdargs);
            break;
        }

        /* exec failed. */
        die("exec");
    }

    close(child_stdin[0]);
    close(child_stdout[1]);

    maxfd = child_stdout[0];
    if (info->fd > maxfd)
        maxfd = info->fd;

    /* This is the parent process. Enter a "caretaker" loop that reads from the
       socket and writes to the subprocess, and reads from the subprocess and
       writes to the socket. We exit the loop on any read error (or EOF). On a
       write error we just close the opposite side of the conversation. */
    crlf_state = 0;
    for (;;) {
        fd_set fds;
        int r, n_r;

        FD_ZERO(&fds);
        FD_SET(info->fd, &fds);
        FD_SET(child_stdout[0], &fds);

        r = fselect(maxfd + 1, &fds, NULL, NULL, NULL);
        if (r == -1) {
            if (errno == EINTR)
//.........这里部分代码省略.........
开发者ID:EricGershman,项目名称:nmap,代码行数:101,代码来源:ncat_posix.c

示例14: request

void* request (void* data){
    pthread_detach(pthread_self());
	int serverfd=*(int*)data;
	int clientfd;
	char headerBuff[MAXHEADERSIZE];
    char RequestHeader[MAXHEADERSIZE];
	char hostname[MAXHOSTSIZE];
	char Buffer[MAXBUFFERSIZE];
    char* urlname; 
    char* cache_buff;
    int cache_size = 0;
	int error;
	int byte;
	int getbyte;
    int cachehit = 0;
	Signal(SIGPIPE,	SIG_IGN);
    free(data);
    rio_t serverrio_t;
//    Rio_readinitb(&serverrio_t,serverfd);
	/*set the structure, and set port to 80*/ 
	printf("to Start read %u\n",pthread_self());

	byte=Rio_readn(serverfd,headerBuff,sizeof(headerBuff));
//	byte=read(serverfd,headerBuff,sizeof(headerBuff));
	printf("finish read byte:%d  %u\n",byte,pthread_self());
	if(byte<=0){
		close(serverfd);
        pthread_exit(NULL);
	}
	printf("%s\n",headerBuff);
	fflush(stdout);

    /*Check if the webpage is cached. if cache hit, no need to connect to server*/
    if(takeurlname(headerBuff,&urlname) == 0){
        perror("Cannot find url name\n");
        close(serverfd);
        pthread_exit(NULL);
    }

	printf("Try to get cached data: %u\n",pthread_self());
    /* Try to get cached data, must check no thread writing the cache,
     * and use FILO architecture to lock when there threads reading cache*/
/*
    P(&mutex);
    readcnt++;
    if(readcnt == 1)
        P(&w);
    V(&mutex);
    if( Get_cachedata(urlname,serverfd) > 0){
        cachehit = 1;
    }

    P(&mutex);
    readcnt--;
    if(readcnt == 0)
        V(&w);
    V(&mutex);
    
    if(cachehit){
        close(serverfd);
        pthread_exit(NULL);
    }
*/
	printf("No cached data try connect: %u\n",pthread_self());
    /* Webpage not cached, retrieve information from web server */

	if( (clientfd=socket(AF_INET,SOCK_STREAM,0))<0){
		perror("socket");
        close(serverfd);
        pthread_exit(NULL);
	} 
//    Rio_readinitb(&clientrio_t,clientfd);


    /* Set the request to the server */ 
	if( settherequest(headerBuff,RequestHeader,hostname) == 0){
		perror("Set Request Error\n");
        close(serverfd);
        pthread_exit(NULL);
	}
	printf("%s\n",RequestHeader);
	fflush(stdout);
   
    /*get server's address info*/
	struct addrinfo *hostinfo;
	if( (error=getaddrinfo(hostname,"http",NULL,&hostinfo)) >0){
		perror("hostinfo");
        close(serverfd);
        pthread_exit(NULL);
	}
    /* connect to the server*/
	if( (connect(clientfd,hostinfo->ai_addr,hostinfo->ai_addrlen))<0){
		perror("connect");
        close(serverfd);
		return NULL;
	}
	printf("Ready to transmitt data: %u\n",pthread_self());
	/*pass the request from browser to server*/
	Rio_writen(clientfd,RequestHeader,byte);
	/*read the information from web server and send it to browser*/
//.........这里部分代码省略.........
开发者ID:sam9595,项目名称:15213_Proxy,代码行数:101,代码来源:proxy_bk.c

示例15: ModuleResize


//.........这里部分代码省略.........
		system("/sbin/dhcpcd eth0");
		system("ifconfig eth0");
#endif
		gSysParaT.sysPara.dwNetMark = GetNetmask("eth0");
		gSysParaT.sysPara.dwAddr = GetIPaddr("eth0");
		get_gateway(gateway);
		gSysParaT.sysPara.dwGateWay = 	get_gateway(gateway);
		DEBUG(DL_DEBUG, "gateway =%s\n", gateway);
	} else {
		printf("i will set static ip.\n");
		SetEthConfigIP(gSysParaT.sysPara.dwAddr, gSysParaT.sysPara.dwNetMark);
		SetEthConfigGW(gSysParaT.sysPara.dwGateWay);
	}

	system("ifconfig");

	strcpy(gSysParaT.sysPara.strVer, box_version);
	initSetParam();
	DEBUG(DL_DEBUG, "logo=%d text=%d ,texthandle->enable=%d,texthandle->showtime=%d\n", outputhandle.logo_show, outputhandle.text_show, texthandle->enable, texthandle->showtime);
#ifdef DSS_ENC_1100_1200
	/*open lcd initial*/
	OpenLCDCom(); //matchbox ++
	gblLoadIDX(); //matchbox ++

	if(-2 == ReadDeviceType(DTYPECONFIG_NAME, 1)) {
		ReadDeviceType(DTYPECONFIG_NAME, 0);
	}

	GetDeviceType(devicebuf);
	DEBUG(DL_DEBUG, "DTYPECONFIG_NAME gDeviceType = %s\n", devicebuf);
#endif

	/*取消PIPE坏的信号*/
	Signal(SIGPIPE, SIG_IGN);
	/* Set the priority of this whole process to max (requires root) */
	setpriority(PRIO_PROCESS, 0, -20);
	/*初始化高码流视频编码库参数*/
	InitVideoEncParams(&gSysParaT.videoPara[PORT_ONE]);
	/*初始化低码流视频编码库参数*/
	InitLowRateParams(&gSysParaT.videoPara[PORT_TWO]);
	/*初始化音频编码库参数*/
	InitAudioEncParams(&gSysParaT.audioPara[PORT_ONE]);
	/* Initialize the mutex which protects the global data */
	pthread_mutex_init(&gbl.mutex, NULL);
	/* Initialize Codec Engine runtime */
	CERuntime_init();
	/* Initialize Davinci Multimedia Application Interface */
	Dmai_init();
	closeWatchDog();

	mid_timer_init();
		
	initWatchDog();
#ifdef CL4000_DVI_SDI

	if(gblGetRemoteIndex() < MAX_FAR_CTRL_NUM) {
		result = InitRemoteStruct(gblGetRemoteIndex());
	}

	gRemoteFD = CameraCtrlInit(PORT_COM2);

	if(gRemoteFD <= 0) {
		DEBUG(DL_ERROR, "Initial CameraCtrlInit() Error\n");
	}

#else
开发者ID:Lichanglu,项目名称:ENC-1260,代码行数:67,代码来源:main.c


注:本文中的Signal函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。