File tree Expand file tree Collapse file tree 3 files changed +32
-17
lines changed Expand file tree Collapse file tree 3 files changed +32
-17
lines changed Original file line number Diff line number Diff line change
1
+ open Bechamel
2
+
3
+ let run () =
4
+ let _ : bool = Sys. opaque_identity (Pool_role. is_master () ) in
5
+ ()
6
+
7
+ let mutex_workload =
8
+ Bechamel_simple_cli. thread_workload ~before: ignore ~after: ignore ~run
9
+
10
+ let benchmarks =
11
+ Test. make_grouped ~name: " Cached reads"
12
+ [Test. make ~name: " Pool_role.is_master" (Staged. stage Pool_role. is_master)]
13
+
14
+ let () = Bechamel_simple_cli. cli ~workloads: [mutex_workload] benchmarks
Original file line number Diff line number Diff line change 1
1
(executables
2
- (names bench_tracing bench_uuid bench_throttle2)
2
+ (names bench_tracing bench_uuid bench_throttle2 bench_cached_reads )
3
3
(libraries tracing bechamel bechamel-notty notty.unix tracing_export threads.posix fmt notty uuid xapi_aux tests_common log xapi_internal)
4
4
)
Original file line number Diff line number Diff line change @@ -28,21 +28,19 @@ type t =
28
28
(* IP address *)
29
29
| Broken
30
30
31
- let role = ref None
31
+ let role = Atomic. make None
32
32
33
- let role_unit_tests = ref false
33
+ let role_unit_tests = Atomic. make false
34
34
35
35
let role_m = Mutex. create ()
36
36
37
37
let with_pool_role_lock f = Xapi_stdext_threads.Threadext.Mutex. execute role_m f
38
38
39
39
let set_pool_role_for_test () =
40
- with_pool_role_lock (fun _ ->
41
- role := Some Master ;
42
- role_unit_tests := true
43
- )
40
+ Atomic. set role (Some Master ) ;
41
+ Atomic. set role_unit_tests true
44
42
45
- let is_unit_test () = with_pool_role_lock ( fun _ -> ! role_unit_tests)
43
+ let is_unit_test () = Atomic. get role_unit_tests
46
44
47
45
let string_of = function
48
46
| Master ->
@@ -80,15 +78,18 @@ let read_pool_role () =
80
78
)
81
79
82
80
let get_role () =
83
- with_pool_role_lock (fun _ ->
84
- match ! role with
85
- | Some x ->
86
- x
87
- | None ->
88
- let r = read_pool_role () in
89
- role := Some r ;
90
- r
91
- )
81
+ match Atomic. get role with
82
+ | Some x ->
83
+ x
84
+ | None ->
85
+ with_pool_role_lock (fun _ ->
86
+ match Atomic. get role with
87
+ | Some x ->
88
+ x
89
+ | None ->
90
+ let r = read_pool_role () in
91
+ Atomic. set role (Some r) ; r
92
+ )
92
93
93
94
let is_master () = get_role () = Master
94
95
You can’t perform that action at this time.
0 commit comments