1.1 --- a/dstest_test_client.cc Tue Feb 23 23:22:41 2021 +0100
1.2 +++ b/dstest_test_client.cc Sat Feb 27 00:04:27 2021 +0100
1.3 @@ -210,58 +210,38 @@
1.4
1.5
1.6
1.7 -static long activity_for_file(unsigned long fileid)
1.8 -{
1.9 - std::thread *activities[START_LIMIT];
1.10 -
1.11 - l4_cap_idx_t context_ref;
1.12 - char *filename;
1.13 - int current = 0;
1.14 -
1.15 - long err = context_for_file(fileid, &context_ref, &filename);
1.16 -
1.17 - if (err)
1.18 - return err;
1.19 -
1.20 - for (unsigned int start_page = 0; start_page < START_LIMIT; start_page++)
1.21 - activities[current++] = new std::thread(activity_iterate, context_ref, fileid, start_page);
1.22 -
1.23 - /* Wait for the threads. */
1.24 -
1.25 - int limit = current;
1.26 -
1.27 - printf("Waiting for %d threads for %ld...\n", limit, fileid);
1.28 -
1.29 - for (current = 0; current < limit; current++)
1.30 - {
1.31 - activities[current]->join();
1.32 - printf("End: %ld @ %d\n", fileid, current);
1.33 - }
1.34 -
1.35 - /* Discard the context. */
1.36 -
1.37 - ipc_cap_free_um(context_ref);
1.38 - ipc_detach_dataspace(filename);
1.39 -
1.40 - printf("End: %ld\n", fileid);
1.41 - return L4_EOK;
1.42 -}
1.43 -
1.44 -
1.45 -
1.46 int main(void)
1.47 {
1.48 /* Introduce concurrency control. */
1.49
1.50 ipc_cap_alloc_init();
1.51
1.52 - std::thread *activities[NUMBER_OF_FILES];
1.53 + std::thread *activities[NUMBER_OF_FILES * START_LIMIT];
1.54 + l4_cap_idx_t context_refs[NUMBER_OF_FILES];
1.55 + char *filenames[NUMBER_OF_FILES];
1.56 +
1.57 + /* Obtain opener contexts for the files. */
1.58
1.59 unsigned long fileid;
1.60 +
1.61 + for (fileid = 0; fileid < NUMBER_OF_FILES; fileid++)
1.62 + {
1.63 + long err = context_for_file(fileid, &context_refs[fileid], &filenames[fileid]);
1.64 +
1.65 + if (err)
1.66 + {
1.67 + printf("Context allocation failed.\n");
1.68 + return 1;
1.69 + }
1.70 + }
1.71 +
1.72 + /* Start threads accessing all the files. */
1.73 +
1.74 int current = 0;
1.75
1.76 for (fileid = 0; fileid < NUMBER_OF_FILES; fileid++)
1.77 - activities[current++] = new std::thread(activity_for_file, fileid);
1.78 + for (unsigned int start_page = 0; start_page < START_LIMIT; start_page++)
1.79 + activities[current++] = new std::thread(activity_iterate, context_refs[fileid], fileid, start_page);
1.80
1.81 /* Wait for the threads. */
1.82
1.83 @@ -270,9 +250,14 @@
1.84 printf("Waiting for %d threads...\n", limit);
1.85
1.86 for (current = 0; current < limit; current++)
1.87 + activities[current]->join();
1.88 +
1.89 + /* Discard the contexts. */
1.90 +
1.91 + for (fileid = 0; fileid < NUMBER_OF_FILES; fileid++)
1.92 {
1.93 - activities[current]->join();
1.94 - printf("Ended: %d\n", current);
1.95 + ipc_cap_free_um(context_refs[fileid]);
1.96 + ipc_detach_dataspace(filenames[fileid]);
1.97 }
1.98
1.99 printf("Activities completed.\n");