Ejemplo n.º 1
0
DECLARE_TEST(mutex, sync) {
	mutex_t* mutex;
	thread_t thread[32];
	size_t ith;

	mutex = mutex_allocate(STRING_CONST("test"));
	mutex_lock(mutex);

	for (ith = 0; ith < 32; ++ith)
		thread_initialize(&thread[ith], mutex_thread, mutex, STRING_CONST("mutex_thread"),
		                  THREAD_PRIORITY_NORMAL, 0);
	for (ith = 0; ith < 32; ++ith)
		thread_start(&thread[ith]);

	test_wait_for_threads_startup(thread, 32);

	mutex_unlock(mutex);

	test_wait_for_threads_finish(thread, 32);

	for (ith = 0; ith < 32; ++ith)
		thread_finalize(&thread[ith]);

	mutex_deallocate(mutex);

	EXPECT_EQ(thread_counter, 32 * 128);

	return 0;
}
Ejemplo n.º 2
0
DECLARE_TEST( mutex, sync )
{
	mutex_t* mutex;
	object_t thread[32];
	int ith;

	mutex = mutex_allocate( "test" );
	mutex_lock( mutex );

	for( ith = 0; ith < 32; ++ith )
	{
		thread[ith] = thread_create( mutex_thread, "mutex_thread", THREAD_PRIORITY_NORMAL, 0 );
		thread_start( thread[ith], mutex );
	}

	test_wait_for_threads_startup( thread, 32 );

	for( ith = 0; ith < 32; ++ith )
	{
		thread_terminate( thread[ith] );
		thread_destroy( thread[ith] );
	}

	mutex_unlock( mutex );

	test_wait_for_threads_exit( thread, 32 );

	mutex_deallocate( mutex );

	EXPECT_EQ( thread_counter, 32 * 128 );

	return 0;
}
Ejemplo n.º 3
0
void creole_connect (void *appdata)
{
  creole_WIKIVERSION = box_dv_short_string (creole_VERSION);
  creole_lexer_mutex = mutex_allocate ();
  bif_define ("WikiV macroexpander 2", bif_creole_macroexpander);
  bif_define ("WikiV lexer 2", bif_creole_lexer);
  bif_define ("WikiV name 2", bif_creole_name);
}
Ejemplo n.º 4
0
void wikiv_connect (void *appdata)
{
  wikiv_WIKIVERSION = box_dv_short_string (WIKIV_VERSION);
  wikiv_lexer_mutex = mutex_allocate ();
  bif_define ("WikiV macroexpander", bif_wikiv_macroexpander);
  bif_define ("WikiV lexer", bif_wikiv_lexer);
  bif_define ("WikiV name", bif_wikiv_name);
}
Ejemplo n.º 5
0
void mediawiki_connect (void *appdata)
{
  mediawiki_WIKIVERSION = box_dv_short_string (MEDIAWIKI_VERSION);
  mediawiki_lexer_mutex = mutex_allocate ();
  bif_define ("WikiV macroexpander 1", bif_mediawiki_macroexpander);
  bif_define ("WikiV lexer 1", bif_mediawiki_lexer);
  bif_define ("WikiV name 1", bif_mediawiki_name);
}
Ejemplo n.º 6
0
int
mts_init ()
{
  if (!local_rm_mutex)
    local_rm_mutex = mutex_allocate ();
  if (vd_use_mts)
    local_rm = init_RM ();
  else
    local_rm = 0;
  return local_rm != NULL;
}
Ejemplo n.º 7
0
static void
_sched_init (void)
{
  _q_lock = mutex_allocate ();

  thread_queue_init (&_deadq);
  thread_queue_init (&_waitq);

  _thread_num_wait = 0;
  _thread_num_dead = 0;
  _thread_num_runnable = -1;	/* not counted */
  _thread_num_total = 1;

#ifdef EXPIRIMENTAL
  io_init ();

  pipe (_ev_pipes);
  thread_nb_fd (_ev_pipes[0]);
  thread_nb_fd (_ev_pipes[1]);
#endif
#ifdef MTX_METER
  all_mtxs_mtx = mutex_allocate ();
#endif
}
Ejemplo n.º 8
0
DECLARE_TEST(mutex, basic) {
	mutex_t* mutex;

	mutex = mutex_allocate(STRING_CONST("test"));

	EXPECT_CONSTSTRINGEQ(mutex_name(mutex), string_const(STRING_CONST("test")));
	EXPECT_TRUE(mutex_try_lock(mutex));
	EXPECT_TRUE(mutex_lock(mutex));
	EXPECT_TRUE(mutex_try_lock(mutex));
	EXPECT_TRUE(mutex_lock(mutex));

	EXPECT_TRUE(mutex_unlock(mutex));
	EXPECT_TRUE(mutex_unlock(mutex));
	EXPECT_TRUE(mutex_unlock(mutex));
	EXPECT_TRUE(mutex_unlock(mutex));

	log_set_suppress(0, ERRORLEVEL_WARNING);
	EXPECT_FALSE(mutex_unlock(mutex));
	log_set_suppress(0, ERRORLEVEL_INFO);

	mutex_signal(mutex);
	thread_yield();
	EXPECT_TRUE(mutex_try_wait(mutex, 1));
	EXPECT_TRUE(mutex_unlock(mutex));

	mutex_signal(mutex);
	thread_yield();
	EXPECT_TRUE(mutex_wait(mutex));
	EXPECT_TRUE(mutex_unlock(mutex));

	log_set_suppress(0, ERRORLEVEL_WARNING);
	EXPECT_FALSE(mutex_try_wait(mutex, 100));
	EXPECT_FALSE(mutex_unlock(mutex));
	log_set_suppress(0, ERRORLEVEL_INFO);

	mutex_signal(mutex);
	thread_yield();
	EXPECT_TRUE(mutex_try_wait(mutex, 1));
	log_set_suppress(0, ERRORLEVEL_WARNING);
	EXPECT_FALSE(mutex_try_wait(mutex, 100));
	EXPECT_TRUE(mutex_unlock(mutex));
	EXPECT_FALSE(mutex_unlock(mutex));
	log_set_suppress(0, ERRORLEVEL_INFO);

	mutex_deallocate(mutex);

	return 0;
}
Ejemplo n.º 9
0
void im_connect (void *appdata)
{
  im_IMVERSION = box_dv_short_string (IM_VERSION);
  im_lib_mutex = mutex_allocate ();

  bif_define ("IM ResizeImageFile", bif_im_ResizeImageFile);
  bif_define ("IM ThumbnailImageFile", bif_im_ThumbnailImageFile);
  bif_define ("IM ConvertImageFile", bif_im_ConvertImageFile);
  bif_define ("IM ResampleImageFile", bif_im_ResampleImageFile);
  bif_define ("IM RotateImageFile", bif_im_RotateImageFile);
  bif_define ("IM CropImageFile", bif_im_CropImageFile);
  bif_define ("IM GetImageFileAttribute", bif_im_GetImageFileAttribute);
  bif_define ("IM GetImageFileFormat", bif_im_GetImageFileFormat);
  bif_define ("IM GetImageFileIdentify", bif_im_GetImageFileIdentify);
  bif_define ("IM GetImageBlobIdentify", bif_im_GetImageBlobIdentify);

  bif_define ("IM GetImageFileWidth", bif_im_GetImageFileWidth);
  bif_define ("IM GetImageFileHeight", bif_im_GetImageFileHeight);
  bif_define ("IM GetImageFileDepth", bif_im_GetImageFileDepth);
  bif_define ("IM GetImageFileWH", bif_im_GetImageFileWH);

  bif_define ("IM ResizeImageFileToBlob", bif_im_ResizeImageFileToBlob);
  bif_define ("IM ThumbnailImageFileToBlob", bif_im_ThumbnailImageFileToBlob);
  bif_define ("IM ResampleImageFileToBlob", bif_im_ResampleImageFileToBlob);
  bif_define ("IM RotateImageFileToBlob", bif_im_RotateImageFileToBlob);
  bif_define ("IM CropImageFileToBlob", bif_im_CropImageFileToBlob);
  bif_define ("IM GetImageBlobAttribute", bif_im_GetImageBlobAttribute);
  bif_define ("IM GetImageBlobFormat", bif_im_GetImageBlobFormat);
  bif_define ("IM GetImageBlobWidth", bif_im_GetImageBlobWidth);
  bif_define ("IM GetImageBlobHeight", bif_im_GetImageBlobHeight);
  bif_define ("IM GetImageBlobDepth", bif_im_GetImageBlobDepth);
  bif_define ("IM GetImageBlobWH", bif_im_GetImageBlobWH);

  bif_define ("IM ConvertImageBlob", bif_im_ConvertImageBlob);
  bif_define ("IM ResizeImageBlob", bif_im_ResizeImageBlob);
  bif_define ("IM ThumbnailImageBlob", bif_im_ThumbnailImageBlob);
  bif_define ("IM DeepZoom4to1", bif_im_DeepZoom4to1);
  bif_define ("IM ResampleImageBlob", bif_im_ResampleImageBlob);
  bif_define ("IM RotateImageBlob", bif_im_RotateImageBlob);
  bif_define ("IM CropImageBlob", bif_im_CropImageBlob);
  bif_define ("IM CropAndResizeImageBlob", bif_im_CropAndResizeImageBlob);
#if defined(HasTTF) || defined(HasFREETYPE)
  bif_define ("IM AnnotateImageBlob", bif_im_AnnotateImageBlob);
#endif
  bif_define ("IM CreateImageBlob", bif_im_CreateImageBlob);
  bif_define ("IM XYtoMorton", bif_im_XY_to_Morton);
  MagickWandGenesis();
}
Ejemplo n.º 10
0
int _random_initialize( void )
{
	if( !_random_mutex )
	{
		int i;
		_random_mutex = mutex_allocate( "random" );

		//Allocate and seed a number of state buffers
		array_reserve( _random_state, 64 );
		array_reserve( _random_available_state, 64 );
		for( i = 0; i < 16; ++i )
		{
			unsigned int* buffer = _random_allocate_buffer();
			array_push( _random_available_state, buffer );
		}
	}
	return 0;
}
Ejemplo n.º 11
0
DECLARE_TEST( mutex, signal )
{
	mutex_t* mutex;
	object_t thread[32];
	int ith;

	mutex = mutex_allocate( "test" );
	mutex_lock( mutex );

	for( ith = 0; ith < 32; ++ith )
	{
		thread[ith] = thread_create( thread_wait, "thread_wait", THREAD_PRIORITY_NORMAL, 0 );
		thread_start( thread[ith], mutex );
	}

	mutex_unlock( mutex );

	test_wait_for_threads_startup( thread, 32 );

	while( atomic_load32( &thread_waiting ) < 32 )
		thread_yield();
	thread_sleep( 1000 ); //Hack wait to give threads time to progress from atomic_incr to mutex_wait

	mutex_signal( mutex );

	for( ith = 0; ith < 32; ++ith )
	{
		thread_terminate( thread[ith] );
		thread_destroy( thread[ith] );
	}

	test_wait_for_threads_exit( thread, 32 );

	EXPECT_EQ( atomic_load32( &thread_waited ), 32 );

	EXPECT_FALSE( mutex_wait( mutex, 500 ) );

	mutex_deallocate( mutex );

	return 0;
}
Ejemplo n.º 12
0
DECLARE_TEST(mutex, signal) {
	mutex_t* mutex;
	thread_t thread[32];
	size_t ith;

	mutex = mutex_allocate(STRING_CONST("test"));
	mutex_lock(mutex);

	for (ith = 0; ith < 32; ++ith)
		thread_initialize(&thread[ith], thread_waiter, mutex, STRING_CONST("thread_wait"),
		                  THREAD_PRIORITY_NORMAL, 0);
	for (ith = 0; ith < 32; ++ith)
		thread_start(&thread[ith]);

	mutex_unlock(mutex);

	test_wait_for_threads_startup(thread, 32);

	while (atomic_load32(&thread_waiting) < 32)
		thread_yield();
	thread_sleep(1000);   //Hack wait to give threads time to progress from atomic_incr to mutex_wait

	mutex_signal(mutex);

	test_wait_for_threads_finish(thread, 32);

	for (ith = 0; ith < 32; ++ith)
		thread_finalize(&thread[ith]);

	EXPECT_EQ(atomic_load32(&thread_waited), 32);

	EXPECT_FALSE(mutex_try_wait(mutex, 500));

	mutex_deallocate(mutex);

	return 0;
}
Ejemplo n.º 13
0
spinlock_t *
spinlock_allocate (void)
{
  return (spinlock_t *) mutex_allocate ();
}
Ejemplo n.º 14
0
int
lua_modulemap_initialize(void) {
	_lua_modulemap = hashmap_allocate(13, 7);
	_lua_modulemap_lock = mutex_allocate(STRING_CONST("lua-modulemap"));
	return 0;
}
Ejemplo n.º 15
0
/*
 * Make mutex
 */
ScmObj Scm_MakeMutex(ScmObj name)
{
    ScmObj m = mutex_allocate(SCM_CLASS_MUTEX, SCM_NIL);
    SCM_MUTEX(m)->name = name;
    return m;
}
Ejemplo n.º 16
0
dk_mutex_t *
mutex_allocate_typed (int n)
{
  return mutex_allocate();
}
Ejemplo n.º 17
0
void
bif_init_func_javavm (void)
{
  java_vm_mutex = mutex_allocate ();
  bif_define ("do_something_bif", bif_do_something_bif);
}