xref: /aoo41x/main/sal/osl/os2/conditn.c (revision 647f063d)
1*647f063dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*647f063dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*647f063dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*647f063dSAndrew Rist  * distributed with this work for additional information
6*647f063dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*647f063dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*647f063dSAndrew Rist  * "License"); you may not use this file except in compliance
9*647f063dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*647f063dSAndrew Rist  *
11*647f063dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*647f063dSAndrew Rist  *
13*647f063dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*647f063dSAndrew Rist  * software distributed under the License is distributed on an
15*647f063dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*647f063dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*647f063dSAndrew Rist  * specific language governing permissions and limitations
18*647f063dSAndrew Rist  * under the License.
19*647f063dSAndrew Rist  *
20*647f063dSAndrew Rist  *************************************************************/
21*647f063dSAndrew Rist 
22*647f063dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "system.h"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <osl/conditn.h>
27cdf0e10cSrcweir #include <osl/diagnose.h>
28cdf0e10cSrcweir #include <osl/time.h>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir 
31cdf0e10cSrcweir 
32cdf0e10cSrcweir /*
33cdf0e10cSrcweir     under WIN32, we use the void* oslCondition
34cdf0e10cSrcweir     as a WIN32 HANDLE (which is also a 32-bit value)
35cdf0e10cSrcweir */
36cdf0e10cSrcweir 
37cdf0e10cSrcweir /*****************************************************************************/
38cdf0e10cSrcweir /* osl_createCondition */
39cdf0e10cSrcweir /*****************************************************************************/
osl_createCondition()40cdf0e10cSrcweir oslCondition SAL_CALL osl_createCondition()
41cdf0e10cSrcweir {
42cdf0e10cSrcweir     HEV hevCondition;
43cdf0e10cSrcweir     APIRET rc;
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     rc = DosCreateEventSem( NULL,       /* unnamed semaphore */
46cdf0e10cSrcweir                             &hevCondition,  /* pointer to variable */
47cdf0e10cSrcweir                                                    /* for the sem-handle */
48cdf0e10cSrcweir                             DC_SEM_SHARED,  /* shared semaphore */
49cdf0e10cSrcweir                             FALSE );         /* initial state is posted */
50cdf0e10cSrcweir 
51cdf0e10cSrcweir     if( rc == NO_ERROR )
52cdf0e10cSrcweir         return (oslCondition)hevCondition;
53cdf0e10cSrcweir     else
54cdf0e10cSrcweir         return NULL;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir 
57cdf0e10cSrcweir /*****************************************************************************/
58cdf0e10cSrcweir /* osl_destroyCondition */
59cdf0e10cSrcweir /*****************************************************************************/
osl_destroyCondition(oslCondition Condition)60cdf0e10cSrcweir void SAL_CALL osl_destroyCondition(oslCondition Condition)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     if( Condition )
63cdf0e10cSrcweir         DosCloseEventSem( (HEV) Condition );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir /*****************************************************************************/
67cdf0e10cSrcweir /* osl_setCondition */
68cdf0e10cSrcweir /*****************************************************************************/
osl_setCondition(oslCondition Condition)69cdf0e10cSrcweir sal_Bool SAL_CALL osl_setCondition(oslCondition Condition)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir     OSL_ASSERT(Condition);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir     return DosPostEventSem((HEV)Condition) == NO_ERROR;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir /*****************************************************************************/
77cdf0e10cSrcweir /* osl_resetCondition */
78cdf0e10cSrcweir /*****************************************************************************/
osl_resetCondition(oslCondition Condition)79cdf0e10cSrcweir sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     ULONG ulPostCount;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir     OSL_ASSERT(Condition);
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     return DosResetEventSem((HEV)Condition, &ulPostCount) == NO_ERROR;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir /*****************************************************************************/
89cdf0e10cSrcweir /* osl_waitCondition */
90cdf0e10cSrcweir /*****************************************************************************/
osl_waitCondition(oslCondition Condition,const TimeValue * pTimeout)91cdf0e10cSrcweir oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const TimeValue * pTimeout )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     long nTimeout;
94cdf0e10cSrcweir     APIRET rc;
95cdf0e10cSrcweir     OSL_ASSERT(Condition);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir     if( pTimeout )
98cdf0e10cSrcweir         nTimeout = pTimeout->Seconds * 1000 + pTimeout->Nanosec / 1000000;
99cdf0e10cSrcweir     else
100cdf0e10cSrcweir         nTimeout = SEM_INDEFINITE_WAIT;
101cdf0e10cSrcweir 
102cdf0e10cSrcweir     rc = DosWaitEventSem((HEV)Condition, nTimeout );
103cdf0e10cSrcweir     if( rc == ERROR_TIMEOUT )
104cdf0e10cSrcweir         return osl_cond_result_timeout;
105cdf0e10cSrcweir     if( rc != NO_ERROR )
106cdf0e10cSrcweir         return osl_cond_result_error;
107cdf0e10cSrcweir 
108cdf0e10cSrcweir     return osl_cond_result_ok;
109cdf0e10cSrcweir }
110cdf0e10cSrcweir 
111cdf0e10cSrcweir /*****************************************************************************/
112cdf0e10cSrcweir /* osl_checkCondition */
113cdf0e10cSrcweir /*****************************************************************************/
osl_checkCondition(oslCondition Condition)114cdf0e10cSrcweir sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir     OSL_ASSERT(Condition);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     return( DosWaitEventSem((HEV)Condition, SEM_IMMEDIATE_RETURN) == NO_ERROR);
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121