cgen: fix for `rlock`/`lock` handling (#8536)
							parent
							
								
									de37b52d4b
								
							
						
					
					
						commit
						2424e2cb02
					
				|  | @ -3420,13 +3420,24 @@ fn (mut g Gen) lock_expr(node ast.LockExpr) { | |||
| 		mtxs = g.new_tmp_var() | ||||
| 		g.writeln('uintptr_t _arr_$mtxs[$node.lockeds.len];') | ||||
| 		g.writeln('bool _isrlck_$mtxs[$node.lockeds.len];') | ||||
| 		mut j := 0 | ||||
| 		for i, id in node.lockeds { | ||||
| 			name := id.name | ||||
| 			deref := if id.is_mut { '->' } else { '.' } | ||||
| 			g.writeln('_arr_$mtxs[$i] = &$name${deref}mtx;') | ||||
| 			// TODO: fix `vfmt` to allow this in string interpolation
 | ||||
| 			is_rlock_str := node.is_rlock[i].str() | ||||
| 			g.writeln('_isrlck_$mtxs[$i] = $is_rlock_str;') | ||||
| 			if !node.is_rlock[i] { | ||||
| 				name := id.name | ||||
| 				deref := if id.is_mut { '->' } else { '.' } | ||||
| 				g.writeln('_arr_$mtxs[$j] = &$name${deref}mtx;') | ||||
| 				g.writeln('_isrlck_$mtxs[$j] = false;') | ||||
| 				j++ | ||||
| 			} | ||||
| 		} | ||||
| 		for i, id in node.lockeds { | ||||
| 			if node.is_rlock[i] { | ||||
| 				name := id.name | ||||
| 				deref := if id.is_mut { '->' } else { '.' } | ||||
| 				g.writeln('_arr_$mtxs[$j] = &$name${deref}mtx;') | ||||
| 				g.writeln('_isrlck_$mtxs[$j] = true;') | ||||
| 				j++ | ||||
| 			} | ||||
| 		} | ||||
| 		g.writeln('__sort_ptr(_arr_$mtxs, _isrlck_$mtxs, $node.lockeds.len);') | ||||
| 		g.writeln('for (int $mtxs=0; $mtxs<$node.lockeds.len; $mtxs++) {') | ||||
|  |  | |||
|  | @ -37,7 +37,7 @@ static inline void __sort_ptr(uintptr_t a[], bool b[], int l) | |||
| 		uintptr_t ins = a[i]; | ||||
| 		bool insb = b[i]; | ||||
| 		int j = i; | ||||
| 		while(j>0 && (a[j-1] > ins || b[j-1] && !insb)) { | ||||
| 		while(j>0 && a[j-1] > ins) { | ||||
| 			a[j] = a[j-1]; | ||||
| 			b[j] = b[j-1]; | ||||
| 			j--; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue