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 /*****************************************************************************/
32 /* osl_createCondition */
33 /*****************************************************************************/
34 oslCondition SAL_CALL
osl_createCondition(void)
36 oslCondition Condition
;
38 Condition
= (oslCondition
)CreateEvent(0, /* no security */
39 sal_True
, /* manual reset */
40 sal_False
, /* initial state not signaled */
41 0); /* automatic name */
47 /*****************************************************************************/
48 /* osl_destroyCondition */
49 /*****************************************************************************/
50 void SAL_CALL
osl_destroyCondition(oslCondition Condition
)
54 OSL_VERIFY(CloseHandle(Condition
));
58 /*****************************************************************************/
59 /* osl_setCondition */
60 /*****************************************************************************/
61 sal_Bool SAL_CALL
osl_setCondition(oslCondition Condition
)
63 OSL_ASSERT(Condition
);
65 return (sal_Bool
)(SetEvent((HANDLE
)Condition
) != FALSE
);
68 /*****************************************************************************/
69 /* osl_resetCondition */
70 /*****************************************************************************/
71 sal_Bool SAL_CALL
osl_resetCondition(oslCondition Condition
)
73 OSL_ASSERT(Condition
);
75 return (sal_Bool
)(ResetEvent((HANDLE
)Condition
) != FALSE
);
78 /*****************************************************************************/
79 /* osl_waitCondition */
80 /*****************************************************************************/
81 oslConditionResult SAL_CALL
osl_waitCondition(oslCondition Condition
,
82 const TimeValue
* pTimeout
)
86 OSL_ASSERT(Condition
);
89 timeout
= pTimeout
->Seconds
* 1000 + pTimeout
->Nanosec
/ 1000000L;
93 /* It's necessary to process SendMessage calls to the current thread to give other threads
94 access to COM objects instatiated in this thread */
98 /* Only wake up if a SendMessage call to the threads message loop is detected */
99 switch( MsgWaitForMultipleObjects( 1, (HANDLE
*)(&Condition
), FALSE
, timeout
, QS_SENDMESSAGE
) )
101 case WAIT_OBJECT_0
+ 1:
105 /* We Must not dispatch the message. PM_NOREMOVE leaves the message queue untouched
106 but dispatches SendMessage calls automatically */
108 PeekMessage( &msg
, NULL
, 0, 0, PM_NOREMOVE
);
113 return (osl_cond_result_ok
);
116 return (osl_cond_result_timeout
);
119 return (osl_cond_result_error
);
124 /*****************************************************************************/
125 /* osl_checkCondition */
126 /*****************************************************************************/
127 sal_Bool SAL_CALL
osl_checkCondition(oslCondition Condition
)
129 OSL_ASSERT(Condition
);
131 return (sal_Bool
)(WaitForSingleObject((HANDLE
)Condition
, 0) == WAIT_OBJECT_0
);
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */