diff options
author | Elliott Hughes <enh@google.com> | 2015-01-20 18:09:05 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-01-21 10:33:30 -0800 |
commit | 8c4994bbc1a9a01e34ea92c91eb5b2d1a27bd074 (patch) | |
tree | 8b632cea0832373b9cb843427bb5976b3668f1a2 /benchmarks | |
parent | f374358414812d3e5a45ba75a2b1926693924420 (diff) | |
download | bionic-8c4994bbc1a9a01e34ea92c91eb5b2d1a27bd074.zip bionic-8c4994bbc1a9a01e34ea92c91eb5b2d1a27bd074.tar.gz bionic-8c4994bbc1a9a01e34ea92c91eb5b2d1a27bd074.tar.bz2 |
Implement __fsetlocking.
The old __isthreaded hack was never very useful on Android because all user
code runs in a VM where there are lots of threads running. But __fsetlocking
lets a caller say "I'll worry about the locking for this FILE*", which is
useful for the normal case where you don't share a FILE* between threads
so you don't need any locking.
Bug: 17154740
Bug: 18593728
Change-Id: I2a8dddc29d3edff39a3d7d793387f2253608a68d
Diffstat (limited to 'benchmarks')
-rw-r--r-- | benchmarks/stdio_benchmark.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp index fe25d76..5658a50 100644 --- a/benchmarks/stdio_benchmark.cpp +++ b/benchmarks/stdio_benchmark.cpp @@ -17,6 +17,7 @@ #include "benchmark.h" #include <stdio.h> +#include <stdio_ext.h> #define KB 1024 #define MB 1024*KB @@ -29,6 +30,7 @@ template <typename Fn> static void ReadWriteTest(int iters, int chunk_size, Fn f, bool buffered) { StopBenchmarkTiming(); FILE* fp = fopen("/dev/zero", "rw"); + __fsetlocking(fp, FSETLOCKING_BYCALLER); char* buf = new char[chunk_size]; StartBenchmarkTiming(); @@ -66,12 +68,22 @@ static void BM_stdio_fwrite_unbuffered(int iters, int chunk_size) { } BENCHMARK(BM_stdio_fwrite_unbuffered)->AT_COMMON_SIZES; -static void BM_stdio_fopen_fgets_fclose(int iters) { +static void FopenFgetsFclose(int iters, bool no_locking) { char buf[1024]; for (int i = 0; i < iters; ++i) { FILE* fp = fopen("/proc/version", "re"); + if (no_locking) __fsetlocking(fp, FSETLOCKING_BYCALLER); fgets(buf, sizeof(buf), fp); fclose(fp); } } -BENCHMARK(BM_stdio_fopen_fgets_fclose); + +static void BM_stdio_fopen_fgets_fclose_locking(int iters) { + FopenFgetsFclose(iters, false); +} +BENCHMARK(BM_stdio_fopen_fgets_fclose_locking); + +static void BM_stdio_fopen_fgets_fclose_no_locking(int iters) { + FopenFgetsFclose(iters, true); +} +BENCHMARK(BM_stdio_fopen_fgets_fclose_no_locking); |