• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ output_init函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

int main(int argc, char * argv[])
{
	int ret, i;
	pthread_mutexattr_t ma;
	pthread_condattr_t ca;
	
	testdata_t * td;
	testdata_t alternativ;
	
	pid_t child_pr=0, chkpid;
	int status;
	pthread_t child_th;
	
	output_init();

/**********
 * Allocate space for the testdata structure
 */
	/* Cannot mmap a file, we use an alternative method */
	td = &alternativ;
	#if VERBOSE > 0
	output("Testdata allocated in the process memory.\n");
	#endif
	
/**********
 * For each test scenario, initialize the attributes and other variables.
 */
	for ( i=0; i< (sizeof(scenarii) / sizeof(scenarii[0])); i++)
	{
		#if VERBOSE > 1
		output("[parent] Preparing attributes for: %s\n", scenarii[i].descr);
		#endif
		/* set / reset everything */
		ret = pthread_mutexattr_init(&ma);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object");  }
		ret = pthread_condattr_init(&ca);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to initialize the cond attribute object");  }
		
		/* Set the mutex type */
		ret = pthread_mutexattr_settype(&ma, scenarii[i].m_type);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to set mutex type");  }
		#if VERBOSE > 1
		output("[parent] Mutex type : %i\n", scenarii[i].m_type);
		#endif
		
/**********
 * Initialize the testdata_t structure with the previously defined attributes 
 */
		/* Initialize the mutex */
		ret = pthread_mutex_init(&(td->mtx), &ma);
		if (ret != 0)
		{  UNRESOLVED(ret, "[parent] Mutex init failed");  }
		
		/* initialize the condvar */
		ret = pthread_cond_init(&(td->cnd), &ca);
		if (ret != 0)
		{  UNRESOLVED(ret, "[parent] Cond init failed");  }
		
		ret = pthread_mutexattr_gettype(&ma, &(td->type));
		if (ret != 0)
		{  UNRESOLVED(ret, "[parent] Unable to read mutex type attribute");  }
		
		td->ctrl=0;
		td->boolean=0;
		td->status=0;
		
/**********
 * Proceed to the actual testing 
 */
		
		/* Create the child */
		/* We are testing across two threads */
		ret = pthread_create(&child_th, NULL, tf, td);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to create the child thread.");  }
		
		/* Note: in case of an error, the child process will be alive for 10 sec then exit. */
		
		/* Child is now running and will enter the timedwait */
		/* We are waiting for this; and we have to monitor the status value as well. */
		ret = pthread_mutex_lock(&(td->mtx));
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to lock the mutex");  }
		
		while ((td->ctrl == 0) && (td->status == 0))
		{
			ret = pthread_mutex_unlock(&(td->mtx));
			if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to unlock the mutex");  }
			sched_yield();
			ret = pthread_mutex_lock(&(td->mtx));
			if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to lock the mutex");  }
		}
		
		if ((td->ctrl == 2) && (td->status == 0)) /* Spurious wakeups hapenned */
		{
			output("Spurious wake ups have happened. Maybe pthread_cond_wait is broken?\n");
			td->ctrl = 1;
		}
		
		if (td->ctrl == 1)/* The child is inside the cond wait */
		{
			ret = pthread_cond_signal(&(td->cnd));
//.........这里部分代码省略.........
开发者ID:jiezh,项目名称:h5vcc,代码行数:101,代码来源:2-2.c


示例2: main

int main (int argc, char *argv[])
{
	int ret=0;
	pthread_t child;

	output_init();

	scenar_init();

	for (sc=0; sc < NSCENAR; sc++)
	{
		#if VERBOSE > 0
		output("-----\n");
		output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr);
		#endif

		if (scenarii[sc].detached != 0) /* only joinable threads can be detached */
		{
			ret = pthread_attr_setdetachstate(&scenarii[sc].ta, PTHREAD_CREATE_JOINABLE);
			if (ret != 0)  {  UNRESOLVED(ret, "Unable to set detachstate back to joinable");  }
		}

		/* for detached scenarii, we will call pthread_detach from inside the thread.
		   for joinable scenarii, we'll call pthread_detach from this thread. */

		ret = pthread_create(&child, &scenarii[sc].ta, threaded, (scenarii[sc].detached != 0)?&ret:NULL);
		switch (scenarii[sc].result)
		{
			case 0: /* Operation was expected to succeed */
				if (ret != 0)  {  UNRESOLVED(ret, "Failed to create this thread");  }
				break;

			case 1: /* Operation was expected to fail */
				if (ret == 0)  {  UNRESOLVED(-1, "An error was expected but the thread creation succeeded");  }
			#if VERBOSE > 0
				break;

			case 2: /* We did not know the expected result */
			default:
				if (ret == 0)
					{ output("Thread has been created successfully for this scenario\n"); }
				else
					{ output("Thread creation failed with the error: %s\n", strerror(ret)); }
			#endif
		}
		if (ret == 0) /* The new thread is running */
		{
			/* Just wait for the thread to terminate */
			do { ret = sem_wait(&(scenarii[sc].sem)); }
			while ((ret == -1) && (errno == EINTR));
			if (ret == -1)  {  UNRESOLVED(errno, "Failed to post the semaphore");  }

			/* If we must detach from here, we do it now. */
			if (scenarii[sc].detached == 0)
			{
				ret = pthread_detach(child);
				if (ret != 0)  {  UNRESOLVED(ret, "Failed to detach the child thread.");  }
			}

			/* now check that the thread resources are freed. */
			ret = pthread_join(child, NULL);
			if (ret == 0)  {  FAILED("We were able to join a detached thread.");  }

			/* Let the thread an additionnal row to cleanup */
			sched_yield();
		}
	}

	scenar_fini();
	#if VERBOSE > 0
	output("-----\n");
	output("All test data destroyed\n");
	output("Test PASSED\n");
	#endif

	PASSED;
}
开发者ID:barajas,项目名称:Intel-GLTP,代码行数:77,代码来源:1-2.c


示例3: main

/* main function */
int main()
{
	int ret;
	long rts;

	struct sigaction sa;

	/* Initialize output */
	output_init();

	/* Test the RTS extension */
	rts = sysconf(_SC_REALTIME_SIGNALS);

	if (rts < 0L)
	{
		UNTESTED("This test needs the RTS extension");
	}

	/* Set the signal handler */
	sa.sa_flags = SA_SIGINFO;

	sa.sa_sigaction = handler;

	ret = sigemptyset(&sa.sa_mask);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to empty signal set");
	}

	/* Install the signal handler for SIGXCPU */
	ret = sigaction(SIGNAL, &sa, 0);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to set signal handler");
	}

	if (called)
	{
		FAILED("The signal handler has been called when no signal was raised");
	}

	ret = raise(SIGNAL);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to raise SIGXCPU");
	}

	if (!called)
	{
		FAILED("the sa_handler was not called whereas SA_SIGINFO was not set");
	}

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
开发者ID:barajas,项目名称:Intel-GLTP,代码行数:65,代码来源:19-25.c


示例4: main

/********* main ********/
int main(int argc, char *argv[])
{
	int ret, i, j;
	pthread_t th;
	pthread_mutexattr_t ma[4], *pma[5];
	pma[4] = NULL;

	output_init();

	/* Initialize the mutex attributes */
	for (i = 0; i < 4; i++) {
		pma[i] = &ma[i];
		if ((ret = pthread_mutexattr_init(pma[i]))) {
			UNRESOLVED(ret, "pthread_mutexattr_init");
		}
	}
#ifndef WITHOUT_XOPEN
	if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_NORMAL))) {
		UNRESOLVED(ret, "pthread_mutexattr_settype (normal)");
	}
	if ((ret = pthread_mutexattr_settype(pma[1], PTHREAD_MUTEX_ERRORCHECK))) {
		UNRESOLVED(ret, "pthread_mutexattr_settype (errorcheck)");
	}
	if ((ret = pthread_mutexattr_settype(pma[2], PTHREAD_MUTEX_RECURSIVE))) {
		UNRESOLVED(ret, "pthread_mutexattr_settype (recursive)");
	}
	if ((ret = pthread_mutexattr_settype(pma[3], PTHREAD_MUTEX_DEFAULT))) {
		UNRESOLVED(ret, "pthread_mutexattr_settype (default)");
	}
#if VERBOSE >1
	output
	    ("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT initialized\n");
#endif
#else
#if VERBOSE > 0
	output
	    ("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT unavailable\n");
#endif
#endif

	/* Initialize the 5 mutex */
	for (i = 0; i < 5; i++) {
		if ((ret = pthread_mutex_init(&mtx[i], pma[i]))) {
		UNRESOLVED(ret, "pthread_mutex_init failed")}
		if ((ret = pthread_mutex_lock(&mtx[i]))) {
		UNRESOLVED(ret, "Initial pthread_mutex_lock failed")}
	}

#if VERBOSE >1
	output("Mutex objects are initialized\n");
#endif

	/* We don't need the mutex attribute objects anymore */
	for (i = 0; i < 4; i++) {
		if ((ret = pthread_mutexattr_destroy(pma[i]))) {
			UNRESOLVED(ret, "pthread_mutexattr_destroy");
		}
	}

	/* Initialize the semaphores */
	if (sem_init(&semsig, 0, 1)) {
		UNRESOLVED(errno, "Sem init (1) failed");
	}
	if (sem_init(&semstart, 0, 0)) {
		UNRESOLVED(errno, "Sem init (0) failed");
	}
#if VERBOSE >1
	output("Going to create the child thread\n");
#endif
	/* Start the child */
	if ((ret = pthread_create(&th, NULL, threaded, NULL))) {
		UNRESOLVED(ret, "Unable to create the thread");
	}
#if VERBOSE >1
	output("Child created\n");
