Esempio n. 1
0
static THREADFUNCDECL(main_proc_thread_func)
{
	const int sleep_ms = 5;
	const int counts_per_second = 1000 / sleep_ms;
	static int refresh_registration_count = 0;
	static int audio_error_count = 0;
	static int audio_error_state = 0;

	THREADFUNCRET(ret);

	/* Increase Priority */
	iaxci_prioboostbegin();

	while ( !main_proc_thread_flag )
	{
		get_iaxc_lock();

		service_network();

		if ( !test_mode &&
				(!audio_error_state ||
				 audio_error_count++ % counts_per_second == 0) )
		{
			/* There are cases when service audio fails such
			 * as when there is no audio devices present in
			 * the system. In these cases, only call
			 * service_audio() once per second until it
			 * succeeds.
			 */
			if ( (audio_error_state = service_audio()) )
			{
				iaxci_usermsg(IAXC_NOTICE,
						"failed to service audio");

				if ( audio_error_count / counts_per_second == 5 )
					iaxci_usermsg(IAXC_TEXT_TYPE_FATALERROR,
							"cannot open audio device"
							" after several tries");
			}
		}

		// Check registration refresh once a second
		if ( refresh_registration_count++ > counts_per_second )
		{
			iaxc_refresh_registrations();
			refresh_registration_count = 0;
		}

		put_iaxc_lock();

		iaxc_millisleep(sleep_ms);
	}

	/* Decrease priority */
	iaxci_prioboostend();

	main_proc_thread_flag = -1;

	return ret;
}
Esempio n. 2
0
static THREADFUNCDECL(main_proc_thread_func)
{
	static int refresh_registration_count = 0;

	THREADFUNCRET(ret);

	/* Increase Priority */
	iaxci_prioboostbegin();

	while ( !main_proc_thread_flag )
	{
		get_iaxc_lock();

		service_network();
		if ( !test_mode )
			service_audio();

		// Check registration refresh once a second
		if ( refresh_registration_count++ > 1000/LOOP_SLEEP )
		{
			iaxc_refresh_registrations();
			refresh_registration_count = 0;
		}

		put_iaxc_lock();

		iaxc_millisleep(LOOP_SLEEP);
	}

	/* Decrease priority */
	iaxci_prioboostend();

	main_proc_thread_flag = -1;

	return ret;
}