VirtualBox

source: vbox/trunk/src/VBox/Runtime/generic/semnoint-generic.cpp@ 5999

Last change on this file since 5999 was 5999, checked in by vboxsync, 17 years ago

The Giant CDDL Dual-License Header Change.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.7 KB
Line 
1/* $Id: semnoint-generic.cpp 5999 2007-12-07 15:05:06Z vboxsync $ */
2/** @file
3 * innotek Portable Runtime - Generic Non-Interruptable Wait and Request Functions.
4 */
5
6/*
7 * Copyright (C) 2006-2007 innotek GmbH
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
27
28/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#define LOG_GROUP RTLOGGROUP_SEM
32#include <iprt/semaphore.h>
33#include <iprt/time.h>
34#include <iprt/err.h>
35#include <iprt/assert.h>
36
37
38
39RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
40{
41 int rc;
42 if (cMillies == RT_INDEFINITE_WAIT)
43 {
44 do rc = RTSemEventWaitNoResume(EventSem, cMillies);
45 while (rc == VERR_INTERRUPTED);
46 }
47 else
48 {
49 const uint64_t u64Start = RTTimeMilliTS();
50 rc = RTSemEventWaitNoResume(EventSem, cMillies);
51 if (rc == VERR_INTERRUPTED)
52 {
53 do
54 {
55 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;
56 if (u64Elapsed >= cMillies)
57 return VERR_TIMEOUT;
58 rc = RTSemEventWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);
59 } while (rc == VERR_INTERRUPTED);
60 }
61 }
62 return rc;
63}
64
65
66RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventSem, unsigned cMillies)
67{
68 int rc;
69 if (cMillies == RT_INDEFINITE_WAIT)
70 {
71 do rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);
72 while (rc == VERR_INTERRUPTED);
73 }
74 else
75 {
76 const uint64_t u64Start = RTTimeMilliTS();
77 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);
78 if (rc == VERR_INTERRUPTED)
79 {
80 do
81 {
82 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;
83 if (u64Elapsed >= cMillies)
84 return VERR_TIMEOUT;
85 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);
86 } while (rc == VERR_INTERRUPTED);
87 }
88 }
89 return rc;
90}
91
92
93RTDECL(int) RTSemMutexRequest(RTSEMMUTEX Mutex, unsigned cMillies)
94{
95 int rc;
96 if (cMillies == RT_INDEFINITE_WAIT)
97 {
98 do rc = RTSemMutexRequestNoResume(Mutex, cMillies);
99 while (rc == VERR_INTERRUPTED);
100 }
101 else
102 {
103 const uint64_t u64Start = RTTimeMilliTS();
104 rc = RTSemMutexRequestNoResume(Mutex, cMillies);
105 if (rc == VERR_INTERRUPTED)
106 {
107 do
108 {
109 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;
110 if (u64Elapsed >= cMillies)
111 return VERR_TIMEOUT;
112 rc = RTSemMutexRequestNoResume(Mutex, cMillies - (unsigned)u64Elapsed);
113 } while (rc == VERR_INTERRUPTED);
114 }
115 }
116 return rc;
117}
118
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