Exemplo n.º 1
0
void
start(void)
{

	sys_priority(PRIORITY);
	sys_share(SHARE);
	sys_yield();

	int i;

	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.
		//*cursorpos++ = PRINTCHAR;
		//call system call instead
		#ifndef __EXERCISE_8__
		sys_print(PRINTCHAR);
		#endif

		#ifdef __EXERCISE_8__
		while(atomic_swap(&spin_lock, 1) != 0){ //run 4ever until locked
			continue;
		}
		*cursorpos++ = PRINTCHAR;
		atomic_swap(&spin_lock, 0); //free
		#endif

		sys_yield();
	}

	// Yield forever.
	while (1)
		//sys_yield();
		sys_exit(0);
}
Exemplo n.º 2
0
void
start(void)
{
	int i;
	sys_share(SHARE);
	sys_priority(PRIORITY);
	#ifdef __EXERCISE_4A__ 
	sys_yield();//for 4a
	#endif
	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.
		//cursorpos++ = PRINTCHAR;
		//atomic_swap(uint32_t *addr, uint32_t val);
		#ifdef __EXERCISE_8__  // exercise 8 sync method
			sys_atomic_print(PRINTCHAR);
		#else // exercise 6 sync method
		while(atomic_swap(&lock,1)!= 0)
		{
			//return 0 means get the lock;
			continue;
		}
		*cursorpos++ = PRINTCHAR;
		atomic_swap(&lock,0);
		#endif
		sys_yield();
		
		//release the lock
	}

	// Yield forever.
	sys_exit(0);
}
Exemplo n.º 3
0
void
start(void)
{
	int i;
	sys_share(SHARE);
	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.
		*cursorpos++ = PRINTCHAR;
		sys_yield();
	}

	// Yield forever.
	sys_exit(0);
}
Exemplo n.º 4
0
void
start(void)
{
	int i;

	sys_priority(MYPRIORITY);
	sys_share(MYSHARE);
	sys_ticket(TICKETS);

	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.
		//*cursorpos++ = PRINTCHAR;
		sys_print(PRINTCHAR);
		sys_yield();
	}

	// Yield forever.
	while (1)
		sys_exit(0); // Exercise 2. Exit so don't yield forever. sys_exit needs an arg (int status)
}
Exemplo n.º 5
0
void
start(void)
{

	// EXERCISE 4A/B code
	sys_priority(PROCESS_PRIORITY);
	sys_share(PROCESS_SHARE);

	// EXERCISE 7 code
	sys_lottery(PROCESS_SHARE);

	// EXERCISE 4A/B code
	sys_yield();

	int i;

	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.

		// EXERCISE 6 and EXERCISE 8
		print_to_screen(&cursorpos, PRINTCHAR);

		/*
		skeleton code that was given
		*cursorpos++ = PRINTCHAR;
		*/

		sys_yield();
	}


	// EXERCISE 2 Code
	// exit process when done
	sys_exit(0);

	// Skeleton code
	// Yield forever.
	while (1)
		sys_yield();
}
Exemplo n.º 6
0
void
start(void)
{
	sys_share(USER_DEFINED_SHARE);
	sys_priority(USER_DEFINED_PRIORITY);
	int i;
	
	for (i = 0; i < RUNCOUNT; i++) {
		// Write characters to the console, yielding after each one.
		if (MECHANISM == 0) 
			*cursorpos++ = PRINTCHAR;
		else if (MECHANISM == 1) {
			uint16_t *curpos = (uint16_t *)fetch_and_add((uint32_t *)&cursorpos,2);
			*curpos = PRINTCHAR;
		} else if (MECHANISM == 2) 
			sys_print(PRINTCHAR);
		sys_yield();
	}

	// Yield forever.
	sys_exit(1);
		
}
Exemplo n.º 7
0
void
start(void)
{
	sys_priority(PRIORITY);
	sys_share(SHARE);

	int i;

	for (i = 0; i < RUNCOUNT; i++) {

		#ifndef __EXERCISE_8__

		// Get lock
		while (atomic_swap(&lock, 1) != 0)
			continue;

		// Print char
		*cursorpos++ = PRINTCHAR;

		// Release lock
		atomic_swap(&lock, 0);

		// Yield after printing
		sys_yield();

		#else

		// Make system call to prin character
		sys_printchar(PRINTCHAR);

		#endif
	}

	// Yield forever.
	while (1)
		sys_exit(0);
}