VirtualBox

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

Last change on this file since 94768 was 93115, checked in by vboxsync, 3 years ago

scm --update-copyright-year

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