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>
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()
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 */
59 return (oslCondition
)hevCondition
;
64 /*****************************************************************************/
65 /* osl_destroyCondition */
66 /*****************************************************************************/
67 void SAL_CALL
osl_destroyCondition(oslCondition 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
)
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
)
102 OSL_ASSERT(Condition
);
105 nTimeout
= pTimeout
->Seconds
* 1000 + pTimeout
->Nanosec
/ 1000000;
107 nTimeout
= SEM_INDEFINITE_WAIT
;
109 rc
= DosWaitEventSem((HEV
)Condition
, nTimeout
);
110 if( rc
== ERROR_TIMEOUT
)
111 return osl_cond_result_timeout
;
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
);