|
|
1 | /** |
|
|
2 | * ZANavi, Zoff Android Navigation system. |
|
|
3 | * Copyright (C) 2011-2012 Zoff <zoff@zoff.cc> |
|
|
4 | * |
|
|
5 | * This program is free software; you can redistribute it and/or |
|
|
6 | * modify it under the terms of the GNU General Public License |
|
|
7 | * version 2 as published by the Free Software Foundation. |
|
|
8 | * |
|
|
9 | * This program is distributed in the hope that it will be useful, |
|
|
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
12 | * GNU General Public License for more details. |
|
|
13 | * |
|
|
14 | * You should have received a copy of the GNU General Public License |
|
|
15 | * along with this program; if not, write to the |
|
|
16 | * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
|
|
17 | * Boston, MA 02110-1301, USA. |
|
|
18 | */ |
|
|
19 | |
1 | /** |
20 | /** |
2 | * Navit, a modular navigation system. |
21 | * Navit, a modular navigation system. |
3 | * Copyright (C) 2005-2011 Navit Team |
22 | * Copyright (C) 2005-2011 Navit Team |
4 | * |
23 | * |
5 | * This program is free software; you can redistribute it and/or |
24 | * This program is free software; you can redistribute it and/or |
… | |
… | |
19 | #include <string.h> |
38 | #include <string.h> |
20 | #include <stdlib.h> |
39 | #include <stdlib.h> |
21 | #include "maptool.h" |
40 | #include "maptool.h" |
22 | #include "debug.h" |
41 | #include "debug.h" |
23 | |
42 | |
|
|
43 | // static char buffer[800000]; --> not thread safe!! |
|
|
44 | // struct item_bin *item_bin = (struct item_bin *) (void *) ib_buffer_; --> not thread safe |
24 | |
45 | |
25 | static char buffer[800000]; |
46 | struct node_item * |
26 | struct item_bin *item_bin=(struct item_bin *)(void *)buffer; |
47 | read_node_item(FILE *in, int local_thread_num) |
|
|
48 | { |
|
|
49 | struct node_item *node_item = (struct node_item *) (void *) ib_buffer_array[local_thread_num]; |
|
|
50 | if (fread(node_item, sizeof(struct node_item), 1, in) != 1) |
|
|
51 | return NULL; |
|
|
52 | return node_item; |
|
|
53 | } |
27 | |
54 | |
28 | struct item_bin * |
55 | struct item_bin * |
29 | read_item(FILE *in) |
56 | read_item(FILE *in, int local_thread_num) |
30 | { |
57 | { |
31 | struct item_bin *ib=(struct item_bin *) buffer; |
58 | struct item_bin *ib = (struct item_bin *) ib_buffer_array[local_thread_num]; |
32 | for (;;) { |
59 | for (;;) |
|
|
60 | { |
33 | switch (item_bin_read(ib, in)) { |
61 | switch (item_bin_read(ib, in)) |
|
|
62 | { |
34 | case 0: |
63 | case 0: |
35 | return NULL; |
64 | return NULL; |
36 | case 2: |
65 | case 2: |
37 | dbg_assert((ib->len+1)*4 < sizeof(buffer)); |
66 | dbg_assert((ib->len + 1) * 4 < sizeof(ib_buffer_array[local_thread_num])); |
38 | bytes_read+=(ib->len+1)*sizeof(int); |
67 | bytes_read += (ib->len + 1) * sizeof(int); |
39 | return ib; |
68 | return ib; |
40 | default: |
69 | default: |
41 | continue; |
70 | continue; |
42 | } |
71 | } |
43 | } |
72 | } |
44 | } |
73 | } |
45 | |
74 | |
46 | struct item_bin * |
75 | struct item_bin * |
47 | read_item_range(FILE *in, int *min, int *max) |
76 | read_item_range(FILE *in, int *min, int *max, int local_thread_num) |
48 | { |
77 | { |
49 | struct range r; |
78 | struct range r; |
50 | |
79 | |
51 | if (fread(&r, sizeof(r), 1, in) != 1) |
80 | if (fread(&r, sizeof(r), 1, in) != 1) |
52 | return NULL; |
81 | return NULL; |
53 | *min=r.min; |
82 | *min = r.min; |
54 | *max=r.max; |
83 | *max = r.max; |
55 | return read_item(in); |
84 | return read_item(in, local_thread_num); |
56 | } |
85 | } |
57 | |
86 | |
58 | struct item_bin * |
87 | struct item_bin * |
59 | init_item(enum item_type type) |
88 | init_item(enum item_type type, int local_thread_num) |
60 | { |
89 | { |
61 | struct item_bin *ib=(struct item_bin *) buffer; |
90 | struct item_bin *ib = (struct item_bin *) ib_buffer_array[local_thread_num]; |
62 | |
91 | |
63 | item_bin_init(ib, type); |
92 | item_bin_init(ib, type); |
64 | return ib; |
93 | return ib; |
65 | } |
94 | } |