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