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 <pthread.h> 18 #include <semaphore.h> 19 #include <stdatomic.h> 20 #include <stdio.h> 21 #include <stdlib.h> 22 23 #include <benchmark/benchmark.h> 24 #include "util.h" 25 BM_semaphore_sem_getvalue(benchmark::State & state)26static void BM_semaphore_sem_getvalue(benchmark::State& state) { 27 sem_t semaphore; 28 sem_init(&semaphore, 1, 1); 29 30 while (state.KeepRunning()) { 31 int unused; 32 sem_getvalue(&semaphore, &unused); 33 } 34 } 35 BIONIC_BENCHMARK(BM_semaphore_sem_getvalue); 36 BM_semaphore_sem_wait_sem_post(benchmark::State & state)37static void BM_semaphore_sem_wait_sem_post(benchmark::State& state) { 38 sem_t semaphore; 39 sem_init(&semaphore, 1, 1); 40 41 while (state.KeepRunning()) { 42 sem_wait(&semaphore); 43 sem_post(&semaphore); 44 } 45 } 46 BIONIC_BENCHMARK(BM_semaphore_sem_wait_sem_post); 47