#endif

	/* Monitor the child */
	for (i = 0; i < 5; i++) {	/* We will do this for the 5 kinds of mutex */
		if (sem_wait(&semstart)) {	/* Wait for the thread to be ready */
			UNRESOLVED(errno, "Unable to wait for the child");
		}
#if VERBOSE >1
		output("Child is ready for iteration %i\n", i + 1);
#endif

		ctrl = 0;	/* init the ctrl var */

		/* Send some signals to the thread */
		for (j = 0; j < 10; j++) {
			if ((ret = sem_wait(&semsig))) {
				UNRESOLVED(errno,
					   "Sem_wait failed from the signal handler");
			}

			sched_yield();	/* Let the child do its stuff - might be a nanosleep here */

			if ((ret = pthread_kill(th, SIGUSR1))) {
				UNRESOLVED(ret, "Pthread_kill failed");
//.........这里部分代码省略.........
开发者ID:Nan619,项目名称:ltp-ddt,代码行数:101,代码来源:5-1.c


示例5: init_machine

static void init_machine(running_machine *machine)
{
	mame_private *mame = machine->mame_data;
	int num;

	/* initialize basic can't-fail systems here */
	cpuintrf_init(machine);
	sndintrf_init(machine);
	fileio_init(machine);
	config_init(machine);
	output_init(machine);
	state_init(machine);
	state_save_allow_registration(TRUE);
	drawgfx_init(machine);
	palette_init(machine);
	render_init(machine);
	ui_init(machine);
	generic_machine_init(machine);
	generic_video_init(machine);
	mame->rand_seed = 0x9d14abd7;

	/* initialize the base time (if not doing record/playback) */
	if (!Machine->record_file && !Machine->playback_file)
		time(&mame->base_time);
	else
		mame->base_time = 0;

	/* init the osd layer */
	if (osd_init(machine) != 0)
		fatalerror("osd_init failed");

	/* initialize the input system */
	/* this must be done before the input ports are initialized */
	if (code_init(machine) != 0)
		fatalerror("code_init failed");

	/* initialize the input ports for the game */
	/* this must be done before memory_init in order to allow specifying */
	/* callbacks based on input port tags */
	if (input_port_init(machine, machine->gamedrv->ipt) != 0)
		fatalerror("input_port_init failed");

	/* load the ROMs if we have some */
	/* this must be done before memory_init in order to allocate memory regions */
	rom_init(machine, machine->gamedrv->rom);

	/* initialize the timers and allocate a soft_reset timer */
	/* this must be done before cpu_init so that CPU's can allocate timers */
	timer_init(machine);
	mame->soft_reset_timer = timer_alloc(soft_reset);

	/* initialize the memory system for this game */
	/* this must be done before cpu_init so that set_context can look up the opcode base */
	if (memory_init(machine) != 0)
		fatalerror("memory_init failed");

	/* now set up all the CPUs */
	if (cpuexec_init(machine) != 0)
		fatalerror("cpuexec_init failed");
	if (cpuint_init(machine) != 0)
		fatalerror("cpuint_init failed");

#ifdef MESS
	/* initialize the devices */
	devices_init(machine);
#endif

	/* start the save/load system */
	saveload_init(machine);

	/* call the game driver's init function */
	/* this is where decryption is done and memory maps are altered */
	/* so this location in the init order is important */
	ui_set_startup_text("Initializing...", TRUE);
	if (machine->gamedrv->driver_init != NULL)
		(*machine->gamedrv->driver_init)(machine);

	/* start the audio system */
	if (sound_init(machine) != 0)
		fatalerror("sound_init failed");

	/* start the video hardware */
	if (video_init(machine) != 0)
		fatalerror("video_init failed");

	/* start the cheat engine */
	if (options.cheat)
		cheat_init(machine);

	/* call the driver's _START callbacks */
	if (machine->drv->machine_start != NULL && (*machine->drv->machine_start)(machine) != 0)
		fatalerror("Unable to start machine emulation");
	if (machine->drv->sound_start != NULL && (*machine->drv->sound_start)(machine) != 0)
		fatalerror("Unable to start sound emulation");
	if (machine->drv->video_start != NULL && (*machine->drv->video_start)(machine) != 0)
		fatalerror("Unable to start video emulation");

	/* free memory regions allocated with REGIONFLAG_DISPOSE (typically gfx roms) */
	for (num = 0; num < MAX_MEMORY_REGIONS; num++)
		if (mame->mem_region[num].flags & ROMREGION_DISPOSE)
//.........这里部分代码省略.........
开发者ID:broftkd,项目名称:mess-cvs,代码行数:101,代码来源:mame.c


示例6: while

	/* We can now free the memory */
	while (ptr_prev != NULL)
	{
		ptr = ptr_prev;
		ptr_prev = *(void **)ptr;
		free(ptr);
	}

	#if VERBOSE > 1
	output("Memory is released\n");
	#endif

	for (i=0; i<4; i++)
		pthread_mutexattr_destroy(pma[i]);

	for (i=0; i<5; i++)
	{
		if (retini[i] != 0 && retini[i] !=ENOMEM)
		{  FAILED("Mutex init returned a wrong error code when no memory was left"); }

		if (retini[i] == 0)
		{
			#if VERBOSE > 0
			output("Mutex initialization for attribute %d succeeds when memory is full\n", i);
			#endif
			if (retdtr[i] != 0)
			{  UNRESOLVED(retdtr[i],  "Mutex destroy failed on mutex inilialized under heavy loaded memory"); }
		}
		#if VERBOSE > 0
		else
		{
			output("Mutex initialization for attribute %d fails with ENOMEM when memory is full\n", i);
		}
		#endif
	}
	PASSED;
}

#else /* WITHOUT_XOPEN */
int main(int argc, char * argv[])
{
	output_init();
	UNTESTED("This test requires XSI features");
}
开发者ID:Mellanox,项目名称:arc_ltp,代码行数:44,代码来源:5-1.c


示例7: main

/* The main test function. */
int main( int argc, char * argv[] )
{
	int ret, i;
	pthread_t ch;

	/* Initialize output */
	output_init();

	ret = pthread_mutex_lock( &mtx );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to lock mutex" );
	}

	ret = pthread_create( &ch, NULL, threaded, NULL );

	if ( ret != 0 )
	{
		UNRESOLVED( ret, "Failed to create a thread" );
	}

	/* Register the handlers */
	for ( i = 0; i < 10000; i++ )
	{
		ret = pthread_atfork( prepare, parent, child );

		if ( ret == ENOMEM )
		{
			output( "ENOMEM returned after %i iterations\n", i );
			break;
		}

		if ( ret != 0 )
		{
			UNRESOLVED( ret, "Failed to register the atfork handlers" );
		}
	}

	if ( ret == 0 )
	{

		/* Let the child go on */
		ret = pthread_mutex_unlock( &mtx );

		if ( ret != 0 )
		{
			UNRESOLVED( ret, "Failed to unlock mutex" );
		}

		ret = pthread_join( ch, NULL );

		if ( ret != 0 )
		{
			UNRESOLVED( ret, "Failed to join the thread" );
		}
	}

	/* Test passed */
#if VERBOSE > 0

	output( "Test passed\n" );

#endif

	PASSED;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:68,代码来源:3-2.c


示例8: main

/* The main test function. */
int main( int argc, char * argv[] )
{
	int ret, status;
	pid_t child, ctl;

	struct itimerval it;

	/* Initialize output */
	output_init();

	/* Create the interval timer */
	it.it_interval.tv_sec = 15;
	it.it_interval.tv_usec = 0;
	it.it_value.tv_sec = 10;
	it.it_value.tv_usec = 0;

	ret = setitimer( ITIMER_REAL, &it, NULL );

	if ( ret != 0 )
	{
		UNRESOLVED( errno, "Failed to set interval timer for ITIMER_REAL" );
	}

	ret = setitimer( ITIMER_VIRTUAL, &it, NULL );

	if ( ret != 0 )
	{
		UNRESOLVED( errno, "Failed to set interval timer for ITIMER_VIRTUAL" );
	}

	ret = setitimer( ITIMER_PROF, &it, NULL );

	if ( ret != 0 )
	{
		UNRESOLVED( errno, "Failed to set interval timer for ITIMER_PROF" );
	}

#if VERBOSE > 0
	output( "All interval timers are set.\n" );

#endif

	/* Create the child */
	child = fork();

	if ( child == ( pid_t ) - 1 )
	{
		UNRESOLVED( errno, "Failed to fork" );
	}

	/* child */
	if ( child == ( pid_t ) 0 )
	{
		/* Check we get the correct information: timer is reset */
		ret = getitimer( ITIMER_REAL, &it );

		if ( ret != 0 )
		{
			UNRESOLVED( errno, "Failed to read ITIMER_REAL in child" );
		}

		if ( it.it_value.tv_sec != 0 )
		{
			FAILED( "Timer ITIMER_REAL was not reset in child" );
		}

		ret = getitimer( ITIMER_VIRTUAL, &it );

		if ( ret != 0 )
		{
			UNRESOLVED( errno, "Failed to read ITIMER_VIRTUAL in child" );
		}

		if ( it.it_value.tv_sec != 0 )
		{
			FAILED( "Timer ITIMER_VIRTUAL was not reset in child" );
		}

		ret = getitimer( ITIMER_PROF, &it );

		if ( ret != 0 )
		{
			UNRESOLVED( errno, "Failed to read ITIMER_PROF in child" );
		}

		if ( it.it_value.tv_sec != 0 )
		{
			FAILED( "Timer ITIMER_PROF was not reset in child" );
		}

		/* We're done */
		exit( PTS_PASS );
	}

	/* Parent joins the child */
	ctl = waitpid( child, &status, 0 );

	if ( ctl != child )
	{
//.........这里部分代码省略.........
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:101,代码来源:13-1.c


示例9: main

/* Main function */
int main (int argc, char * argv[])
{
	int ret;
	pthread_t th_work, th_sig1, th_sig2;
	thestruct arg1, arg2;
	
	output_init();

	#ifdef WITH_SYNCHRO
	if (sem_init(&semsig1, 0, 1))
	{ UNRESOLVED(errno, "Semsig1  init"); }
	if (sem_init(&semsig2, 0, 1))
	{ UNRESOLVED(errno, "Semsig2  init"); }
	#endif
	
	if (sem_init(&semsync, 0, 0))
	{ UNRESOLVED(errno, "semsync init"); }
	
	if ((ret = pthread_create(&th_work, NULL, threaded, NULL)))
	{ UNRESOLVED(ret, "Worker thread creation failed"); }
	
	arg1.thr = &th_work;
	arg2.thr = &th_work;
	arg1.sig = SIGUSR1;
	arg2.sig = SIGUSR2;
#ifdef WITH_SYNCHRO
	arg1.sem = &semsig1;
	arg2.sem = &semsig2;
#endif
	
	if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1)))
	{ UNRESOLVED(ret, "Signal 1 sender thread creation failed"); }
	if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2)))
	{ UNRESOLVED(ret, "Signal 2 sender thread creation failed"); }
	
	/* Let's wait for a while now */
	sleep(1);
	
	/* Now stop the threads and join them */
	do { do_it=0; }
	while (do_it);
	
	if ((ret = pthread_join(th_sig1, NULL)))
	{ UNRESOLVED(ret, "Signal 1 sender thread join failed"); }
	if ((ret = pthread_join(th_sig2, NULL)))
	{ UNRESOLVED(ret, "Signal 2 sender thread join failed"); }
	
	if (sem_post(&semsync))
	{ UNRESOLVED(errno, "could not post semsync"); }
	
	if ((ret = pthread_join(th_work, NULL)))
	{ UNRESOLVED(ret, "Worker thread join failed"); }

	#if VERBOSE > 0
	output("Test executed successfully.\n");
	output("  %d condvars initialization and destruction were done.\n", count_ope);
	#ifdef WITH_SYNCHRO
	output("  %d signals were sent meanwhile.\n", count_sig);
	#endif 
	#endif	
	PASSED;
}
开发者ID:SummerSnail2014,项目名称:haiku,代码行数:63,代码来源:4-2.c


示例10: main

/* The main test function. */
int main(void)
{
	int ret, value;

	sem_t *sem;

	/* Initialize output */
	output_init();

	/* Create the semaphore */
	sem = sem_open(SEM_NAME, O_CREAT | O_EXCL, 0777, 2);

	if (sem == SEM_FAILED && errno == EEXIST) {
		sem_unlink(SEM_NAME);
		sem = sem_open(SEM_NAME, O_CREAT | O_EXCL, 0777, 2);
	}

	if (sem == SEM_FAILED) {
		UNRESOLVED(errno, "Failed to create the semaphore");
	}

	/* Use the semaphore to change its value. */
	do {
		ret = sem_wait(sem);
	} while (ret != 0 && errno == EINTR);

	if (ret != 0) {
		UNRESOLVED(errno, "Failed to wait for the semaphore");
	}

	/* Here, count is 1. Now, close the semaphore */
	ret = sem_close(sem);

	if (ret != 0) {
		UNRESOLVED(errno, "Failed to close the semaphore");
	}

	/* Open the semaphore again */
	sem = sem_open(SEM_NAME, O_CREAT, 0777, 3);

	if (sem == SEM_FAILED) {
		UNRESOLVED(errno, "Failed to re-open the semaphore");
	}

	/* Check current semaphore count */
	ret = sem_getvalue(sem, &value);

	if (ret != 0) {
		UNRESOLVED(errno, "Failed to get semaphore value");
	}

	if (value != 1) {
		output("Got value: %d\n", value);
		FAILED("The semaphore count has changed after sem_close");
	}

	/* Now, we can destroy all */
	ret = sem_close(sem);

	if (ret != 0) {
		UNRESOLVED(errno, "Failed to close the semaphore");
	}

	ret = sem_unlink(SEM_NAME);

	if (ret != 0) {
		UNRESOLVED(errno, "Failed to unlink the semaphore");
	}

	/* Test passed */
#if VERBOSE > 0
	output("Test passed\n");

#endif
	PASSED;
}
开发者ID:kraj,项目名称:ltp,代码行数:77,代码来源:3-2.c


