コード例 #1
0
ファイル: p1.c プロジェクト: myyerrol/operating_system_test
int main( int argc , char ** argv )
{

  int i ;     	/* loop index */
  int scr_sem; 		/* id of screen semaphore */
  int prod_sem,cons_sem;	

  scr_sem = Create_Semaphore ( "screen" , 1 ) ;   /* register for screen use */

  prod_sem = Create_Semaphore ( "prod_sem" , 0 ) ; 

  cons_sem = Create_Semaphore ( "cons_sem" , 1 ) ;  


  for (i=0; i < 5; i++) {
    P(cons_sem);
    Print ("Produced %d\n",i) ;
    V(prod_sem);
  }
  
  Destroy_Semaphore(scr_sem);
  Destroy_Semaphore(prod_sem);
  Destroy_Semaphore(cons_sem);

  return 0;
}
コード例 #2
0
ファイル: ping.c プロジェクト: dasGringuen/os-implementation
int main(int argc , char ** argv)
{
  int i,j ;     	/* loop index */
  int scr_sem; 		/* id of screen semaphore */
  int time; 		/* current and start time */
  int ping,pong;	/* id of semaphores to sync processes b & c */

  time = Get_Time_Of_Day();
  scr_sem = Create_Semaphore ("screen" , 1) ;   /* register for screen use */
  ping = Create_Semaphore ("ping" , 1) ;   
  pong = Create_Semaphore ("pong" , 0) ;  

  for (i=0; i < 5; i++) {
       P(pong);
       for (j=0; j < 35000; j++);
       Print("Ping\n ");
       V(ping);
  }

  time = Get_Time_Of_Day() - time;
  P (scr_sem) ;
  Print ("Process Ping is done at time: %d\n", time) ;
  V(scr_sem);

  Destroy_Semaphore(pong);
  Destroy_Semaphore(ping);
  Destroy_Semaphore(scr_sem);

  return (0);

}
コード例 #3
0
PGPdiskSemaphore::~PGPdiskSemaphore()
{
	if (NULL!=(int)(mSemHandle))
	{
		Destroy_Semaphore(mSemHandle);
		mSemHandle = NULL;
	}
}
コード例 #4
0
ファイル: Blkmover.c プロジェクト: xfxf123444/japan
NTSTATUS	PostScript(BOOL bReboot)
#endif
{
    PBYTE	pSector;
    DWORD	dwHashIndex;
    DWORD	dwSectorNum;
    PBYTE	pSectors;
    BOOL	bSucc;
    BOOL	bRetVal = TRUE;
    int 	nTotalSectors;
    int 	n;

#ifdef WIN_9X
    if (bReboot)
      Reboot();
    Wait_Semaphore(g_hSemSyncIO,BLOCK_THREAD_IDLE);
    EnableOrDisable(FALSE);
    if (g_hSemInternalReq)
		Destroy_Semaphore(g_hSemInternalReq);
#else
    if (g_MoverCache.pCache)
		ExFreePool(g_MoverCache.pCache);
	
	if(g_pMoverData)
	{
		ExFreePool(g_pMoverData);
		g_pMoverData = NULL;
	}
	if(g_pSharkData)
	{
		ExFreePool(g_pSharkData);
		g_pSharkData	= NULL;
	}
	if(g_partitionInfo)
	{
		ExFreePool(g_partitionInfo);
		g_partitionInfo = NULL;
	}
	g_bBlkMovSucc	 = FALSE;
	g_bPartitionSet  = FALSE;
#endif

#ifdef WIN_9X
    Signal_Semaphore(g_hSemSyncIO);
    return  bRetVal;
#else
	return STATUS_SUCCESS;
#endif
}   //	PostScript
コード例 #5
0
ファイル: sbbsexec.cpp プロジェクト: K6BSD/SBBSUnstable
BOOL SBBSExecInt14::handler(VMHANDLE hVM, CLIENT_STRUCT* pRegs, DWORD intno)
{
	BYTE*	buffer;
	BYTE	ch;
	WORD	buflen;
    WORD	rd,wr;
    WORD	avail;
	vm_t*	vm = find_vm(hVM);

	if(vm==NULL || vm->mode!=SBBSEXEC_MODE_FOSSIL) {
		return(FALSE); // Tells VMM that interrupt was not handled
	}


	DBTRACEx(4,"Int14 func",_clientAH);

	switch(_clientAH) {
		case 0x00:	/* Initialize/Set baud rate */
        	DBTRACE(0,"Int14 init");
			_clientAX=PortStatus(vm);
			break;
		case 0x01: /* write char to com port */
        	if(RingBufFree(&vm->out)<2) {
            	DBTRACEx(1,"!OUTPUT BUFFER OVERFLOW, hVM", hVM);
            	vm->output_sem=Create_Semaphore(0);
                Wait_Semaphore(vm->output_sem,BLOCK_THREAD_IDLE);
                Destroy_Semaphore(vm->output_sem);
                vm->output_sem=NULL;
                if(!vm->online) {
                	DBTRACE(0,"!USER HUNG UP");
                	return(true);
                }
            }
			ch=_clientAL;
			RingBufWrite(&vm->out,&ch,1);
#if 0	/* Now done in SBBS.DLL/XTRN.CPP */
			if(ch==0xff) { /* escape TELNET IAC */
				RingBufWrite(&vm->out,&ch,1);
				DBTRACE(1,"Escaped IAC in output stream");
			}
#endif
			vm->overrun=false;
			_clientAX=PortStatus(vm);
			break;
		case 0x02: /* read char from com port */
			if(!RingBufFull(&vm->in)) {
            	DBTRACEx(0,"Waiting on input semaphore, hVM", hVM);
            	vm->input_sem=Create_Semaphore(0);
                Wait_Semaphore(vm->input_sem,BLOCK_THREAD_IDLE);
                Destroy_Semaphore(vm->input_sem);
                vm->input_sem=NULL;
#if 0
				_clientAH=0x80;	/* timed-out */
				return(TRUE);
#endif
			}
			RingBufRead(&vm->in,&ch,1);
			_clientAH=0;
			_clientAL=ch;
			break;
		case 0x03:	/* request status */
			_clientAX=PortStatus(vm);
			break;
		case 0x04:	/* initialize */
			DBTRACE(0,"Int14 func 4 init");
			_clientAX=0x1954;	/* magic number = success */
			_clientBH=5;		/* FOSSIL rev */
			_clientBL=0x1B;		/* maximum FOSSIL func supported */
			break;
        case 0x08:	// flush output buffer
            DBTRACE(0,"Int14 FLUSH OUTPUT BUFFER");
            vm->output_sem=Create_Semaphore(0);
            Wait_Semaphore(vm->output_sem,BLOCK_THREAD_IDLE);
            Destroy_Semaphore(vm->output_sem);
            vm->output_sem=NULL;
			break;
        case 0x09:	// purge output buffer
        	DBTRACE(0,"Int14 PURGE OUTPUT BUFFER");
        	RingBufReInit(&vm->out);
            break;
        case 0x0A:	// purge input buffer
        	DBTRACE(0,"Int14 PURGE INPUT BUFFER");
        	RingBufReInit(&vm->in);
            break;
		case 0x0B: /* write char to com port, no wait */
        	if(RingBufFree(&vm->out)<2) {
            	_clientAX=0; // char was not accepted
                break;
            }
			ch=_clientAL;
			RingBufWrite(&vm->out,&ch,1);
#if 0	/* Now done in SBBS.DLL/XTRN.CPP */
			if(ch==0xff) { /* escape TELNET IAC */
				RingBufWrite(&vm->out,&ch,1);
				DBTRACE(1,"Escaped IAC in output stream");
			}
#endif
			_clientAX=1; // char was accepted
			break;
        case 0x0C:	// non-destructive read-ahead
			if(!RingBufFull(&vm->in)) {
				_clientAX=0xffff;	// no char available
				break;
			}
			RingBufPeek(&vm->in,&ch,1);
			_clientAH=0;
			_clientAL=ch;
			break;
		case 0x13:	/* write to display */
			dprintf("%c",_clientAL);
			break;
        case 0x18:	/* read bock */
        	rd=_clientCX;
            avail=RingBufFull(&vm->in);
            if(rd>avail)
            	rd=avail;
            if(rd) {
	            buffer = (BYTE*)MAPFLAT(CRS.Client_ES, CWRS.Client_DI);
                rd = RingBufRead(&vm->in, buffer, rd);
            }
            _clientAX = rd;
            break;
        case 0x19:	/* write block */
			wr=_clientCX;
            avail=RingBufFree(&vm->out);
            if(wr>avail)
            	wr=avail;
            if(wr) {
	            buffer = (BYTE*)MAPFLAT(CRS.Client_ES, CWRS.Client_DI);
                wr = RingBufWrite(&vm->out, buffer, wr);
            }
            _clientAX = wr;
            break;
#if 1
        case 0x1B:	// driver info
        {
        	DBTRACE(1,"Int14 driver info");
            struct {
                WORD    info_size;
                BYTE	curr_fossil;
                BYTE	curr_rev;
                DWORD	id_string;
                WORD	inbuf_size;
                WORD	inbuf_free;
                WORD	outbuf_size;
                WORD	outbuf_free;
                BYTE	screen_width;
                BYTE	screen_height;
                BYTE	baud_rate;
            } info={ sizeof(info), 5, 1, 0
            		,RINGBUF_SIZE_IN-1, RingBufFree(&vm->in)
                    ,RINGBUF_SIZE_OUT-1, RingBufFree(&vm->out)
                    ,80,25
                    ,1 // 38400
                    };
//			Map_Lin_To_VM_Addr
			buffer = (BYTE*)MAPFLAT(CRS.Client_ES, CWRS.Client_DI);
            wr=sizeof(info);
            if(wr>_clientCX)
            	wr=_clientCX;
            memcpy(buffer, &info, wr);
        	_clientAX=wr;
            break;
		}
#endif
		default:
			DBTRACEx(0,"!UNHANDLED INTERRUPT 14h function",_clientAH);
			break;
	}
	return(TRUE);	// Tells VMM that interrupt was handled
}
コード例 #6
0
ファイル: syscall.c プロジェクト: sinabeuro/geekos5
/*
 * Destroy a semaphore.
 * Params:
 *   state->ebx - the semaphore id
 *
 * Returns: 0 if successful, error code (< 0) if unsuccessful
 */
static int Sys_DestroySemaphore(struct Interrupt_State* state)
{
	return Destroy_Semaphore(state->ebx);
    TODO("DestroySemaphore system call");
}