1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 #include <osl/conditn.h>
23 #include <osl/diagnose.h>
27 under WIN32, we use the void* oslCondition
28 as a WIN32 HANDLE (which is also a 32-bit value)
31 oslCondition SAL_CALL
osl_createCondition(void)
33 oslCondition Condition
;
35 Condition
= reinterpret_cast<oslCondition
>(CreateEventW(nullptr, /* no security */
36 true, /* manual reset */
37 false, /* initial state not signaled */
38 nullptr)); /* automatic name */
44 void SAL_CALL
osl_destroyCondition(oslCondition Condition
)
47 OSL_VERIFY(CloseHandle(Condition
));
50 sal_Bool SAL_CALL
osl_setCondition(oslCondition Condition
)
52 OSL_ASSERT(Condition
);
54 return SetEvent(reinterpret_cast<HANDLE
>(Condition
)) != FALSE
;
57 sal_Bool SAL_CALL
osl_resetCondition(oslCondition Condition
)
59 OSL_ASSERT(Condition
);
61 return ResetEvent(reinterpret_cast<HANDLE
>(Condition
)) != FALSE
;
64 oslConditionResult SAL_CALL
osl_waitCondition(oslCondition Condition
,
65 const TimeValue
* pTimeout
)
69 OSL_ASSERT(Condition
);
72 timeout
= pTimeout
->Seconds
* 1000 + pTimeout
->Nanosec
/ 1000000L;
76 /* It's necessary to process SendMessage calls to the current thread to give other threads
77 access to COM objects instantiated in this thread */
81 /* Only wake up if a SendMessage call to the threads message loop is detected */
82 switch( MsgWaitForMultipleObjects( 1, reinterpret_cast<HANDLE
*>(&Condition
), FALSE
, timeout
, QS_SENDMESSAGE
) )
84 case WAIT_OBJECT_0
+ 1:
88 /* We Must not dispatch the message. PM_NOREMOVE leaves the message queue untouched
89 but dispatches SendMessage calls automatically */
91 PeekMessageW( &msg
, nullptr, 0, 0, PM_NOREMOVE
);
96 return osl_cond_result_ok
;
99 return osl_cond_result_timeout
;
102 return osl_cond_result_error
;
107 sal_Bool SAL_CALL
osl_checkCondition(oslCondition Condition
)
109 OSL_ASSERT(Condition
);
111 return WaitForSingleObject(reinterpret_cast<HANDLE
>(Condition
), 0) == WAIT_OBJECT_0
;
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */