+#if CONFIG_THREAD_GROUPS
+struct thread_group *
+task_coalition_get_thread_group(task_t task)
+{
+ coalition_t coal = task->coalition[COALITION_TYPE_JETSAM];
+ /* return system thread group for non-jetsam coalitions */
+ if (coal == COALITION_NULL) {
+ return init_coalition[COALITION_TYPE_JETSAM]->j.thread_group;
+ }
+ return coal->j.thread_group;
+}
+
+
+struct thread_group *
+kdp_coalition_get_thread_group(coalition_t coal)
+{
+ if (coal->type != COALITION_TYPE_JETSAM) {
+ return NULL;
+ }
+ assert(coal->j.thread_group != NULL);
+ return coal->j.thread_group;
+}
+
+struct thread_group *
+coalition_get_thread_group(coalition_t coal)
+{
+ if (coal->type != COALITION_TYPE_JETSAM) {
+ return NULL;
+ }
+ assert(coal->j.thread_group != NULL);
+ return thread_group_retain(coal->j.thread_group);
+}
+
+void
+coalition_set_thread_group(coalition_t coal, struct thread_group *tg)
+{
+ assert(coal != COALITION_NULL);
+ assert(tg != NULL);
+
+ if (coal->type != COALITION_TYPE_JETSAM) {
+ return;
+ }
+ struct thread_group *old_tg = coal->j.thread_group;
+ assert(old_tg != NULL);
+ coal->j.thread_group = tg;
+
+ KDBG_RELEASE(MACHDBG_CODE(DBG_MACH_COALITION, MACH_COALITION_THREAD_GROUP_SET),
+ coal->id, coal->type, thread_group_get_id(tg));
+
+ thread_group_release(old_tg);
+}
+
+void
+task_coalition_thread_group_focal_update(task_t task)
+{
+ assert(task->coalition[COALITION_FOCAL_TASKS_ACCOUNTING] != COALITION_NULL);
+ thread_group_flags_update_lock();
+ uint32_t focal_count = task_coalition_focal_count(task);
+ if (focal_count) {
+ thread_group_set_flags_locked(task_coalition_get_thread_group(task), THREAD_GROUP_FLAGS_UI_APP);
+ } else {
+ thread_group_clear_flags_locked(task_coalition_get_thread_group(task), THREAD_GROUP_FLAGS_UI_APP);
+ }
+ thread_group_flags_update_unlock();
+}
+
+#endif