1 /* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 // -*- c++ -*- 19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 20 21 // O S C L _ S E M A P H O R E 22 23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = 24 25 /** 26 * @file oscl_semaphore.h 27 * @brief This file provides implementation of mutex 28 * 29 */ 30 31 // Definition file for OSCL Semaphore 32 #ifndef OSCL_SEMAPHORE_H_INCLUDED 33 #define OSCL_SEMAPHORE_H_INCLUDED 34 35 #ifndef OSCLCONFIG_PROC_H_INCLUDED 36 #include "osclconfig_proc.h" 37 #endif 38 39 #ifndef OSCL_THREAD_H_INCLUDED 40 #include "oscl_thread.h" 41 #endif 42 43 44 /** 45 * Class Semaphore 46 */ 47 class OsclSemaphore 48 { 49 public: 50 51 /** 52 * Class constructor 53 */ 54 OSCL_IMPORT_REF OsclSemaphore(); 55 56 /** 57 * Class destructor 58 */ 59 OSCL_IMPORT_REF ~OsclSemaphore(); 60 61 /** 62 * Creates the Semaphore 63 * 64 * @param Intialcount 65 * 66 * @return Returns the Error whether it is success or failure 67 *incase of failure it will return what is the specific error 68 */ 69 OSCL_IMPORT_REF OsclProcStatus::eOsclProcError Create(uint32 initVal = 0); 70 71 /** 72 * Closes the Semaphore 73 * 74 * @param It wont take any parameters 75 * 76 * @return Returns the Error whether it is success or failure 77 *incase of failure it will return what is the specific error 78 */ 79 OSCL_IMPORT_REF OsclProcStatus::eOsclProcError Close(); 80 81 /** 82 * Makes the thread to wait on the Semaphore 83 * 84 * @param It wont take any parameters 85 * 86 * @return Returns the Error whether it is success or failure 87 *incase of failure it will return what is the specific error 88 */ 89 OSCL_IMPORT_REF OsclProcStatus::eOsclProcError Wait(); 90 91 /** 92 * Makes the thread to wait on the Semaphore, with a timeout. 93 * 94 * @param timeout in milliseconds. 95 * 96 * @return Returns SUCCESS_ERROR if the semaphore was aquired, 97 * WAIT_TIMEOUT_ERROR if the timeout expired without acquiring the 98 * semaphore, or an error code if the operation failed. 99 * Note: this function may not be supported on all platforms, and 100 * may return NOT_IMPLEMENTED. 101 */ 102 OSCL_IMPORT_REF OsclProcStatus::eOsclProcError Wait(uint32 timeout_msec); 103 104 /** 105 * Try to acquire semaphore ,if the semaphore is already acquired by another thread, 106 * calling thread immediately returns with out blocking 107 * 108 * @param It wont take any parameters 109 * 110 * @return Returns SUCCESS_ERROR if the semaphore was acquired, 111 * SEM_LOCKED_ERROR if the semaphore cannot be acquired without waiting, 112 * or an error code if the operation failed. 113 * Note: this function may not be supported on all platforms, and 114 * may return NOT_IMPLEMENTED. 115 */ 116 OSCL_IMPORT_REF OsclProcStatus::eOsclProcError TryWait(); 117 118 /** 119 * Signals that the thread is finished with the Semaphore 120 * 121 * @param It wont take any parameters 122 * 123 * @return Returns the Error whether it is success or failure 124 *incase of failure it will return what is the specific error 125 */ 126 OSCL_IMPORT_REF OsclProcStatus::eOsclProcError Signal(); 127 128 private: 129 130 131 132 bool bCreated; 133 //for pthreads implementations without sem timedwait support. 134 TOsclMutexObject ObjMutex; 135 TOsclConditionObject ObjCondition; 136 uint32 iCount; 137 138 139 }; 140 141 142 143 144 145 #endif // END OF File 146 147