update dev300-m58
[ooovba.git] / sal / osl / w32 / conditn.c
blobd6cf1a573732dc5130108f562025e9535cfc3098
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: conditn.c,v $
10 * $Revision: 1.8 $
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 ************************************************************************/
31 #include "system.h"
33 #include <osl/conditn.h>
34 #include <osl/diagnose.h>
35 #include <osl/time.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 */
54 return Condition;
58 /*****************************************************************************/
59 /* osl_destroyCondition */
60 /*****************************************************************************/
61 void SAL_CALL osl_destroyCondition(oslCondition Condition)
63 if(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)
95 DWORD timeout;
97 OSL_ASSERT(Condition);
99 if (pTimeout)
100 timeout = pTimeout->Seconds * 1000 + pTimeout->Nanosec / 1000000L;
101 else
102 timeout = INFINITE;
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 */
107 while ( 1 )
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:
114 MSG msg;
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 );
121 break;
123 case WAIT_OBJECT_0:
124 return (osl_cond_result_ok);
126 case WAIT_TIMEOUT:
127 return (osl_cond_result_timeout);
129 default:
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);