@@ -1578,3 +1578,71 @@ static int s_test_event_loop_serialized_scheduling(struct aws_allocator *allocat
15781578}
15791579
15801580AWS_TEST_CASE (event_loop_serialized_scheduling , s_test_event_loop_serialized_scheduling )
1581+
1582+ struct aws_elg_callers_context {
1583+ struct aws_event_loop_group * elg ;
1584+ bool is_callers_thread ;
1585+ struct aws_mutex mutex ;
1586+ struct aws_condition_variable condition_variable ;
1587+ bool invoked ;
1588+ };
1589+
1590+ static void s_test_elg_callers_task (struct aws_task * task , void * user_data , enum aws_task_status status ) {
1591+ (void )task ;
1592+ (void )status ;
1593+ struct aws_elg_callers_context * context = user_data ;
1594+ aws_mutex_lock (& context -> mutex );
1595+ context -> is_callers_thread = aws_event_loop_group_any_thread_is_callers_thread (context -> elg );
1596+ context -> invoked = true;
1597+ aws_mutex_unlock (& context -> mutex );
1598+ aws_condition_variable_notify_one (& context -> condition_variable );
1599+ }
1600+
1601+ static bool s_test_elg_callers_task_invoked (void * args ) {
1602+ struct aws_elg_callers_context * context = args ;
1603+ return context -> invoked ;
1604+ }
1605+
1606+ static int s_test_event_loop_group_is_callers_thread (struct aws_allocator * allocator , void * ctx ) {
1607+ (void )ctx ;
1608+
1609+ aws_io_library_init (allocator );
1610+
1611+ struct aws_event_loop_group_options elg_options = {
1612+ .loop_count = 4 ,
1613+ };
1614+
1615+ struct aws_event_loop_group * event_loop_group = aws_event_loop_group_new (allocator , & elg_options );
1616+
1617+ ASSERT_FALSE (aws_event_loop_group_any_thread_is_callers_thread (event_loop_group ));
1618+
1619+ struct aws_event_loop * event_loop = aws_event_loop_group_get_next_loop (event_loop_group );
1620+
1621+ struct aws_thread external_thread ;
1622+ aws_thread_init (& external_thread , allocator );
1623+
1624+ struct aws_elg_callers_context context = {
1625+ .elg = event_loop_group ,
1626+ .is_callers_thread = false,
1627+ .condition_variable = AWS_CONDITION_VARIABLE_INIT ,
1628+ .mutex = AWS_MUTEX_INIT ,
1629+ };
1630+
1631+ struct aws_task task ;
1632+ aws_task_init (& task , s_test_elg_callers_task , & context , "check_elg_callers_thread" );
1633+
1634+ aws_event_loop_schedule_task_now (event_loop , & task );
1635+ ASSERT_SUCCESS (aws_condition_variable_wait_pred (
1636+ & context .condition_variable , & context .mutex , s_test_elg_callers_task_invoked , & context ));
1637+ aws_mutex_unlock (& context .mutex );
1638+
1639+ ASSERT_TRUE (context .is_callers_thread );
1640+
1641+ aws_event_loop_group_release (event_loop_group );
1642+
1643+ aws_io_library_clean_up ();
1644+
1645+ return AWS_OP_SUCCESS ;
1646+ }
1647+
1648+ AWS_TEST_CASE (event_loop_group_is_callers_thread , s_test_event_loop_group_is_callers_thread )
0 commit comments