1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: conditn.c,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <osl/conditn.h>
34 #include <osl/diagnose.h>
38 under WIN32, we use the void* oslCondition
39 as a WIN32 HANDLE (which is also a 32-bit value)
42 /*****************************************************************************/
43 /* osl_createCondition */
44 /*****************************************************************************/
45 oslCondition SAL_CALL
osl_createCondition(void)
47 oslCondition Condition
;
49 Condition
= (oslCondition
)CreateEvent(0, /* no security */
50 sal_True
, /* manual reset */
51 sal_False
, /* initial state not signaled */
52 0); /* automatic name */
58 /*****************************************************************************/
59 /* osl_destroyCondition */
60 /*****************************************************************************/
61 void SAL_CALL
osl_destroyCondition(oslCondition Condition
)
65 OSL_VERIFY(CloseHandle(Condition
));
69 /*****************************************************************************/
70 /* osl_setCondition */
71 /*****************************************************************************/
72 sal_Bool SAL_CALL
osl_setCondition(oslCondition Condition
)
74 OSL_ASSERT(Condition
);
76 return (sal_Bool
)(SetEvent((HANDLE
)Condition
) != FALSE
);
79 /*****************************************************************************/
80 /* osl_resetCondition */
81 /*****************************************************************************/
82 sal_Bool SAL_CALL
osl_resetCondition(oslCondition Condition
)
84 OSL_ASSERT(Condition
);
86 return (sal_Bool
)(ResetEvent((HANDLE
)Condition
) != FALSE
);
89 /*****************************************************************************/
90 /* osl_waitCondition */
91 /*****************************************************************************/
92 oslConditionResult SAL_CALL
osl_waitCondition(oslCondition Condition
,
93 const TimeValue
* pTimeout
)
97 OSL_ASSERT(Condition
);
100 timeout
= pTimeout
->Seconds
* 1000 + pTimeout
->Nanosec
/ 1000000L;
104 /* It's necessary to process SendMessage calls to the current thread to give other threads
105 access to COM objects instatiated in this thread */
109 /* Only wake up if a SendMessage call to the threads message loop is detected */
110 switch( MsgWaitForMultipleObjects( 1, (HANDLE
*)(&Condition
), FALSE
, timeout
, QS_SENDMESSAGE
) )
112 case WAIT_OBJECT_0
+ 1:
116 /* We Must not dispatch the message. PM_NOREMOVE leaves the message queue untouched
117 but dispatches SendMessage calls automatically */
119 PeekMessage( &msg
, NULL
, 0, 0, PM_NOREMOVE
);
124 return (osl_cond_result_ok
);
127 return (osl_cond_result_timeout
);
130 return (osl_cond_result_error
);
135 /*****************************************************************************/
136 /* osl_checkCondition */
137 /*****************************************************************************/
138 sal_Bool SAL_CALL
osl_checkCondition(oslCondition Condition
)
140 OSL_ASSERT(Condition
);
142 return (sal_Bool
)(WaitForSingleObject((HANDLE
)Condition
, 0) == WAIT_OBJECT_0
);