1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 #include "system.h" 29 30 #include <osl/conditn.h> 31 #include <osl/diagnose.h> 32 #include <osl/time.h> 33 34 35 36 /* 37 under WIN32, we use the void* oslCondition 38 as a WIN32 HANDLE (which is also a 32-bit value) 39 */ 40 41 /*****************************************************************************/ 42 /* osl_createCondition */ 43 /*****************************************************************************/ 44 oslCondition SAL_CALL osl_createCondition() 45 { 46 HEV hevCondition; 47 APIRET rc; 48 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 */ 54 55 if( rc == NO_ERROR ) 56 return (oslCondition)hevCondition; 57 else 58 return NULL; 59 } 60 61 /*****************************************************************************/ 62 /* osl_destroyCondition */ 63 /*****************************************************************************/ 64 void SAL_CALL osl_destroyCondition(oslCondition Condition) 65 { 66 if( Condition ) 67 DosCloseEventSem( (HEV) Condition ); 68 } 69 70 /*****************************************************************************/ 71 /* osl_setCondition */ 72 /*****************************************************************************/ 73 sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) 74 { 75 OSL_ASSERT(Condition); 76 77 return DosPostEventSem((HEV)Condition) == NO_ERROR; 78 } 79 80 /*****************************************************************************/ 81 /* osl_resetCondition */ 82 /*****************************************************************************/ 83 sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition) 84 { 85 ULONG ulPostCount; 86 87 OSL_ASSERT(Condition); 88 89 return DosResetEventSem((HEV)Condition, &ulPostCount) == NO_ERROR; 90 } 91 92 /*****************************************************************************/ 93 /* osl_waitCondition */ 94 /*****************************************************************************/ 95 oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, const TimeValue * pTimeout ) 96 { 97 long nTimeout; 98 APIRET rc; 99 OSL_ASSERT(Condition); 100 101 if( pTimeout ) 102 nTimeout = pTimeout->Seconds * 1000 + pTimeout->Nanosec / 1000000; 103 else 104 nTimeout = SEM_INDEFINITE_WAIT; 105 106 rc = DosWaitEventSem((HEV)Condition, nTimeout ); 107 if( rc == ERROR_TIMEOUT ) 108 return osl_cond_result_timeout; 109 if( rc != NO_ERROR ) 110 return osl_cond_result_error; 111 112 return osl_cond_result_ok; 113 } 114 115 /*****************************************************************************/ 116 /* osl_checkCondition */ 117 /*****************************************************************************/ 118 sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition) 119 { 120 OSL_ASSERT(Condition); 121 122 return( DosWaitEventSem((HEV)Condition, SEM_IMMEDIATE_RETURN) == NO_ERROR); 123 } 124 125