@@ -6,9 +6,10 @@ use crate::report::{AtomicOperation, AtomicReport, AtomicViolation, ViolationPat
66use petgraph:: graph:: NodeIndex ;
77use petgraph:: visit:: EdgeRef ;
88use petgraph:: { Direction , Graph } ;
9+ use std:: cell:: RefCell ;
910use std:: collections:: { HashMap , HashSet } ;
10- use std:: sync :: { Arc , Mutex , RwLock } ;
11- use std:: thread ;
11+ use std:: rc :: Rc ;
12+ use std:: sync :: { Arc , RwLock } ;
1213use std:: time:: Instant ;
1314
1415pub struct AtomicityViolationDetector < ' a > {
@@ -37,10 +38,10 @@ impl<'a> AtomicityViolationDetector<'a> {
3738
3839 // 2. 将图结构包装在 Arc<RwLock> 中
3940 let graph = Arc :: new ( RwLock :: new ( self . state_graph . graph . clone ( ) ) ) ;
40- let initial_net = Arc :: new ( RwLock :: new ( self . state_graph . initial_net . as_ref ( ) . clone ( ) ) ) ;
4141
4242 // 3. 并行检查违背
43- let violations = self . check_violations ( loads, stores, & graph, & initial_net) ;
43+ let violations =
44+ self . check_violations ( loads, stores, & graph, self . state_graph . initial_net . clone ( ) ) ;
4445
4546 if !violations. is_empty ( ) {
4647 report. has_violation = true ;
@@ -84,8 +85,10 @@ impl<'a> AtomicityViolationDetector<'a> {
8485 let mut loads = HashMap :: new ( ) ;
8586 let mut stores = HashMap :: new ( ) ;
8687
87- for node_idx in self . state_graph . initial_net . node_indices ( ) {
88- if let Some ( PetriNetNode :: T ( t) ) = self . state_graph . initial_net . node_weight ( node_idx) {
88+ for node_idx in self . state_graph . initial_net . borrow ( ) . node_indices ( ) {
89+ if let Some ( PetriNetNode :: T ( t) ) =
90+ self . state_graph . initial_net . borrow ( ) . node_weight ( node_idx)
91+ {
8992 match & t. transition_type {
9093 ControlType :: Call ( CallType :: AtomicLoad ( var_id, ordering, span, thread_id) ) => {
9194 if format ! ( "{:?}" , ordering) == "Relaxed" {
@@ -123,50 +126,33 @@ impl<'a> AtomicityViolationDetector<'a> {
123126 loads : HashMap < NodeIndex , AtomicOp > ,
124127 stores : HashMap < NodeIndex , AtomicOp > ,
125128 graph : & Arc < RwLock < Graph < StateNode , StateEdge > > > ,
126- initial_net : & Arc < RwLock < Graph < PetriNetNode , PetriNetEdge > > > ,
129+ initial_net : Rc < RefCell < Graph < PetriNetNode , PetriNetEdge > > > ,
127130 ) -> Vec < ViolationPattern > {
128- let all_violations = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
129- let mut handles = vec ! [ ] ;
131+ let mut all_violations = Vec :: new ( ) ;
132+ let graph = graph. read ( ) . unwrap ( ) ;
133+ let initial_net = initial_net. borrow ( ) ;
130134
131135 for ( load_trans, load_op) in loads {
132- let all_violations = Arc :: clone ( & all_violations) ;
133- let stores = stores. clone ( ) ;
134- let graph = Arc :: clone ( graph) ;
135- let initial_net = Arc :: clone ( initial_net) ;
136- unsafe {
137- let handle = thread:: spawn ( move || {
138- let graph = graph. read ( ) . unwrap ( ) ;
139- for state in graph. node_indices ( ) {
140- for edge in graph. edges_directed ( state, Direction :: Outgoing ) {
141- if edge. weight ( ) . transition == load_trans {
142- if let Some ( violation) = Self :: check_state_for_violation (
143- & graph,
144- & initial_net. read ( ) . unwrap ( ) ,
145- state,
146- & load_op,
147- & stores,
148- ) {
149- all_violations. lock ( ) . unwrap ( ) . push ( violation) ;
150- }
151- }
136+ for state in graph. node_indices ( ) {
137+ for edge in graph. edges_directed ( state, Direction :: Outgoing ) {
138+ if edge. weight ( ) . transition == load_trans {
139+ if let Some ( violation) = Self :: check_state_for_violation (
140+ & graph,
141+ & initial_net,
142+ state,
143+ & load_op,
144+ & stores,
145+ ) {
146+ all_violations. push ( violation) ;
152147 }
153148 }
154- } ) ;
155- handles. push ( handle) ;
149+ }
156150 }
157151 }
158152
159- for handle in handles {
160- handle. join ( ) . unwrap ( ) ;
161- }
162-
163- let violations = Arc :: try_unwrap ( all_violations)
164- . unwrap ( )
165- . into_inner ( )
166- . unwrap ( ) ;
167153 let mut pattern_map: HashMap < ViolationPattern , Vec < Vec < ( usize , u8 ) > > > = HashMap :: new ( ) ;
168154
169- for violation in violations {
155+ for violation in all_violations {
170156 let pattern = ViolationPattern {
171157 load_op : AtomicOperation {
172158 operation_type : "load" . to_string ( ) ,
0 commit comments