| 1047 | } |
| 1048 | |
| 1049 | void *load_threads(void *ptr) |
| 1050 | { |
| 1051 | int i; |
| 1052 | load_args args = *(load_args *)ptr; |
| 1053 | if (args.threads == 0) args.threads = 1; |
| 1054 | data *out = args.d; |
| 1055 | int total = args.n; |
| 1056 | free(ptr); |
| 1057 | data *buffers = calloc(args.threads, sizeof(data)); |
| 1058 | pthread_t *threads = calloc(args.threads, sizeof(pthread_t)); |
| 1059 | for(i = 0; i < args.threads; ++i){ |
| 1060 | args.d = buffers + i; |
| 1061 | args.n = (i+1) * total/args.threads - i * total/args.threads; |
| 1062 | threads[i] = load_data_in_thread(args); |
| 1063 | } |
| 1064 | for(i = 0; i < args.threads; ++i){ |
| 1065 | pthread_join(threads[i], 0); |
| 1066 | } |
| 1067 | *out = concat_datas(buffers, args.threads); |
| 1068 | out->shallow = 0; |
| 1069 | for(i = 0; i < args.threads; ++i){ |
| 1070 | buffers[i].shallow = 1; |
| 1071 | free_data(buffers[i]); |
| 1072 | } |
| 1073 | free(buffers); |
| 1074 | free(threads); |
| 1075 | return 0; |
| 1076 | } |
| 1077 | |
| 1078 | void load_data_blocking(load_args args) |
| 1079 | { |
nothing calls this directly
no test coverage detected