1 |
joko |
1.1 |
/* Betriebssystem & Middleware |
2 |
|
|
* |
3 |
|
|
* Betriebssystemarchitektur SS 2006 |
4 |
|
|
* |
5 |
|
|
* Uebung 4.4 |
6 |
|
|
*/ |
7 |
joko |
1.3 |
|
8 |
joko |
1.13 |
// $Id: bmp_fractal.c,v 1.12 2006/07/02 09:27:14 joko Exp $ |
9 |
joko |
1.3 |
|
10 |
|
|
#include <windows.h> |
11 |
joko |
1.1 |
#include <stdio.h> |
12 |
|
|
#include <errno.h> |
13 |
|
|
|
14 |
|
|
#define XSIZE 500 |
15 |
|
|
#define YSIZE 500 |
16 |
|
|
#include "algorithm.h" |
17 |
|
|
|
18 |
joko |
1.11 |
BOOL VERBOSE = FALSE; |
19 |
joko |
1.9 |
|
20 |
joko |
1.3 |
|
21 |
joko |
1.2 |
/* BMP Header */ |
22 |
joko |
1.1 |
unsigned char header[54]={0x42,0x4d, // signature BM |
23 |
|
|
0xe6,0x71,0x0b,0x0, // filesize 750054 |
24 |
|
|
0x0,0x0,0x0,0x0, // reserved |
25 |
|
|
0x36,0x0,0x0,0x0, // image offset 54 |
26 |
|
|
0x28,0x0,0x0,0x0, // size of header follows 40 |
27 |
|
|
0xf4,0x1,0x0,0x0, // with of image 500 |
28 |
|
|
0xf4,0x1,0x0,0x0, // height of image 500 |
29 |
|
|
0x1,0x0, // number of planes 1 |
30 |
|
|
0x18,0x0, // number of pixel 24 |
31 |
|
|
0x0,0x0,0x0,0x0, // compression |
32 |
|
|
0xb0,0x71,0x0b,0x0, // size of image 750000 |
33 |
|
|
0x0,0x0,0x0,0x0, // xres |
34 |
|
|
0x0,0x0,0x0,0x0, // yres |
35 |
|
|
0x0,0x0,0x0,0x0, // number of colortables |
36 |
|
|
0x0,0x0,0x0,0x0 // number of important colors |
37 |
|
|
}; |
38 |
|
|
|
39 |
joko |
1.3 |
|
40 |
|
|
void printErrorAndExit(const char *msg, DWORD err) { |
41 |
|
|
LPSTR lpMsgBuf; |
42 |
|
|
if(FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER| |
43 |
|
|
FORMAT_MESSAGE_FROM_SYSTEM | |
44 |
|
|
FORMAT_MESSAGE_IGNORE_INSERTS, |
45 |
|
|
NULL, |
46 |
|
|
err, |
47 |
|
|
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language |
48 |
|
|
(LPTSTR) &lpMsgBuf, |
49 |
|
|
0, |
50 |
|
|
NULL )) |
51 |
|
|
{ |
52 |
joko |
1.11 |
fprintf(stdout, "%s: %s\n", msg, lpMsgBuf); |
53 |
joko |
1.3 |
LocalFree(lpMsgBuf); |
54 |
|
|
} |
55 |
|
|
else |
56 |
|
|
{ |
57 |
joko |
1.11 |
fprintf(stdout, "Error at FormatMesage: %d\n",err=GetLastError()); |
58 |
joko |
1.3 |
} |
59 |
|
|
exit(err); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
|
63 |
|
|
void write_blank_file(char *filename) { |
64 |
|
|
|
65 |
|
|
FILE *fd; |
66 |
|
|
int len, i, img_size; |
67 |
|
|
|
68 |
|
|
// open file handle |
69 |
|
|
fd = fopen(filename, "wb+"); |
70 |
|
|
if (NULL == fd) { |
71 |
|
|
perror("open"); |
72 |
|
|
exit(1); |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
// write bmp header to file |
76 |
|
|
len = fwrite(header, 1, sizeof(header), fd); |
77 |
|
|
|
78 |
|
|
// error checking |
79 |
|
|
if (-1 == len || len != sizeof(header)) { |
80 |
|
|
perror("write"); |
81 |
|
|
exit(2); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
// write three null-bytes for each pixel to file to create a black picture |
85 |
|
|
img_size = XSIZE * YSIZE; |
86 |
|
|
for (i = 0; i < img_size; i++) { |
87 |
|
|
len = fwrite("\0\0\0", 1, 3, fd); |
88 |
|
|
if (-1 == len || len != 3) { |
89 |
|
|
perror("write"); |
90 |
|
|
exit(4); |
91 |
joko |
1.1 |
} |
92 |
joko |
1.3 |
} |
93 |
|
|
|
94 |
|
|
// close file handle |
95 |
|
|
fclose(fd); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
|
99 |
joko |
1.6 |
// arguments for each thread |
100 |
|
|
typedef struct _WorkerArguments { |
101 |
joko |
1.7 |
int start_row; |
102 |
|
|
int number_of_rows; |
103 |
joko |
1.6 |
unsigned char * pBitmap; |
104 |
|
|
} WORKERARGS, *PWORKERARGS; |
105 |
|
|
|
106 |
|
|
// worker thread - main entry function |
107 |
joko |
1.10 |
DWORD WINAPI fractal_create_segment (LPVOID lpParam) { |
108 |
joko |
1.6 |
|
109 |
|
|
// thread stuff |
110 |
|
|
int thread_id; |
111 |
|
|
PWORKERARGS args; |
112 |
joko |
1.7 |
unsigned char *pDataBitmapSegment; |
113 |
joko |
1.6 |
|
114 |
|
|
// fractal calculation |
115 |
|
|
int x, y; |
116 |
|
|
char bgr[3]; |
117 |
|
|
|
118 |
|
|
thread_id = GetCurrentThreadId(); |
119 |
|
|
|
120 |
|
|
// get worker arguments |
121 |
|
|
args = (PWORKERARGS)lpParam; |
122 |
joko |
1.7 |
|
123 |
|
|
// calculate pointer to beginning of segment |
124 |
|
|
pDataBitmapSegment = (unsigned char *)((INT_PTR)args->pBitmap + (YSIZE - (args->start_row + args->number_of_rows)) * 3 * XSIZE); |
125 |
joko |
1.9 |
|
126 |
|
|
// debugging |
127 |
|
|
if (VERBOSE) { |
128 |
joko |
1.11 |
fprintf(stdout, "----------------------------------------------\n"); |
129 |
|
|
fprintf(stdout, "thread_id: %i\n", thread_id); |
130 |
|
|
fprintf(stdout, "arg.start_row: %i\n", args->start_row); |
131 |
|
|
fprintf(stdout, "arg.number_of_rows: %i\n", args->number_of_rows); |
132 |
|
|
fprintf(stdout, "segment_start: %p\n", pDataBitmapSegment); |
133 |
joko |
1.9 |
} |
134 |
joko |
1.6 |
|
135 |
|
|
// calculate fractal |
136 |
|
|
for (y = (args->start_row + args->number_of_rows) - 1; y >= args->start_row; y--) { |
137 |
joko |
1.11 |
//fprintf(stdout, "calc: thread=%i; y=%i limits: %i,%i p: %p\n", thread_id, y, args->start_row, args->number_of_rows, pDataBitmapSegment); |
138 |
joko |
1.6 |
for (x = 0; x < XSIZE; x++) { |
139 |
|
|
getColorValuesAt(x * (2.0 / XSIZE) - 1.5, y * (2.0 / YSIZE) - 1.0, &bgr[2], &bgr[1], &bgr[0]); |
140 |
|
|
|
141 |
|
|
// transfer color values to current pixel |
142 |
joko |
1.7 |
pDataBitmapSegment[0] = bgr[0]; |
143 |
|
|
pDataBitmapSegment[1] = bgr[1]; |
144 |
|
|
pDataBitmapSegment[2] = bgr[2]; |
145 |
joko |
1.6 |
|
146 |
|
|
// move pointer to next pixel |
147 |
joko |
1.7 |
pDataBitmapSegment += 3; |
148 |
joko |
1.6 |
|
149 |
|
|
} |
150 |
joko |
1.9 |
//no padding required because 1500%4 =0 ??? |
151 |
joko |
1.6 |
} |
152 |
|
|
|
153 |
joko |
1.9 |
if (VERBOSE) |
154 |
joko |
1.11 |
fprintf(stdout, "thread finished: %i\n", thread_id); |
155 |
joko |
1.6 |
return 0; |
156 |
|
|
|
157 |
|
|
} |
158 |
|
|
|
159 |
joko |
1.13 |
BOOL scan_argv(int argc, char *argv[], char opt_name[], char *opt_value[]) { |
160 |
|
|
int i; |
161 |
|
|
char * opt_current_name; |
162 |
|
|
char * opt_current_value; |
163 |
|
|
|
164 |
|
|
//printf("searching for: '%s'\n", opt_name); |
165 |
|
|
|
166 |
|
|
for (i = 1; i < argc; i++) { |
167 |
|
|
opt_current_name = argv[i]; |
168 |
|
|
if (strcmp(opt_current_name, opt_name) == 0) { |
169 |
|
|
//printf("opt: %s\n", opt_current_name); |
170 |
|
|
opt_current_value = argv[i+1]; |
171 |
|
|
//printf("opt-current-value: %s\n", opt_current_value); |
172 |
|
|
if (opt_current_value != NULL) { |
173 |
|
|
//*opt_value = *argv[i+1]; |
174 |
|
|
*opt_value = *opt_current_value; |
175 |
|
|
//printf("opt-value: %s\n", opt_value); |
176 |
|
|
} |
177 |
|
|
return TRUE; |
178 |
|
|
} |
179 |
|
|
} |
180 |
|
|
return FALSE; |
181 |
|
|
} |
182 |
|
|
|
183 |
joko |
1.6 |
|
184 |
joko |
1.3 |
int main(int argc, char *argv[]) { |
185 |
|
|
|
186 |
joko |
1.4 |
// MMF support |
187 |
|
|
DWORD err; |
188 |
joko |
1.3 |
HANDLE hMap, hFile; |
189 |
|
|
LPVOID pData; |
190 |
joko |
1.9 |
unsigned char *pDataBitmap; |
191 |
joko |
1.4 |
|
192 |
joko |
1.5 |
// workers |
193 |
joko |
1.10 |
int workers = 5; |
194 |
joko |
1.7 |
int worker_index, worker_rows, worker_startrow; |
195 |
joko |
1.6 |
HANDLE *worker_handles; |
196 |
|
|
PWORKERARGS worker_args; |
197 |
|
|
|
198 |
joko |
1.10 |
// threads or processes? |
199 |
joko |
1.13 |
BOOL use_processes = FALSE; |
200 |
joko |
1.12 |
BOOL is_worker_process = FALSE; |
201 |
joko |
1.10 |
|
202 |
|
|
// information for creating processes |
203 |
|
|
STARTUPINFO si; |
204 |
|
|
PROCESS_INFORMATION pi; |
205 |
joko |
1.13 |
char szCmdline[65536]; |
206 |
joko |
1.10 |
|
207 |
joko |
1.13 |
// command line stuff |
208 |
|
|
char arg_option[1024]; |
209 |
|
|
char *arg_value[1024]; |
210 |
|
|
//arg_value = malloc(1024); |
211 |
joko |
1.10 |
|
212 |
joko |
1.13 |
VERBOSE = FALSE; |
213 |
joko |
1.11 |
|
214 |
joko |
1.10 |
// "parse" command line arguments |
215 |
joko |
1.13 |
/* |
216 |
joko |
1.10 |
if (argc >= 2) { |
217 |
joko |
1.11 |
if (strcmp(argv[1], "--worker") == 0) { |
218 |
joko |
1.12 |
is_worker_process = TRUE; |
219 |
joko |
1.11 |
} |
220 |
joko |
1.10 |
} |
221 |
joko |
1.13 |
*/ |
222 |
|
|
|
223 |
|
|
//scan_argv(argc, argv, "--worker", &arg_value); |
224 |
|
|
//*arg_value = '\0'; |
225 |
|
|
// parse command line arguments |
226 |
|
|
if (scan_argv(argc, argv, "--worker", arg_value)) { |
227 |
|
|
use_processes = TRUE; |
228 |
|
|
is_worker_process = TRUE; |
229 |
|
|
|
230 |
|
|
} else if (scan_argv(argc, argv, "-p", arg_value)) { |
231 |
|
|
use_processes = TRUE; |
232 |
|
|
is_worker_process = FALSE; |
233 |
|
|
workers = atoi(arg_value); |
234 |
|
|
|
235 |
|
|
} else if (scan_argv(argc, argv, "-t", arg_value)) { |
236 |
|
|
use_processes = FALSE; |
237 |
|
|
is_worker_process = FALSE; |
238 |
|
|
workers = atoi(arg_value); |
239 |
|
|
|
240 |
|
|
} |
241 |
|
|
//printf("value: %s\n", arg_value); |
242 |
|
|
//exit(0); |
243 |
|
|
|
244 |
joko |
1.10 |
|
245 |
joko |
1.11 |
if (VERBOSE && use_processes) { |
246 |
|
|
fprintf(stdout, "===================================================== "); |
247 |
joko |
1.12 |
if (is_worker_process) |
248 |
joko |
1.11 |
fprintf(stdout, "WORKER-PROCESS\n"); |
249 |
|
|
else |
250 |
|
|
fprintf(stdout, "MASTER-PROCESS\n"); |
251 |
joko |
1.10 |
} |
252 |
joko |
1.3 |
|
253 |
joko |
1.4 |
// create empty bmp-file (black background) |
254 |
joko |
1.12 |
if (!is_worker_process) |
255 |
joko |
1.10 |
write_blank_file("test.bmp"); |
256 |
joko |
1.3 |
|
257 |
joko |
1.12 |
// master creates memory mapped file |
258 |
|
|
if (!is_worker_process) { |
259 |
joko |
1.10 |
|
260 |
joko |
1.12 |
// open file for reading and writing |
261 |
joko |
1.10 |
hFile = CreateFile("test.bmp", GENERIC_WRITE|GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); |
262 |
|
|
if (INVALID_HANDLE_VALUE == hFile) { |
263 |
|
|
err = GetLastError(); |
264 |
|
|
printErrorAndExit("Error at CreateFile",err); |
265 |
|
|
} |
266 |
joko |
1.3 |
|
267 |
joko |
1.12 |
// create the file mapping object |
268 |
joko |
1.10 |
hMap = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, "bmp_fractal"); |
269 |
|
|
if (NULL == hMap) { |
270 |
|
|
printErrorAndExit("Error at CreateFileMapping", GetLastError()); |
271 |
|
|
} |
272 |
joko |
1.12 |
|
273 |
|
|
// worker uses existing memory mapped file |
274 |
joko |
1.10 |
} else { |
275 |
|
|
|
276 |
|
|
// open existing mapping object |
277 |
|
|
hMap = OpenFileMapping(FILE_MAP_WRITE, FALSE, "bmp_fractal"); |
278 |
|
|
if (NULL == hMap) |
279 |
|
|
printErrorAndExit("Error at OpenFileMapping", GetLastError()); |
280 |
joko |
1.3 |
} |
281 |
|
|
|
282 |
joko |
1.12 |
// map the whole file into the process context |
283 |
joko |
1.3 |
pData = MapViewOfFile(hMap, FILE_MAP_WRITE, 0, 0, 0); |
284 |
|
|
if (NULL == pData) { |
285 |
|
|
printErrorAndExit("Error at MapViewOfFile", GetLastError()); |
286 |
|
|
} |
287 |
|
|
|
288 |
|
|
|
289 |
|
|
// calculate pointer to beginning of bitmap |
290 |
|
|
pDataBitmap = (unsigned char *)((INT_PTR)pData + sizeof(header)); |
291 |
|
|
|
292 |
|
|
// debugging |
293 |
joko |
1.9 |
if (VERBOSE) { |
294 |
joko |
1.11 |
fprintf(stdout, "pos. of file: %p\n", pData); |
295 |
|
|
fprintf(stdout, "pos. of bitmap: %p\n", pDataBitmap); |
296 |
joko |
1.9 |
} |
297 |
joko |
1.3 |
|
298 |
joko |
1.10 |
|
299 |
joko |
1.12 |
if (use_processes && is_worker_process) { |
300 |
joko |
1.10 |
|
301 |
|
|
if (VERBOSE) |
302 |
joko |
1.11 |
fprintf(stdout, "inside worker-process\n"); |
303 |
joko |
1.10 |
|
304 |
joko |
1.11 |
// get segment information from command line |
305 |
joko |
1.10 |
worker_startrow = atoi(argv[2]); |
306 |
|
|
worker_rows = atoi(argv[3]); |
307 |
|
|
|
308 |
|
|
// allocate memory for one worker's arguments |
309 |
|
|
if ((worker_args = malloc(sizeof(worker_args[0]))) == NULL) |
310 |
|
|
perror("malloc"), exit(1); |
311 |
|
|
|
312 |
|
|
// assign worker's arguments |
313 |
|
|
worker_args[0].start_row = worker_startrow; |
314 |
|
|
worker_args[0].number_of_rows = worker_rows; |
315 |
|
|
worker_args[0].pBitmap = pDataBitmap; |
316 |
|
|
|
317 |
|
|
fractal_create_segment(&worker_args[0]); |
318 |
joko |
1.12 |
|
319 |
|
|
// cleanup mmap-handle |
320 |
|
|
if (!CloseHandle(hMap)) |
321 |
|
|
printErrorAndExit("Error at CloseHandle", GetLastError()); |
322 |
joko |
1.10 |
|
323 |
joko |
1.13 |
return 0; |
324 |
joko |
1.10 |
} |
325 |
|
|
|
326 |
joko |
1.3 |
/* |
327 |
joko |
1.9 |
// turn bitmap into white canvas |
328 |
joko |
1.3 |
for (offset = 0; offset < 500 * 500 * 3; offset++) { |
329 |
joko |
1.9 |
*pDataBitmap = 255; |
330 |
|
|
pDataBitmap++; |
331 |
joko |
1.3 |
} |
332 |
joko |
1.9 |
exit(0); |
333 |
joko |
1.3 |
*/ |
334 |
|
|
|
335 |
joko |
1.9 |
// allocate memory for bitmap |
336 |
|
|
/* |
337 |
|
|
if ((pDataBitmap = malloc(XSIZE * YSIZE * 3 * sizeof(pDataBitmap[0]))) == NULL) |
338 |
|
|
perror("malloc"), exit(1); |
339 |
|
|
*/ |
340 |
|
|
|
341 |
joko |
1.6 |
// allocate memory for table of all worker handles |
342 |
joko |
1.9 |
if ((worker_handles = malloc(workers * sizeof(worker_handles[0]))) == NULL) |
343 |
joko |
1.6 |
perror("malloc"), exit(1); |
344 |
|
|
|
345 |
|
|
// allocate memory for table of all worker arguments |
346 |
joko |
1.9 |
if ((worker_args = malloc(workers * sizeof(worker_args[0]))) == NULL) |
347 |
joko |
1.6 |
perror("malloc"), exit(1); |
348 |
joko |
1.8 |
|
349 |
joko |
1.6 |
|
350 |
joko |
1.10 |
// calculate bitmap segment length for workers |
351 |
joko |
1.5 |
worker_rows = YSIZE / workers; |
352 |
joko |
1.9 |
if (VERBOSE) |
353 |
joko |
1.11 |
fprintf(stdout, "rows for each worker: %i\n", worker_rows); |
354 |
joko |
1.10 |
|
355 |
|
|
// start workers |
356 |
joko |
1.5 |
for (worker_index = 0; worker_index < workers; worker_index++) { |
357 |
|
|
|
358 |
joko |
1.9 |
// debugging: just run single thread |
359 |
joko |
1.7 |
//if (worker_index == 1) |
360 |
|
|
// continue; |
361 |
|
|
|
362 |
joko |
1.5 |
// number of row to start for each worker |
363 |
|
|
worker_startrow = worker_index * worker_rows; |
364 |
|
|
|
365 |
|
|
// recalculate number of rows for last worker if (YSIZE mod workers) != 0 |
366 |
|
|
if (worker_index == workers - 1) { |
367 |
|
|
worker_rows = YSIZE - worker_startrow; |
368 |
joko |
1.9 |
if (VERBOSE) |
369 |
joko |
1.11 |
fprintf(stdout, "rows for last worker: %i\n", worker_rows); |
370 |
joko |
1.5 |
} |
371 |
joko |
1.6 |
|
372 |
joko |
1.10 |
// assign each worker's arguments |
373 |
joko |
1.6 |
worker_args[worker_index].start_row = worker_startrow; |
374 |
|
|
worker_args[worker_index].number_of_rows = worker_rows; |
375 |
|
|
worker_args[worker_index].pBitmap = pDataBitmap; |
376 |
|
|
|
377 |
joko |
1.10 |
if (!use_processes) { |
378 |
joko |
1.6 |
|
379 |
joko |
1.10 |
worker_handles[worker_index] = CreateThread( |
380 |
|
|
NULL, // LPSECURITY_ATTRIBUTES lpThreadAttributes, |
381 |
|
|
0, // SIZE_T dwStackSize, |
382 |
|
|
&fractal_create_segment, // LPTHREAD_START_ROUTINE lpStartAddress, |
383 |
|
|
&worker_args[worker_index], // LPVOID lpParameter, |
384 |
|
|
0, // DWORD dwCreationFlags, |
385 |
|
|
NULL // LPDWORD lpThreadId |
386 |
|
|
); |
387 |
|
|
|
388 |
|
|
if (!worker_handles[worker_index]) |
389 |
|
|
printErrorAndExit("CreateThread failed", GetLastError()); |
390 |
|
|
|
391 |
|
|
} else { |
392 |
|
|
|
393 |
joko |
1.11 |
_snprintf(szCmdline, 1023, "%s %s %i %i", argv[0], "--worker", worker_startrow, worker_rows); |
394 |
|
|
if (VERBOSE) |
395 |
|
|
fprintf(stdout, "starting worker process: %s\n", szCmdline); |
396 |
joko |
1.10 |
ZeroMemory( &si, sizeof(si) ); |
397 |
|
|
si.cb = sizeof(si); |
398 |
|
|
ZeroMemory( &pi, sizeof(pi) ); |
399 |
|
|
|
400 |
|
|
if (!CreateProcess( |
401 |
|
|
NULL, // No module name (use command line) |
402 |
|
|
szCmdline, // Command line |
403 |
|
|
NULL, // Process handle not inheritable |
404 |
|
|
NULL, // Thread handle not inheritable |
405 |
|
|
FALSE, // Set handle inheritance to FALSE |
406 |
|
|
0, // No creation flags |
407 |
|
|
NULL, // Use parent's environment block |
408 |
|
|
NULL, // Use parent's starting directory |
409 |
|
|
&si, // Pointer to STARTUPINFO structure |
410 |
|
|
&pi // Pointer to PROCESS_INFORMATION structure |
411 |
|
|
)) |
412 |
|
|
printErrorAndExit("CreateProcess failed", GetLastError()); |
413 |
|
|
|
414 |
|
|
worker_handles[worker_index] = pi.hProcess; |
415 |
|
|
|
416 |
|
|
} |
417 |
|
|
|
418 |
joko |
1.5 |
} |
419 |
|
|
|
420 |
joko |
1.6 |
// wait for all threads |
421 |
joko |
1.9 |
if (VERBOSE) |
422 |
joko |
1.11 |
fprintf(stdout, "waiting for workers to finish...\n"); |
423 |
joko |
1.6 |
if (WaitForMultipleObjects(workers, worker_handles, TRUE, INFINITE) == WAIT_FAILED) |
424 |
|
|
perror("WaitForMultipleObjects"); |
425 |
joko |
1.7 |
|
426 |
joko |
1.9 |
// debugging: just run single thread |
427 |
joko |
1.7 |
//if (WaitForSingleObject(worker_handles[0], INFINITE) == WAIT_FAILED) |
428 |
|
|
// perror("WaitForSingleObject"); |
429 |
|
|
|
430 |
|
|
// close all worker handles |
431 |
|
|
for (worker_index = 0; worker_index < workers; worker_index++) |
432 |
|
|
CloseHandle(worker_handles[worker_index]); |
433 |
|
|
|
434 |
joko |
1.12 |
// write the result into the file |
435 |
joko |
1.3 |
if (!FlushViewOfFile(pData, 0)) { |
436 |
|
|
err = GetLastError(); |
437 |
|
|
printErrorAndExit("Error at UnmapViewOfFile", err); |
438 |
|
|
} |
439 |
|
|
|
440 |
joko |
1.12 |
// remove the mapped file |
441 |
joko |
1.3 |
if (!UnmapViewOfFile(pData)) { |
442 |
|
|
err = GetLastError(); |
443 |
|
|
printErrorAndExit("Error at UnmapViewOfFile", err); |
444 |
|
|
exit(err); |
445 |
|
|
} |
446 |
|
|
|
447 |
joko |
1.12 |
// cleanup handles |
448 |
joko |
1.3 |
if (!CloseHandle(hMap) || !CloseHandle(hFile) ) { |
449 |
|
|
err = GetLastError(); |
450 |
|
|
printErrorAndExit("Error at CloseHandle", err); |
451 |
|
|
} |
452 |
joko |
1.1 |
|
453 |
joko |
1.9 |
free(worker_args); |
454 |
|
|
free(worker_handles); |
455 |
joko |
1.8 |
|
456 |
|
|
return 0; |
457 |
|
|
|
458 |
joko |
1.1 |
} |