VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/PDMAllTask.cpp@ 101189

Last change on this file since 101189 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.2 KB
Line 
1/* $Id: PDMAllTask.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * PDM Task - Asynchronous user mode tasks, all context code.
4 */
5
6/*
7 * Copyright (C) 2019-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29/*********************************************************************************************************************************
30* Header Files *
31*********************************************************************************************************************************/
32#define LOG_GROUP LOG_GROUP_PDM_TASK
33#include "PDMInternal.h"
34#include <VBox/vmm/pdmtask.h>
35#include <VBox/vmm/gvm.h>
36#include <VBox/err.h>
37
38#include <VBox/log.h>
39#include <VBox/sup.h>
40#include <iprt/asm.h>
41#include <iprt/assert.h>
42#include <iprt/semaphore.h>
43
44
45
46/**
47 * Triggers a task.
48 *
49 * @returns VBox status code.
50 * @retval VINF_ALREADY_POSTED is the task is already pending.
51 *
52 * @param pVM The cross context VM structure.
53 * @param enmType The task owner type.
54 * @param pvOwner The task owner.
55 * @param hTask The task to trigger.
56 * @thread Any
57 */
58VMM_INT_DECL(int) PDMTaskTrigger(PVMCC pVM, PDMTASKTYPE enmType, RTR3PTR pvOwner, PDMTASKHANDLE hTask)
59{
60 /*
61 * Validate input and translate the handle to a task.
62 */
63 AssertReturn(pvOwner, VERR_NOT_OWNER);
64 AssertReturn(enmType >= PDMTASKTYPE_DEV && enmType <= PDMTASKTYPE_INTERNAL, VERR_NOT_OWNER);
65
66 size_t const iTask = hTask % RT_ELEMENTS(pVM->pdm.s.aTaskSets[0].aTasks);
67 size_t const iTaskSet = hTask / RT_ELEMENTS(pVM->pdm.s.aTaskSets[0].aTasks);
68#ifdef IN_RING3
69 AssertReturn(iTaskSet < RT_ELEMENTS(pVM->pdm.s.apTaskSets), VERR_INVALID_HANDLE);
70 PPDMTASKSET pTaskSet = pVM->pdm.s.apTaskSets[iTaskSet];
71 AssertReturn(pTaskSet, VERR_INVALID_HANDLE);
72#else
73 AssertReturn(iTaskSet < RT_ELEMENTS(pVM->pdm.s.aTaskSets),
74 iTaskSet < RT_ELEMENTS(pVM->pdm.s.apTaskSets) ? VERR_INVALID_CONTEXT : VERR_INVALID_HANDLE);
75 PPDMTASKSET pTaskSet = &pVM->pdm.s.aTaskSets[iTaskSet];
76#endif
77 AssertReturn(pTaskSet->u32Magic == PDMTASKSET_MAGIC, VERR_INVALID_MAGIC);
78 PPDMTASK pTask = &pTaskSet->aTasks[iTask];
79
80 /*
81 * Check task ownership.
82 */
83 AssertReturn(pvOwner == pTask->pvOwner, VERR_NOT_OWNER);
84 AssertReturn(enmType == pTask->enmType, VERR_NOT_OWNER);
85
86 /*
87 * Trigger the task, wake up the thread if the task isn't triggered yet.
88 */
89 if (!ASMAtomicBitTestAndSet(&pTaskSet->fTriggered, (uint32_t)iTask))
90 {
91 Log(("PDMTaskTrigger: Triggered %RU64 (%s)\n", hTask, R3STRING(pTask->pszName)));
92#ifdef IN_RING3
93 if (pTaskSet->hEventR3 != NIL_RTSEMEVENT)
94 {
95 int rc = RTSemEventSignal(pTaskSet->hEventR3);
96 AssertLogRelRCReturn(rc, rc);
97 }
98 else
99#endif
100 {
101 int rc = SUPSemEventSignal(pVM->pSession, pTaskSet->hEventR0);
102 AssertLogRelRCReturn(rc, rc);
103 }
104 return VINF_SUCCESS;
105 }
106 ASMAtomicIncU32(&pTask->cAlreadyTrigged);
107 Log(("PDMTaskTrigger: %RU64 (%s) was already triggered\n", hTask, R3STRING(pTask->pszName)));
108 return VINF_ALREADY_POSTED;
109}
110
111
112/**
113 * Triggers an internal task.
114 *
115 * @returns VBox status code.
116 * @param pVM The cross context VM structure.
117 * @param hTask The task to trigger.
118 * @thread Any
119 */
120VMM_INT_DECL(int) PDMTaskTriggerInternal(PVMCC pVM, PDMTASKHANDLE hTask)
121{
122 return PDMTaskTrigger(pVM, PDMTASKTYPE_INTERNAL, pVM->pVMR3, hTask);
123}
124
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette