VirtualBox

source: vbox/trunk/src/VBox/HostDrivers/Support/SUPLibSem.cpp@ 20860

Last change on this file since 20860 was 19894, checked in by vboxsync, 16 years ago

SUPLibSem.cpp: Set cMillies.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 KB
Line 
1/* $Id: SUPLibSem.cpp 19894 2009-05-21 15:52:49Z vboxsync $ */
2/** @file
3 * VirtualBox Support Library - Semaphores, ring-3 implementation.
4 */
5
6/*
7 * Copyright (C) 2009 Sun Microsystems, Inc.
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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31
32/*******************************************************************************
33* Header Files *
34*******************************************************************************/
35#define LOG_GROUP LOG_GROUP_SUP
36#include <VBox/sup.h>
37
38#include <VBox/err.h>
39#include <VBox/param.h>
40#include <iprt/assert.h>
41
42#include "SUPLibInternal.h"
43#include "SUPDrvIOC.h"
44
45
46/**
47 * Worker that makes a SUP_IOCTL_SEM_OP request.
48 *
49 * @returns VBox status code.
50 * @param pSession The session handle.
51 * @param uType The semaphore type.
52 * @param hSem The semaphore handle.
53 * @param uOp The operation.
54 * @param cMillies The timeout if applicable, otherwise 0.
55 */
56DECLINLINE(int) supSemOp(PSUPDRVSESSION pSession, uint32_t uType, uintptr_t hSem, uint32_t uOp, uint32_t cMillies)
57{
58 SUPSEMOP Req;
59 Req.Hdr.u32Cookie = g_u32Cookie;
60 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
61 Req.Hdr.cbIn = SUP_IOCTL_SEM_OP_SIZE_IN;
62 Req.Hdr.cbOut = SUP_IOCTL_SEM_OP_SIZE_OUT;
63 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
64 Req.Hdr.rc = VERR_INTERNAL_ERROR;
65 Req.u.In.uType = uType;
66 Req.u.In.hSem = (uint32_t)hSem;
67 AssertReturn(Req.u.In.hSem == hSem, VERR_INVALID_HANDLE);
68 Req.u.In.uOp = uOp;
69 Req.u.In.cMillies = cMillies;
70 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SEM_OP, &Req, sizeof(Req));
71 if (RT_SUCCESS(rc))
72 rc = Req.Hdr.rc;
73
74 return rc;
75}
76
77
78SUPDECL(int) SUPSemEventCreate(PSUPDRVSESSION pSession, PSUPSEMEVENT phEvent)
79{
80 AssertPtrReturn(phEvent, VERR_INVALID_POINTER);
81
82 SUPSEMCREATE Req;
83 Req.Hdr.u32Cookie = g_u32Cookie;
84 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
85 Req.Hdr.cbIn = SUP_IOCTL_SEM_CREATE_SIZE_IN;
86 Req.Hdr.cbOut = SUP_IOCTL_SEM_CREATE_SIZE_OUT;
87 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
88 Req.Hdr.rc = VERR_INTERNAL_ERROR;
89 Req.u.In.uType = SUP_SEM_TYPE_EVENT;
90 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SEM_CREATE, &Req, sizeof(Req));
91 if (RT_SUCCESS(rc))
92 {
93 rc = Req.Hdr.rc;
94 if (RT_SUCCESS(rc))
95 *phEvent = (SUPSEMEVENT)(uintptr_t)Req.u.Out.hSem;
96 }
97
98 return rc;
99}
100
101
102SUPDECL(int) SUPSemEventClose(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent)
103{
104 if (hEvent == NIL_SUPSEMEVENT)
105 return VINF_SUCCESS;
106 return supSemOp(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP_CLOSE, 0);
107}
108
109
110SUPDECL(int) SUPSemEventSignal(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent)
111{
112 return supSemOp(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP_SIGNAL, 0);
113}
114
115
116SUPDECL(int) SUPSemEventWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENT hEvent, uint32_t cMillies)
117{
118 return supSemOp(pSession, SUP_SEM_TYPE_EVENT, (uintptr_t)hEvent, SUPSEMOP_WAIT, cMillies);
119}
120
121SUPDECL(int) SUPSemEventMultiCreate(PSUPDRVSESSION pSession, PSUPSEMEVENTMULTI phEventMulti)
122{
123 AssertPtrReturn(phEventMulti, VERR_INVALID_POINTER);
124
125 SUPSEMCREATE Req;
126 Req.Hdr.u32Cookie = g_u32Cookie;
127 Req.Hdr.u32SessionCookie = g_u32SessionCookie;
128 Req.Hdr.cbIn = SUP_IOCTL_SEM_CREATE_SIZE_IN;
129 Req.Hdr.cbOut = SUP_IOCTL_SEM_CREATE_SIZE_OUT;
130 Req.Hdr.fFlags = SUPREQHDR_FLAGS_DEFAULT;
131 Req.Hdr.rc = VERR_INTERNAL_ERROR;
132 Req.u.In.uType = SUP_SEM_TYPE_EVENT_MULTI;
133 int rc = suplibOsIOCtl(&g_supLibData, SUP_IOCTL_SEM_CREATE, &Req, sizeof(Req));
134 if (RT_SUCCESS(rc))
135 {
136 rc = Req.Hdr.rc;
137 if (RT_SUCCESS(rc))
138 *phEventMulti = (SUPSEMEVENTMULTI)(uintptr_t)Req.u.Out.hSem;
139 }
140
141 return rc;
142}
143
144
145SUPDECL(int) SUPSemEventMultiClose(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
146{
147 if (hEventMulti == NIL_SUPSEMEVENTMULTI)
148 return VINF_SUCCESS;
149 return supSemOp(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP_CLOSE, 0);
150}
151
152
153SUPDECL(int) SUPSemEventMultiSignal(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
154{
155 return supSemOp(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP_SIGNAL, 0);
156}
157
158
159SUPDECL(int) SUPSemEventMultiReset(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti)
160{
161 return supSemOp(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP_RESET, 0);
162}
163
164
165SUPDECL(int) SUPSemEventMultiWaitNoResume(PSUPDRVSESSION pSession, SUPSEMEVENTMULTI hEventMulti, uint32_t cMillies)
166{
167 return supSemOp(pSession, SUP_SEM_TYPE_EVENT_MULTI, (uintptr_t)hEventMulti, SUPSEMOP_WAIT, cMillies);
168}
169
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