Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / sal / osl / w32 / conditn.c
blob1f83cd1cb1a2b8e77b3778fa87d25b1928210a4d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include "system.h"
22 #include <osl/conditn.h>
23 #include <osl/diagnose.h>
24 #include <osl/time.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 */
43 return Condition;
47 /*****************************************************************************/
48 /* osl_destroyCondition */
49 /*****************************************************************************/
50 void SAL_CALL osl_destroyCondition(oslCondition Condition)
52 if(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)
84 DWORD timeout;
86 OSL_ASSERT(Condition);
88 if (pTimeout)
89 timeout = pTimeout->Seconds * 1000 + pTimeout->Nanosec / 1000000L;
90 else
91 timeout = INFINITE;
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 */
96 while ( 1 )
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:
103 MSG msg;
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 );
110 break;
112 case WAIT_OBJECT_0:
113 return (osl_cond_result_ok);
115 case WAIT_TIMEOUT:
116 return (osl_cond_result_timeout);
118 default:
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: */