Home | History | Annotate | Download | only in libtiutils
      1 /*
      2  * Copyright (C) Texas Instruments - http://www.ti.com/
      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 express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 
     18 
     19 #include <utils/Errors.h>
     20 #include <semaphore.h>
     21 #include <stdio.h>
     22 #include <stdarg.h>
     23 #include <stdlib.h>
     24 #include <string.h>
     25 #include <unistd.h>
     26 
     27 #include "Status.h"
     28 
     29 namespace Ti {
     30 namespace Utils {
     31 
     32 class Semaphore
     33 {
     34 public:
     35 
     36     Semaphore();
     37     ~Semaphore();
     38 
     39     //Release semaphore
     40     status_t Release();
     41 
     42     ///Create the semaphore with initial count value
     43     status_t Create(int count=0);
     44 
     45     ///Wait operation
     46     status_t Wait();
     47 
     48     ///Signal operation
     49     status_t Signal();
     50 
     51     ///Current semaphore count
     52     int Count();
     53 
     54     ///Wait operation with a timeout
     55     status_t WaitTimeout(int timeoutMicroSecs);
     56 
     57 private:
     58     sem_t *mSemaphore;
     59 
     60 };
     61 
     62 } // namespace Utils
     63 } // namespace Ti
     64