diff options
author | Jean-Philippe Andre <jp.andre@samsung.com> | 2013-08-23 18:31:30 +0900 |
---|---|---|
committer | Jean-Philippe Andre <jp.andre@samsung.com> | 2013-10-28 15:47:14 +0900 |
commit | 3f30fae818cde5d0f9d2159e7461d53493f295b8 (patch) | |
tree | 0ff4b645137674a2ac0c25b70f22b09845f0848f /src/lib/evas/cserve2 | |
parent | 8b39c443fe711fd311d1fabc6273b023bd242694 (diff) |
evas/cserve2: Remap indexes when count is wrong
When advertised count is wrong, try to remap the index.
This will avoid errors with string_get().
Diffstat (limited to 'src/lib/evas/cserve2')
-rw-r--r-- | src/lib/evas/cserve2/evas_cs2_client.c | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/lib/evas/cserve2/evas_cs2_client.c b/src/lib/evas/cserve2/evas_cs2_client.c index b378b7914a..16e1ebbf1b 100644 --- a/src/lib/evas/cserve2/evas_cs2_client.c +++ b/src/lib/evas/cserve2/evas_cs2_client.c | |||
@@ -1969,7 +1969,17 @@ _shared_index_item_get_by_id(Shared_Index *si, int elemsize, unsigned int id) | |||
1969 | high = si->header->emptyidx; // Should be si->header->sortedidx | 1969 | high = si->header->emptyidx; // Should be si->header->sortedidx |
1970 | 1970 | ||
1971 | if (high > si->count) | 1971 | if (high > si->count) |
1972 | high = si->count; | 1972 | { |
1973 | if (eina_file_refresh(si->f)) | ||
1974 | { | ||
1975 | WRN("Refreshing indexes."); | ||
1976 | _string_index_refresh(); | ||
1977 | _shared_index_remap_check(si, elemsize); | ||
1978 | high = MIN(si->header->emptyidx, si->count); | ||
1979 | } | ||
1980 | else | ||
1981 | high = si->count; | ||
1982 | } | ||
1973 | 1983 | ||
1974 | base = si->data + sizeof(Shared_Array_Header); | 1984 | base = si->data + sizeof(Shared_Array_Header); |
1975 | 1985 | ||
@@ -2128,12 +2138,26 @@ _shared_index_remap_check(Shared_Index *si, int elemsize) | |||
2128 | 2138 | ||
2129 | if (si->count != si->header->count) | 2139 | if (si->count != si->header->count) |
2130 | { | 2140 | { |
2141 | int oldcount; | ||
2131 | // generation_id should have been incremented. Maybe we are hitting | 2142 | // generation_id should have been incremented. Maybe we are hitting |
2132 | // a race condition here, when cserve2 grows an index. | 2143 | // a race condition here, when cserve2 grows an index. |
2133 | WRN("Reported index count differs from known count: %d vs %d", | 2144 | WRN("Reported index count differs from known count: %d vs %d", |
2134 | si->header->count, si->count); | 2145 | si->header->count, si->count); |
2146 | oldcount = si->count; | ||
2147 | eina_file_refresh(si->f); | ||
2135 | filesize = eina_file_size_get(si->f); | 2148 | filesize = eina_file_size_get(si->f); |
2136 | si->count = (filesize - sizeof(Shared_Array_Header)) / elemsize; | 2149 | si->count = (filesize - sizeof(Shared_Array_Header)) / elemsize; |
2150 | if (si->count != oldcount) | ||
2151 | { | ||
2152 | DBG("Remapping current index"); | ||
2153 | eina_file_map_free(si->f, si->data); | ||
2154 | si->data = eina_file_map_all(si->f, EINA_FILE_RANDOM); | ||
2155 | if (!si->data) | ||
2156 | { | ||
2157 | ERR("Failed to remap index: %m"); | ||
2158 | return EINA_FALSE; | ||
2159 | } | ||
2160 | } | ||
2137 | if (si->count > si->header->count) | 2161 | if (si->count > si->header->count) |
2138 | { | 2162 | { |
2139 | WRN("Index reports %d elements, but file can contain only %d", | 2163 | WRN("Index reports %d elements, but file can contain only %d", |