Ejemplo n.º 1
0
int
main(int argc, char *argv[])
{
   int qid;
   msg m;

   qid = mg_open( "/tmp/pb_msgqueue" );

   printf( "Opened qid %d\n", qid );

   // Draining queued data
   printf( "Draining pending data\n" );
   mg_drain( qid, MG_TYPE );
   printf( "   done\n" );

	signal( SIGINT, sigint_handler );

   while ( !hit_sigint && (mg_recv( qid, MG_TYPE, &m ) > 0) ) {
      do_magic( &m );
   }

   mg_release( qid );

   return 0;
}
Ejemplo n.º 2
0
int main(int argc, char** argv)
{
	char input[128];
	int boxes;
	int dimensions;
	int dimension[10];
	box_t box[30];
	int i, j;
	int result[30];
	int result_length;

	while (fgets(input, 128, stdin)) {
		sscanf(input, "%d %d", &boxes, &dimensions);

		result_length = 0;
		for (i = 0; i < 30; i++) {
			result[i] = 0;
		}

		for (i = 0; i < boxes; i++) {
			fgets(input, 128, stdin);
			sscanf(input, "%d %d %d %d %d %d %d %d %d %d", dimension+0, dimension+1, dimension+2, dimension+3, dimension+4, dimension+5, dimension+6, dimension+7, dimension+8, dimension+9);

			qsort(dimension, dimensions, sizeof(int), intcmp);

			box_init(&box[i], i + 1, dimension, dimensions);
		}

		for (i = 0; i < boxes; i++) {
			for (j = i + 1; j < boxes; j++) {
				if (boxcmp(&box[i], &box[j]) < 0) {
					box_append_fits_in(&box[i], &box[j]);
					box_append_fits_out(&box[j], &box[i]);
				}
				else if (boxcmp(&box[i], &box[j]) > 0) {
					box_append_fits_in(&box[j], &box[i]);
					box_append_fits_out(&box[i], &box[j]);
				}
			}
		}

		for (i = 0; i < boxes; i++) {
			do_magic(&box[i], result, &result_length, 1);
		}

		print_result(result, result_length);
	}

	return EXIT_SUCCESS;
}
Ejemplo n.º 3
0
static void do_software_suspend(void)
{
	if (arch_prepare_suspend()) {
		printk("%sArchitecture failed to prepare\n", name_suspend);
		return;
	}		
	if (pm_prepare_console())
		printk( "%sCan't allocate a console... proceeding\n", name_suspend);
	if (!prepare_suspend_processes()) {

		/* At this point, all user processes and "dangerous"
                   kernel threads are stopped. Free some memory, as we
                   need half of memory free. */

		free_some_memory();
		
		/* No need to invalidate any vfsmnt list -- 
		 * they will be valid after resume, anyway.
		 */
		blk_run_queues();

		/* Save state of all device drivers, and stop them. */		   
		if(drivers_suspend()==0)
			/* If stopping device drivers worked, we proceed basically into
			 * suspend_save_image.
			 *
			 * do_magic(0) returns after system is resumed.
			 *
			 * do_magic() copies all "used" memory to "free" memory, then
			 * unsuspends all device drivers, and writes memory to disk
			 * using normal kernel mechanism.
			 */
			do_magic(0);
		thaw_processes();
	}
	software_suspend_enabled = 1;
	MDELAY(1000);
	pm_restore_console();
}
Ejemplo n.º 4
0
/**
 *	software_resume - Resume from a saved image.
 *
 *	Called as a late_initcall (so all devices are discovered and 
 *	initialized), we call swsusp to see if we have a saved image or not.
 *	If so, we quiesce devices, then restore the saved image. We will 
 *	return above (in pm_suspend_disk() ) if everything goes well. 
 *	Otherwise, we fail gracefully and return to the normally 
 *	scheduled program.
 *
 */
static int __init software_resume(void)
{
	if (num_online_cpus() > 1) {
		printk(KERN_WARNING "Software Suspend has malfunctioning SMP support. Disabled :(\n");	
		return -EINVAL;
	}
	/* We enable the possibility of machine suspend */
	software_suspend_enabled = 1;
	if (!resume_status)
		return 0;

	printk( "%s", name_resume );
	if (resume_status == NORESUME) {
		if(resume_file[0])
			read_suspend_image(resume_file, 1);
		printk( "disabled\n" );
		return 0;
	}
	MDELAY(1000);

	if (pm_prepare_console())
		printk("swsusp: Can't allocate a console... proceeding\n");

	if (!resume_file[0] && resume_status == RESUME_SPECIFIED) {
		printk( "suspension device unspecified\n" );
		return -EINVAL;
	}

	printk( "resuming from %s\n", resume_file);
	if (read_suspend_image(resume_file, 0))
		goto read_failure;
	do_magic(1);
	panic("This never returns");

read_failure:
	pm_restore_console();
	return 0;
}
Ejemplo n.º 5
0
int do_magic(box_t* curr_box, int* result, int* result_length, int depth)
{
	int i;
	int write;

	if ((curr_box->fits_in_length == 0) && (depth > *result_length)) {
		*result_length = depth;
		write = 1;
	}
	else {
		write = 0;
	}

	for (i = 0; i < curr_box->fits_in_length; i++) {
		write |= do_magic(curr_box->fits_in[i], result, result_length, depth + 1);
	}

	if (write) {
		result[depth-1] = curr_box->id;
	}

	return write;
}
Ejemplo n.º 6
0
int main()
{
  std::cout << do_magic(2) << '\n';
  //Forgot to test do_magic(42)
}