1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
30 #include <osl/conditn.h>
31 #include <osl/diagnose.h>
37 under WIN32, we use the void* oslCondition
38 as a WIN32 HANDLE (which is also a 32-bit value)
41 /*****************************************************************************/
42 /* osl_createCondition */
43 /*****************************************************************************/
44 oslCondition SAL_CALL
osl_createCondition()
49 rc
= DosCreateEventSem( NULL
, /* unnamed semaphore */
50 &hevCondition
, /* pointer to variable */
51 /* for the sem-handle */
52 DC_SEM_SHARED
, /* shared semaphore */
53 FALSE
); /* initial state is posted */
56 return (oslCondition
)hevCondition
;
61 /*****************************************************************************/
62 /* osl_destroyCondition */
63 /*****************************************************************************/
64 void SAL_CALL
osl_destroyCondition(oslCondition Condition
)
67 DosCloseEventSem( (HEV
) Condition
);
70 /*****************************************************************************/
71 /* osl_setCondition */
72 /*****************************************************************************/
73 sal_Bool SAL_CALL
osl_setCondition(oslCondition Condition
)
75 OSL_ASSERT(Condition
);
77 return DosPostEventSem((HEV
)Condition
) == NO_ERROR
;
80 /*****************************************************************************/
81 /* osl_resetCondition */
82 /*****************************************************************************/
83 sal_Bool SAL_CALL
osl_resetCondition(oslCondition Condition
)
87 OSL_ASSERT(Condition
);
89 return DosResetEventSem((HEV
)Condition
, &ulPostCount
) == NO_ERROR
;
92 /*****************************************************************************/
93 /* osl_waitCondition */
94 /*****************************************************************************/
95 oslConditionResult SAL_CALL
osl_waitCondition(oslCondition Condition
, const TimeValue
* pTimeout
)
99 OSL_ASSERT(Condition
);
102 nTimeout
= pTimeout
->Seconds
* 1000 + pTimeout
->Nanosec
/ 1000000;
104 nTimeout
= SEM_INDEFINITE_WAIT
;
106 rc
= DosWaitEventSem((HEV
)Condition
, nTimeout
);
107 if( rc
== ERROR_TIMEOUT
)
108 return osl_cond_result_timeout
;
110 return osl_cond_result_error
;
112 return osl_cond_result_ok
;
115 /*****************************************************************************/
116 /* osl_checkCondition */
117 /*****************************************************************************/
118 sal_Bool SAL_CALL
osl_checkCondition(oslCondition Condition
)
120 OSL_ASSERT(Condition
);
122 return( DosWaitEventSem((HEV
)Condition
, SEM_IMMEDIATE_RETURN
) == NO_ERROR
);