示例11: main

/** The main entry point of GridLAB-D
    @returns Exit codes XC_SUCCESS, etc. (see gridlabd.h)
 **/
int main(int argc, /**< the number entries on command-line argument list \p argv */
		 char *argv[]) /**< a list of pointers to the command-line arguments */
{
	char *pd1, *pd2;
	int i, pos=0;
	
	char *browser = getenv("GLBROWSER");

	/* set the default timezone */
	timestamp_set_tz(NULL);

	exec_clock(); /* initialize the wall clock */
	realtime_starttime(); /* mark start */
	
	/* set the process info */
	global_process_id = getpid();

	/* specify the default browser */
	if ( browser!= NULL )
		strncpy(global_browser,browser,sizeof(global_browser)-1);

#if defined WIN32 && _DEBUG 
	atexit(pause_at_exit);
#endif

#ifdef WIN32
	kill_starthandler();
	atexit(kill_stophandler);
#endif

	/* capture the execdir */
	strcpy(global_execname,argv[0]);
	strcpy(global_execdir,argv[0]);
	pd1 = strrchr(global_execdir,'/');
	pd2 = strrchr(global_execdir,'\\');
	if (pd1>pd2) *pd1='\0';
	else if (pd2>pd1) *pd2='\0';

	/* determine current working directory */
	getcwd(global_workdir,1024);

	/* capture the command line */
	for (i=0; i<argc; i++)
	{
		if (pos < (int)(sizeof(global_command_line)-strlen(argv[i])))
			pos += sprintf(global_command_line+pos,"%s%s",pos>0?" ":"",argv[i]);
	}

	/* main initialization */
	if (!output_init(argc,argv) || !exec_init())
		exit(XC_INIERR);

	/* set thread count equal to processor count if not passed on command-line */
	if (global_threadcount == 0)
		global_threadcount = processor_count();
	output_verbose("detected %d processor(s)", processor_count());
	output_verbose("using %d helper thread(s)", global_threadcount);

	/* process command line arguments */
	if (cmdarg_load(argc,argv)==FAILED)
	{
		output_fatal("shutdown after command line rejected");
		/*	TROUBLESHOOT
			The command line is not valid and the system did not
			complete its startup procedure.  Correct the problem
			with the command line and try again.
		 */
		exit(XC_ARGERR);
	}

	/* stitch clock */
	global_clock = global_starttime;

	/* initialize scheduler */
	sched_init(0);

	/* recheck threadcount in case user set it 0 */
	if (global_threadcount == 0)
	{
		global_threadcount = processor_count();
		output_verbose("using %d helper thread(s)", global_threadcount);
	}

	/* see if newer version is available */
	if ( global_check_version )
		check_version(1);

	/* setup the random number generator */
	random_init();

	/* pidfile */
	if (strcmp(global_pidfile,"")!=0)
	{
		FILE *fp = fopen(global_pidfile,"w");
		if (fp==NULL)
		{
			output_fatal("unable to create pidfile '%s'", global_pidfile);
//.........这里部分代码省略.........
开发者ID:AMFIRNAS,项目名称:wso2-gridlabd,代码行数:101,代码来源:main.c


示例12: main

/* Main entry point. */
int main(int argc, char * argv[])
{
	int ret;
	int sc;
	pthread_mutexattr_t ma;
	
	testdata_t * td;
	testdata_t alternativ;
	
	pid_t child_pr=0, chkpid;
	int status;
	pthread_t child_th;
	
	/* Initialize output */
	output_init();
	
/**********
 * Allocate space for the testdata structure
 */
	/* Cannot mmap a file (or not interested in this), we use an alternative method */
	td = &alternativ;
	#if VERBOSE > 0
	output("Testdata allocated in the process memory.\n");
	#endif
	
/**********
 * For each test scenario, initialize the attributes and other variables.
 * Do the whole thing for each time to test.
 */
	for ( sc=0; sc < NSCENAR ; sc++)
	{
		#if VERBOSE > 1
		output("[parent] Preparing attributes for: %s\n", scenarii[sc].descr);
		#endif
		/* set / reset everything */
		ret = pthread_mutexattr_init(&ma);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object");  }
		
		#ifndef WITHOUT_XOPEN
		/* Set the mutex type */
		ret = pthread_mutexattr_settype(&ma, scenarii[sc].m_type);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to set mutex type");  }
		#if VERBOSE > 1
		output("[parent] Mutex type : %i\n", scenarii[sc].m_type);
		#endif
		#endif
			
/**********
 * Initialize the testdata_t structure with the previously defined attributes 
 */
		/* Initialize the mutex */
		ret = pthread_mutex_init(&(td->mtx), &ma);
		if (ret != 0)
		{  UNRESOLVED(ret, "[parent] Mutex init failed");  }
		
		/* Initialize the other datas from the test structure */
		td->status=0;
		
/**********
 * Proceed to the actual testing 
 */
		/* Trylock the mutex twice before creating children */
		ret = pthread_mutex_trylock(&(td->mtx));
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to trylock the mutex");  }
		ret = pthread_mutex_trylock(&(td->mtx));
		#ifndef WITHOUT_XOPEN
		if (scenarii[sc].m_type == PTHREAD_MUTEX_RECURSIVE)
		{
			if (ret != 0)  {  UNRESOLVED(ret, "Failed to pthread_mutex_trylock() twice a recursive mutex");  }
			
			/* Unlock once so the count is "1" */
			ret = pthread_mutex_unlock(&(td->mtx));
			if (ret != 0)  {  UNRESOLVED(ret, "Failed to unlock the mutex");  }
		}
		else
		#endif
			if (ret == 0)  {  FAILED("Main was able to pthread_mutex_trylock() twice without error");  }
			
		/* Create the children */
		/* We are testing across two threads */
		ret = pthread_create(&child_th, NULL, tf, td);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to create the child thread.");  }
			
		/* Wait for the child to terminate */
		ret = pthread_join(child_th, NULL);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to join the thread");  }
		
		/* Check the child status */
		if (td->status != EBUSY)  
		{
			output("Unexpected return value: %d (%s)\n", td->status, strerror(td->status));
			FAILED("pthread_mutex_trylock() did not return EBUSY in the child");
		}
		
		/* Unlock the mutex */
		ret= pthread_mutex_unlock(&(td->mtx));
		if (ret != 0)  {  UNRESOLVED(ret, "Failed to unlock the mutex");  }
		
/**********
//.........这里部分代码省略.........
开发者ID:jiezh,项目名称:h5vcc,代码行数:101,代码来源:1-2.c


示例13: main

/* The main test function. */
int main(void)
{
	int ret, i;
	sem_t *sems;
	sem_t sem_last;

	long max;

	/* Initialize output */
	output_init();

	max = sysconf(_SC_SEM_NSEMS_MAX);

	if (max <= 0) {
		output("sysconf(_SC_SEM_NSEMS_MAX) = %ld\n", max);
		UNTESTED("There is no constraint on SEM_NSEMS_MAX");
	}

	sems = (sem_t *) calloc(max, sizeof(sem_t));

	if (sems == NULL) {
		UNRESOLVED(errno, "Failed to alloc space");
	}

	for (i = 0; i < max; i++) {
		ret = sem_init(&sems[i], 0, 0);

		if (ret != 0) {
			output
			    ("sem_init failed to initialize the %d nth semaphore.\n",
			     i);
			output("Tryed to initialize %ld.\n", max);
			output("Error is %d: %s\n", errno, strerror(errno));

			for (; i > 0; i--)
				sem_destroy(&sems[i - 1]);

			free(sems);

			PASSED;
		}
	}

	ret = sem_init(&sem_last, 0, 1);

	if (ret == 0) {
		FAILED
		    ("We were able to sem_init more than SEM_NSEMS_MAX semaphores");
	}

	if (errno != ENOSPC) {
		output("Error is %d: %s\n", errno, strerror(errno));
	}

	for (i = 0; i < max; i++)
		sem_destroy(&sems[i]);

	free(sems);

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
开发者ID:1587,项目名称:ltp,代码行数:69,代码来源:7-1.c


示例14: main

int main (int argc, char * argv[])
{
	int ret;
	
	pthread_mutexattr_t ma;
	pthread_condattr_t ca;
	
	int scenar;
	
	int child_count;
	
	pid_t pid;
	int status;
	
	pthread_attr_t ta;
	
	testdata_t alternativ;
	
	output_init();
	
/**********
 * Allocate space for the testdata structure
 */
	/* Cannot mmap a file, we use an alternative method */
	td = &alternativ;
	#if VERBOSE > 0
	output("Testdata allocated in the process memory.\n");
	#endif
	
	/* Initialize the thread attribute object */
	ret = pthread_attr_init(&ta);
	if (ret != 0)  {  UNRESOLVED(ret, "[parent] Failed to initialize a thread attribute object");  }
	ret = pthread_attr_setstacksize(&ta, PTHREAD_STACK_MIN);
	if (ret != 0)  {  UNRESOLVED(ret, "[parent] Failed to set thread stack size");  }
	
	/* Do the test for each test scenario */
	for (scenar=0; scenar < NSCENAR; scenar++)
	{
		/* set / reset everything */
		ret = pthread_mutexattr_init(&ma);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object");  }
		ret = pthread_condattr_init(&ca);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to initialize the cond attribute object");  }
		
		#ifndef WITHOUT_XOPEN
		/* Set the mutex type */
		ret = pthread_mutexattr_settype(&ma, scenarii[scenar].m_type);
		if (ret != 0)  {  UNRESOLVED(ret, "[parent] Unable to set mutex type");  }
		#endif
		
		td->mtype=scenarii[scenar].m_type;
		
		/* initialize the condvar */
		ret = pthread_cond_init(&td->cnd, &ca);
		if (ret != 0)  {  UNRESOLVED(ret, "Cond init failed");  }
		
		/* initialize the mutex */
		ret = pthread_mutex_init(&td->mtx, &ma);
		if (ret != 0)  {  UNRESOLVED(ret, "Mutex init failed");  }
		
		/* Destroy the attributes */
		ret = pthread_condattr_destroy(&ca);
		if (ret != 0)  {  UNRESOLVED(ret, "Failed to destroy the cond var attribute object");  }
		
		ret = pthread_mutexattr_destroy(&ma);
		if (ret != 0)  {  UNRESOLVED(ret, "Failed to destroy the mutex attribute object");  }
		
		#if VERBOSE > 2
		output("[parent] Starting test %s\n", scenarii[scenar].descr);
		#endif
		
		td->count=0;
		
		/* Create all the children */
		for (children.nb=0; children.nb<NCHILDREN; children.nb++)
		{
			ret = pthread_create(&(children.ch[children.nb].t), &ta, child, NULL);
			if (ret != 0)  {  UNRESOLVED(ret, "Failed to create enough threads");  }
		}
		#if VERBOSE > 4
		output("[parent] Created %i children\n", NCHILDREN);
		#endif
		
		/* Make sure all children are waiting */
		ret = pthread_mutex_lock(&td->mtx);
		if (ret != 0) {  UNRESOLVED_KILLALL(ret, "Failed to lock mutex");  }
		child_count = td->count;
		while (child_count < NCHILDREN)
		{
			ret = pthread_mutex_unlock(&td->mtx);
			if (ret != 0)  {  UNRESOLVED_KILLALL(ret, "Failed to unlock mutex");  }
			sched_yield();
			ret = pthread_mutex_lock(&td->mtx);
			if (ret != 0) {  UNRESOLVED_KILLALL(ret, "Failed to lock mutex");  }
			child_count = td->count;
		}
		
		#if VERBOSE > 4
		output("[parent] All children are waiting\n");
		#endif
//.........这里部分代码省略.........
开发者ID:jiezh,项目名称:h5vcc,代码行数:101,代码来源:2-3.c


示例15: main

/* main routine */
int main(int argc, char * argv[])
{
	int ret, i;
	void * rval;
	struct sigaction sa;

	pthread_t threads[NSCENAR * SCALABILITY_FACTOR * FACTOR];
	int rets[NSCENAR * SCALABILITY_FACTOR * FACTOR];

 	/* Initialize output */
	output_init();

	/* Initialize scenarii table */
	scenar_init();

	/* Register the signal handler for SIGUSR1 */
	sigemptyset (&sa.sa_mask);
	sa.sa_flags = 0;
	sa.sa_handler = sighdl;
	if ((ret = sigaction (SIGUSR1, &sa, NULL)))
	{ UNRESOLVED(ret, "Unable to register signal handler"); }
	if ((ret = sigaction (SIGALRM, &sa, NULL)))
	{ UNRESOLVED(ret, "Unable to register signal handler"); }
	#if VERBOSE > 1
	output("[parent] Signal handler registered\n");
	#endif

	while (do_it)
	{
		/* Create all the threads */
		for (i=0; i<SCALABILITY_FACTOR * FACTOR; i++)
		{
			for (sc=0; sc<NSCENAR; sc++)
			{
				/* Skip the alternative stack threads */
				if (scenarii[sc].altstack != 0)
					continue;

				rets[i*NSCENAR + sc] = pthread_create(&threads[i*NSCENAR + sc], &scenarii[sc].ta, threaded, &threads[i*NSCENAR + sc]);
				switch (scenarii[sc].result)
				{
					case 0: /* Operation was expected to succeed */
						if (rets[i*NSCENAR + sc] != 0)  {  UNRESOLVED(rets[i*NSCENAR + sc], "Failed to create this thread");  }
						break;

					case 1: /* Operation was expected to fail */
						if (rets[i*NSCENAR + sc] == 0)  {  UNRESOLVED(-1, "An error was expected but the thread creation succeeded");  }
						break;

					case 2: /* We did not know the expected result */
					default:
						#if VERBOSE > 5
						if (rets[i*NSCENAR + sc] == 0)
							{ output("Thread has been created successfully for this scenario\n"); }
						else
							{ output("Thread creation failed with the error: %s\n", strerror(rets[i*NSCENAR + sc])); }
						#endif
						;
				}
				if (rets[i*NSCENAR + sc] == 0)
				{
					/* Just wait for the thread to terminate */
					do { ret = sem_wait(&scenarii[sc].sem); }
					while ((ret == -1) && (errno == EINTR));
					if (ret == -1)  {  UNRESOLVED(errno, "Failed to wait for the semaphore");  }
				}
			}
		}

		/* Join all the joinable threads and check the value */
		for (i=0; i<SCALABILITY_FACTOR * FACTOR; i++)
		{
			for (sc=0; sc<NSCENAR; sc++)
			{
				if ((scenarii[sc].altstack == 0) && (scenarii[sc].detached == 0) && (rets[i*NSCENAR + sc] == 0))
				{
					ret = pthread_join(threads[i*NSCENAR + sc], &rval);
					if (ret != 0)  {  UNRESOLVED(ret, "Unable to join a thread");  }

					if (rval !=  (void *)&threads[i*NSCENAR + sc])
					{
						output("arg: %p -- got %p -- NULL=%p\n", &threads[i*NSCENAR + sc], rval, NULL);
						FAILED("The retrieved error value is corrupted");
					}
				}
			}
		}

		iterations++;
	}

	/* Destroy scenarii attributes */
	scenar_fini();

	/* Test passed */
	output("pthread_exit stress test PASSED -- %llu iterations\n",iterations);
	PASSED;
}
开发者ID:andreimironenko,项目名称:ltp-full,代码行数:99,代码来源:stress.c


示例16: main

/* The main test function. */
int main(int argc, char * argv[])
{
	int ret, param, status;
	pid_t child, ctl;

	struct sched_param sp;

	/* Initialize output */
	output_init();

	/* Change process policy and parameters */
	sp.sched_priority = param = sched_get_priority_max(POLICY);

	if (sp.sched_priority == -1)
	{
		UNRESOLVED(errno, "Failed to get max priority value");
	}

	ret = sched_setscheduler(0, POLICY, &sp);

	if (ret == -1)
	{
		UNRESOLVED(errno, "Failed to change process scheduling policy");
	}

	/* Create the child */
	child = fork();

	if (child == -1)
	{
		UNRESOLVED(errno, "Failed to fork");
	}

	/* child */
	if (child == 0)
	{

		/* Check the scheduling policy */
		ret = sched_getscheduler(0);

		if (ret == -1)
		{
			UNRESOLVED(errno, "Failed to read scheduling policy in child");
		}

		if (ret != POLICY)
		{
			FAILED("The scheduling policy was not inherited");
		}

		ret = sched_getparam(0, &sp);

		if (ret != 0)
		{
			UNRESOLVED(errno, "Failed to read scheduling parameter in child");
		}

		if (sp.sched_priority != param)
		{
			FAILED("The scheduling parameter was not inherited");
		}

		/* We're done */
		exit(PTS_PASS);
	}

	/* Parent joins the child */
	ctl = waitpid(child, &status, 0);

	if (ctl != child)
	{
		UNRESOLVED(errno, "Waitpid returned the wrong PID");
	}

	if (!WIFEXITED(status) || (WEXITSTATUS(status) != PTS_PASS))
	{
		FAILED("Child exited abnormally");
	}

	/* Test passed */
#if VERBOSE > 0
	output("Test passed\n");

#endif
	PASSED;
}
开发者ID:barajas,项目名称:Intel-GLTP,代码行数:87,代码来源:17-1.c


示例17: main

/* main function */
int main()
{
	int ret;

	struct sigaction sa, save;

	/* Initialize output */
	output_init();

	/* Register the signal handler with signal */

	if (SIG_ERR == signal(SIGNAL, handler_1))
	{
		UNRESOLVED(errno, "Failed to register signal handler with signal()");
	}

	/* As whether signal handler is restored to default when executed
	is implementation defined, we cannot check it was registered here. */

	/* Set the new signal handler with sigaction*/
	sa.sa_flags = 0;

	sa.sa_handler = handler_2;

	ret = sigemptyset(&sa.sa_mask);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to empty signal set");
	}

	/* Install the signal handler for SIGXFSZ */
	ret = sigaction(SIGNAL, &sa, &save);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to set signal handler");
	}

	/* Check the signal handler has been set up */
	ret = raise(SIGNAL);

	if (ret != 0)
	{
		UNRESOLVED(ret , "Failed to raise the signal");
	}

	if (called != 0)
	{
		FAILED("handler not executed");
	}

	/* Restore the first signal handler */
	ret = sigaction(SIGNAL, &save, 0);

	if (ret != 0)
	{
		UNRESOLVED(ret, "Failed to set signal handler");
	}

	/* Check the signal handler has been set up */
	ret = raise(SIGNAL);

	if (ret != 0)
	{
		UNRESOLVED(ret , "Failed to raise the signal");
	}

	if (called != 1)
	{
		FAILED("handler not executed");
	}

	/* Test passed */
#if VERBOSE > 0

	output("Test passed\n");

#endif

	PASSED;
}
开发者ID:shubmit,项目名称:shub-ltp,代码行数:83,代码来源:28-26.c


示例18: main

/* The main test function. */
int main( int argc, char * argv[] )
{
	int ret, error;
	sem_t * sem;
#undef PATH_MAX
#undef NAME_MAX
	long PATH_MAX, NAME_MAX;
	char * sem_name;

	/* Initialize output */
	output_init();

	/* Get PATH_MAX value */
	PATH_MAX = pathconf( "/", _PC_PATH_MAX );

#if VERBOSE > 0
	output( "PATH_MAX: %ld\n", PATH_MAX );
#endif

	if ( PATH_MAX > 0 )
	{
		/* create a semaphore with a name longer than PATH_MAX */
		sem_name = calloc( PATH_MAX + 1, sizeof( char ) );

		if ( sem_name == NULL )
		{
			UNRESOLVED( errno, "Failed to allocate space for the semaphore name" );
		}

		/* the space was allocated */
		sem_name[ 0 ] = '/';

		sem_name[ PATH_MAX ] = '\0';

		memset( sem_name + 1, 'P', PATH_MAX - 1 );

		/* Create the semaphore */
		sem = sem_open( sem_name, O_CREAT, 0777, 1 );

		if ( sem != SEM_FAILED )
		{
			ret = sem_unlink( sem_name );
			error = errno;
			free( sem_name );

			if ( ret == 0 )
			{
				FAILED( "The function did not return ENAMETOOLONG as expected" );
			}
			else
			{
				output( "Error was %d: %s\n", error, strerror( error ) );
				FAILED( "Unable to unlink a semaphore which we just created" );
			}
		}

#if VERBOSE > 0
		else
		{
			output( "Creation of the semaphore failed with error %d: %s\n", errno, strerror( errno ) );
		}

#endif

	}

	/* Get NAME_MAX value */
	NAME_MAX = pathconf( "/", _PC_NAME_MAX );

#if VERBOSE > 0
	output( "NAME_MAX: %ld\n", NAME_MAX );

#endif

	if ( NAME_MAX > 0 )
	{
		/* create a semaphore with a name longer than 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ output_line函数代码示例发布时间:2022-05-30
下一篇:
C++ output_high函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap