1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 #include <osl/conditn.h>
31 #include <osl/diagnose.h>
35 under WIN32, we use the void* oslCondition
36 as a WIN32 HANDLE (which is also a 32-bit value)
39 /*****************************************************************************/
40 /* osl_createCondition */
41 /*****************************************************************************/
42 oslCondition SAL_CALL
osl_createCondition(void)
44 oslCondition Condition
;
46 Condition
= (oslCondition
)CreateEvent(0, /* no security */
47 sal_True
, /* manual reset */
48 sal_False
, /* initial state not signaled */
49 0); /* automatic name */
55 /*****************************************************************************/
56 /* osl_destroyCondition */
57 /*****************************************************************************/
58 void SAL_CALL
osl_destroyCondition(oslCondition Condition
)
62 OSL_VERIFY(CloseHandle(Condition
));
66 /*****************************************************************************/
67 /* osl_setCondition */
68 /*****************************************************************************/
69 sal_Bool SAL_CALL
osl_setCondition(oslCondition Condition
)
71 OSL_ASSERT(Condition
);
73 return (sal_Bool
)(SetEvent((HANDLE
)Condition
) != FALSE
);
76 /*****************************************************************************/
77 /* osl_resetCondition */
78 /*****************************************************************************/
79 sal_Bool SAL_CALL
osl_resetCondition(oslCondition Condition
)
81 OSL_ASSERT(Condition
);
83 return (sal_Bool
)(ResetEvent((HANDLE
)Condition
) != FALSE
);
86 /*****************************************************************************/
87 /* osl_waitCondition */
88 /*****************************************************************************/
89 oslConditionResult SAL_CALL
osl_waitCondition(oslCondition Condition
,
90 const TimeValue
* pTimeout
)
94 OSL_ASSERT(Condition
);
97 timeout
= pTimeout
->Seconds
* 1000 + pTimeout
->Nanosec
/ 1000000L;
101 /* It's necessary to process SendMessage calls to the current thread to give other threads
102 access to COM objects instatiated in this thread */
106 /* Only wake up if a SendMessage call to the threads message loop is detected */
107 switch( MsgWaitForMultipleObjects( 1, (HANDLE
*)(&Condition
), FALSE
, timeout
, QS_SENDMESSAGE
) )
109 case WAIT_OBJECT_0
+ 1:
113 /* We Must not dispatch the message. PM_NOREMOVE leaves the message queue untouched
114 but dispatches SendMessage calls automatically */
116 PeekMessage( &msg
, NULL
, 0, 0, PM_NOREMOVE
);
121 return (osl_cond_result_ok
);
124 return (osl_cond_result_timeout
);
127 return (osl_cond_result_error
);
132 /*****************************************************************************/
133 /* osl_checkCondition */
134 /*****************************************************************************/
135 sal_Bool SAL_CALL
osl_checkCondition(oslCondition Condition
)
137 OSL_ASSERT(Condition
);
139 return (sal_Bool
)(WaitForSingleObject((HANDLE
)Condition
, 0) == WAIT_OBJECT_0
);