cgen: format shared structs (#12062)
							parent
							
								
									03269f9854
								
							
						
					
					
						commit
						e94e08475d
					
				|  | @ -877,7 +877,10 @@ fn (mut g Gen) write_shareds() { | |||
| 		done_types << typ | ||||
| 		sh_typ := '__shared__$base' | ||||
| 		mtx_typ := 'sync__RwMutex' | ||||
| 		g.shared_types.writeln('struct $sh_typ { $mtx_typ mtx; $base val; };') | ||||
| 		g.shared_types.writeln('struct $sh_typ {') | ||||
| 		g.shared_types.writeln('\t$mtx_typ mtx;') | ||||
| 		g.shared_types.writeln('\t$base val;') | ||||
| 		g.shared_types.writeln('};') | ||||
| 		g.shared_functions.writeln('static inline voidptr __dup${sh_typ}(voidptr src, int sz) {') | ||||
| 		g.shared_functions.writeln('\t$sh_typ* dest = memdup(src, sz);') | ||||
| 		g.shared_functions.writeln('\tsync__RwMutex_init(&dest->mtx);') | ||||
|  |  | |||
|  | @ -23,14 +23,20 @@ const c_current_commit_hash_default = ' | |||
| 
 | ||||
| const c_concurrency_helpers = ' | ||||
| typedef struct __shared_map __shared_map; | ||||
| struct __shared_map { sync__RwMutex mtx; map val; }; | ||||
| struct __shared_map { | ||||
| 	sync__RwMutex mtx; | ||||
| 	map val; | ||||
| }; | ||||
| static inline voidptr __dup_shared_map(voidptr src, int sz) { | ||||
| 	__shared_map* dest = memdup(src, sz); | ||||
| 	sync__RwMutex_init(&dest->mtx); | ||||
| 	return dest; | ||||
| } | ||||
| typedef struct __shared_array __shared_array; | ||||
| struct __shared_array { sync__RwMutex mtx; array val; }; | ||||
| struct __shared_array { | ||||
| 	sync__RwMutex mtx; | ||||
| 	array val; | ||||
| }; | ||||
| static inline voidptr __dup_shared_array(voidptr src, int sz) { | ||||
| 	__shared_array* dest = memdup(src, sz); | ||||
| 	sync__RwMutex_init(&dest->mtx); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue