VirtualBox

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

Last change on this file since 899 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 3.4 KB
Line 
1/* $Id: semnoint-generic.cpp 1 1970-01-01 00:00:00Z vboxsync $ */
2/** @file
3 * InnoTek Portable Runtime - Generic Non-Interruptable Wait and Request Functions.
4 */
5
6/*
7 * Copyright (C) 2006 InnoTek Systemberatung 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 as published by the Free Software Foundation,
13 * in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
14 * distribution. VirtualBox OSE is distributed in the hope that it will
15 * be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * If you received this file as part of a commercial VirtualBox
18 * distribution, then only the terms of your commercial VirtualBox
19 * license agreement apply instead of the previous paragraph.
20 */
21
22
23/*******************************************************************************
24* Header Files *
25*******************************************************************************/
26#define LOG_GROUP RTLOGGROUP_SEM
27#include <iprt/semaphore.h>
28#include <iprt/time.h>
29#include <iprt/err.h>
30#include <iprt/assert.h>
31
32
33
34RTDECL(int) RTSemEventWait(RTSEMEVENT EventSem, unsigned cMillies)
35{
36 int rc;
37 if (cMillies == RT_INDEFINITE_WAIT)
38 {
39 do rc = RTSemEventWaitNoResume(EventSem, cMillies);
40 while (rc == VERR_INTERRUPTED);
41 }
42 else
43 {
44 const uint64_t u64Start = RTTimeMilliTS();
45 rc = RTSemEventWaitNoResume(EventSem, cMillies);
46 if (rc == VERR_INTERRUPTED)
47 {
48 do
49 {
50 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;
51 if (u64Elapsed >= cMillies)
52 return VERR_TIMEOUT;
53 rc = RTSemEventWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);
54 } while (rc == VERR_INTERRUPTED);
55 }
56 }
57 return rc;
58}
59
60
61RTDECL(int) RTSemEventMultiWait(RTSEMEVENTMULTI EventSem, unsigned cMillies)
62{
63 int rc;
64 if (cMillies == RT_INDEFINITE_WAIT)
65 {
66 do rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);
67 while (rc == VERR_INTERRUPTED);
68 }
69 else
70 {
71 const uint64_t u64Start = RTTimeMilliTS();
72 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies);
73 if (rc == VERR_INTERRUPTED)
74 {
75 do
76 {
77 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;
78 if (u64Elapsed >= cMillies)
79 return VERR_TIMEOUT;
80 rc = RTSemEventMultiWaitNoResume(EventSem, cMillies - (unsigned)u64Elapsed);
81 } while (rc == VERR_INTERRUPTED);
82 }
83 }
84 return rc;
85}
86
87
88RTDECL(int) RTSemMutexRequest(RTSEMMUTEX Mutex, unsigned cMillies)
89{
90 int rc;
91 if (cMillies == RT_INDEFINITE_WAIT)
92 {
93 do rc = RTSemMutexRequestNoResume(Mutex, cMillies);
94 while (rc == VERR_INTERRUPTED);
95 }
96 else
97 {
98 const uint64_t u64Start = RTTimeMilliTS();
99 rc = RTSemMutexRequestNoResume(Mutex, cMillies);
100 if (rc == VERR_INTERRUPTED)
101 {
102 do
103 {
104 uint64_t u64Elapsed = RTTimeMilliTS() - u64Start;
105 if (u64Elapsed >= cMillies)
106 return VERR_TIMEOUT;
107 rc = RTSemMutexRequestNoResume(Mutex, cMillies - (unsigned)u64Elapsed);
108 } while (rc == VERR_INTERRUPTED);
109 }
110 }
111 return rc;
112}
113
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