1 /* 2 * Copyright (C) 2014 The Android Open Source Project 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 #include "benchmark.h" 18 19 #include <semaphore.h> 20 BM_semaphore_sem_getvalue(int iters)21static void BM_semaphore_sem_getvalue(int iters) { 22 StopBenchmarkTiming(); 23 sem_t semaphore; 24 sem_init(&semaphore, 1, 1); 25 StartBenchmarkTiming(); 26 27 for (int i = 0; i < iters; ++i) { 28 int dummy; 29 sem_getvalue(&semaphore, &dummy); 30 } 31 32 StopBenchmarkTiming(); 33 } 34 BENCHMARK(BM_semaphore_sem_getvalue); 35 BM_semaphore_sem_wait_sem_post(int iters)36static void BM_semaphore_sem_wait_sem_post(int iters) { 37 StopBenchmarkTiming(); 38 sem_t semaphore; 39 sem_init(&semaphore, 1, 1); 40 StartBenchmarkTiming(); 41 42 for (int i = 0; i < iters; ++i) { 43 sem_wait(&semaphore); 44 sem_post(&semaphore); 45 } 46 47 StopBenchmarkTiming(); 48 } 49 BENCHMARK(BM_semaphore_sem_wait_sem_post); 50