update dev300-m57
[ooovba.git] / sal / osl / os2 / conditn.c
blob6bc724c10215d2d29433316bfecb346533ec4f09
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.6 $
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>
40 under WIN32, we use the void* oslCondition
41 as a WIN32 HANDLE (which is also a 32-bit value)
44 /*****************************************************************************/
45 /* osl_createCondition */
46 /*****************************************************************************/
47 oslCondition SAL_CALL osl_createCondition()
49 HEV hevCondition;
50 APIRET rc;
52 rc = DosCreateEventSem( NULL, /* unnamed semaphore */
53 &hevCondition, /* pointer to variable */
54 /* for the sem-handle */
55 DC_SEM_SHARED, /* shared semaphore */
56 FALSE ); /* initial state is posted */
58 if( rc == NO_ERROR )
59 return (oslCondition)hevCondition;
60 else
61 return NULL;
64 /*****************************************************************************/
65 /* osl_destroyCondition */
66 /*****************************************************************************/
67 void SAL_CALL osl_destroyCondition(oslCondition Condition)
69 if( Condition )
70 DosCloseEventSem( (HEV) Condition );
73 /*****************************************************************************/
74 /* osl_setCondition */
75 /*****************************************************************************/
76 sal_Bool SAL_CALL osl_setCondition(oslCondition Condition)
78 OSL_ASSERT(Condition);
80 return DosPostEventSem((HEV)Condition) == NO_ERROR;
83 /*****************************************************************************/
84 /* osl_resetCondition */
85 /*****************************************************************************/
86 sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition)
88 ULONG ulPostCount;
90 OSL_ASSERT(Condition);
92 return DosResetEventSem((HEV)Condition, &ulPostCount) == NO_ERROR;
95 /*****************************************************************************/
96 /* osl_waitCondition */
97 /*****************************************************************************/
98 oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const TimeValue * pTimeout )
100 long nTimeout;
101 APIRET rc;
102 OSL_ASSERT(Condition);
104 if( pTimeout )
105 nTimeout = pTimeout->Seconds * 1000 + pTimeout->Nanosec / 1000000;
106 else
107 nTimeout = SEM_INDEFINITE_WAIT;
109 rc = DosWaitEventSem((HEV)Condition, nTimeout );
110 if( rc == ERROR_TIMEOUT )
111 return osl_cond_result_timeout;
112 if( rc != NO_ERROR )
113 return osl_cond_result_error;
115 return osl_cond_result_ok;
118 /*****************************************************************************/
119 /* osl_checkCondition */
120 /*****************************************************************************/
121 sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition)
123 OSL_ASSERT(Condition);
125 return( DosWaitEventSem((HEV)Condition, SEM_IMMEDIATE_RETURN) == NO_ERROR);