1b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes/*
2b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * Copyright (C) 2014 The Android Open Source Project
3b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes *
4b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * Licensed under the Apache License, Version 2.0 (the "License");
5b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * you may not use this file except in compliance with the License.
6b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * You may obtain a copy of the License at
7b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes *
8b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes *      http://www.apache.org/licenses/LICENSE-2.0
9b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes *
10b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * Unless required by applicable law or agreed to in writing, software
11b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * distributed under the License is distributed on an "AS IS" BASIS,
12b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * See the License for the specific language governing permissions and
14b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes * limitations under the License.
15b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes */
16b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes
17b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes#include "benchmark.h"
18b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes
19b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes#include <semaphore.h>
20b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes
21b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughesstatic void BM_semaphore_sem_getvalue(int iters) {
22b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  StopBenchmarkTiming();
23b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  sem_t semaphore;
24b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  sem_init(&semaphore, 1, 1);
25b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  StartBenchmarkTiming();
26b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes
27b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  for (int i = 0; i < iters; ++i) {
28b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes    int dummy;
29b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes    sem_getvalue(&semaphore, &dummy);
30b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  }
31b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes
32b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  StopBenchmarkTiming();
33b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes}
34b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott HughesBENCHMARK(BM_semaphore_sem_getvalue);
35b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes
36b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughesstatic void BM_semaphore_sem_wait_sem_post(int iters) {
37b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  StopBenchmarkTiming();
38b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  sem_t semaphore;
39b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  sem_init(&semaphore, 1, 1);
40b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  StartBenchmarkTiming();
41b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes
42b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  for (int i = 0; i < iters; ++i) {
43b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes    sem_wait(&semaphore);
44b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes    sem_post(&semaphore);
45b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  }
46b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes
47b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes  StopBenchmarkTiming();
48b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott Hughes}
49b28e490b7350b21c5ae9e5b3bb3e082d8357a1b0Elliott HughesBENCHMARK(BM_semaphore_sem_wait_sem_post);
50