VirtualBox

source: vbox/trunk/src/VBox/Runtime/r3/win/semeventmulti-win.cpp@ 25640

Last change on this file since 25640 was 25640, checked in by vboxsync, 15 years ago

iprt: Added RTSemEventMulti[Set|Add|Remove]Signaller.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 4.7 KB
Line 
1/* $Id: semeventmulti-win.cpp 25640 2010-01-04 16:44:23Z vboxsync $ */
2/** @file
3 * IPRT - Multiple Release Event Semaphore, Windows.
4 */
5
6/*
7 * Copyright (C) 2006-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 RTLOGGROUP_SEMAPHORE
36#include <Windows.h>
37
38#include <iprt/semaphore.h>
39#include <iprt/thread.h>
40#include <iprt/assert.h>
41#include <iprt/err.h>
42#include "internal/strict.h"
43
44
45/*******************************************************************************
46* Defined Constants And Macros *
47*******************************************************************************/
48/** Converts semaphore to win32 handle. */
49#define SEM2HND(Sem) ((HANDLE)(uintptr_t)Sem)
50
51
52/* Undefine debug mappings. */
53#undef RTSemEventMultiWait
54#undef RTSemEventMultiWaitNoResume
55
56
57RTDECL(int) RTSemEventMultiCreate(PRTSEMEVENTMULTI pEventMultiSem)
58{
59 /*
60 * Create the semaphore.
61 * (Manual reset, not signaled, private event object.)
62 */
63 HANDLE hev = CreateEvent(NULL, TRUE, FALSE, NULL);
64 if (hev)
65 {
66 *pEventMultiSem = (RTSEMEVENTMULTI)(void *)hev;
67 return VINF_SUCCESS;
68 }
69 return RTErrConvertFromWin32(GetLastError());
70}
71
72
73RTDECL(int) RTSemEventMultiDestroy(RTSEMEVENTMULTI EventMultiSem)
74{
75 /*
76 * Close semaphore handle.
77 */
78 if (CloseHandle(SEM2HND(EventMultiSem)))
79 return VINF_SUCCESS;
80 AssertMsgFailed(("Destroy EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));
81 return RTErrConvertFromWin32(GetLastError());
82}
83
84
85RTDECL(int) RTSemEventMultiSignal(RTSEMEVENTMULTI EventMultiSem)
86{
87 /*
88 * Signal the object.
89 */
90 if (SetEvent(SEM2HND(EventMultiSem)))
91 return VINF_SUCCESS;
92 AssertMsgFailed(("Signaling EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));
93 return RTErrConvertFromWin32(GetLastError());
94}
95
96
97RTDECL(int) RTSemEventMultiReset(RTSEMEVENTMULTI EventMultiSem)
98{
99 /*
100 * Reset the object.
101 */
102 if (ResetEvent(SEM2HND(EventMultiSem)))
103 return VINF_SUCCESS;
104 AssertMsgFailed(("Resetting EventMultiSem %p failed, lasterr=%d\n", EventMultiSem, GetLastError()));
105 return RTErrConvertFromWin32(GetLastError());
106}
107
108
109RTDECL(int) RTSemEventMultiWaitNoResume(RTSEMEVENTMULTI EventMultiSem, unsigned cMillies)
110{
111 /*
112 * Wait for condition.
113 */
114 int rc = WaitForSingleObjectEx(SEM2HND(EventMultiSem), cMillies == RT_INDEFINITE_WAIT ? INFINITE : cMillies, TRUE);
115 switch (rc)
116 {
117 case WAIT_OBJECT_0: return VINF_SUCCESS;
118 case WAIT_TIMEOUT: return VERR_TIMEOUT;
119 case WAIT_IO_COMPLETION: return VERR_INTERRUPTED;
120 case WAIT_ABANDONED: return VERR_SEM_OWNER_DIED;
121 default:
122 {
123 AssertMsgFailed(("Wait on EventMultiSem %p failed, rc=%d lasterr=%d\n", EventMultiSem, rc, GetLastError()));
124 int rc2 = RTErrConvertFromWin32(GetLastError());
125 if (rc2)
126 return rc2;
127
128 AssertMsgFailed(("WaitForSingleObject(event) -> rc=%d while converted lasterr=%d\n", rc, rc2));
129 return VERR_INTERNAL_ERROR;
130 }
131 }
132}
133
134
135RTDECL(void) RTSemEventMultiSetSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
136{
137 /** @todo implement RTSemEventMultiSetSignaller on Windows */
138}
139
140
141RTDECL(void) RTSemEventMultiAddSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
142{
143}
144
145
146RTDECL(void) RTSemEventMultiRemoveSignaller(RTSEMEVENTMULTI hEventMultiSem, RTTHREAD hThread)
147{
148}
149
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