diff options
author | Jean-Philippe Andre <jp.andre@samsung.com> | 2013-10-11 14:47:07 +0900 |
---|---|---|
committer | Jean-Philippe Andre <jp.andre@samsung.com> | 2013-10-28 15:47:16 +0900 |
commit | 4c44b5a553290f0e35675974da59b1205e06e850 (patch) | |
tree | 64c85a1151a88d87c4cfc693ce9c13ffaf195230 /src/lib/evas/cserve2 | |
parent | ffa27c70825161606a06cda017d2a82c50cfb34f (diff) |
evas/cserve2: Use Eina_Refcount instead of int
Use the refcount macros instead of manually handling
integers. Not sure if it really helps since the refcounting
in cs2 client is a bit special :)
Diffstat (limited to 'src/lib/evas/cserve2')
-rw-r--r-- | src/lib/evas/cserve2/evas_cs2_client.c | 76 | ||||
-rw-r--r-- | src/lib/evas/cserve2/evas_cs2_private.h | 2 |
2 files changed, 43 insertions, 35 deletions
diff --git a/src/lib/evas/cserve2/evas_cs2_client.c b/src/lib/evas/cserve2/evas_cs2_client.c index df3573f6ef..520c4002ea 100644 --- a/src/lib/evas/cserve2/evas_cs2_client.c +++ b/src/lib/evas/cserve2/evas_cs2_client.c | |||
@@ -44,7 +44,7 @@ static const Evas_Image_Load_Opts empty_lo = { | |||
44 | struct _File_Entry { | 44 | struct _File_Entry { |
45 | unsigned int file_id; | 45 | unsigned int file_id; |
46 | unsigned int server_file_id; | 46 | unsigned int server_file_id; |
47 | unsigned int refcount; | 47 | EINA_REFCOUNT; |
48 | Eina_Stringshare *hkey; | 48 | Eina_Stringshare *hkey; |
49 | }; | 49 | }; |
50 | 50 | ||
@@ -980,14 +980,16 @@ _image_open_server_send(Image_Entry *ie) | |||
980 | 980 | ||
981 | fentry->file_id = ++_file_id; | 981 | fentry->file_id = ++_file_id; |
982 | fentry->hkey = eina_stringshare_add(hkey); | 982 | fentry->hkey = eina_stringshare_add(hkey); |
983 | EINA_REFCOUNT_INIT(fentry); | ||
983 | eina_hash_direct_add(_file_entries, fentry->hkey, fentry); | 984 | eina_hash_direct_add(_file_entries, fentry->hkey, fentry); |
984 | } | 985 | } |
985 | fentry->refcount++; | 986 | else |
987 | EINA_REFCOUNT_REF(fentry); | ||
986 | 988 | ||
987 | dentry = calloc(1, sizeof(*dentry)); | 989 | dentry = calloc(1, sizeof(*dentry)); |
988 | if (!dentry) | 990 | if (!dentry) |
989 | { | 991 | { |
990 | if (!(--fentry->refcount)) | 992 | EINA_REFCOUNT_UNREF(fentry) |
991 | eina_hash_del(_file_entries, fentry->hkey, fentry); | 993 | eina_hash_del(_file_entries, fentry->hkey, fentry); |
992 | return 0; | 994 | return 0; |
993 | } | 995 | } |
@@ -1008,7 +1010,7 @@ _image_open_server_send(Image_Entry *ie) | |||
1008 | buf = malloc(size); | 1010 | buf = malloc(size); |
1009 | if (!buf) | 1011 | if (!buf) |
1010 | { | 1012 | { |
1011 | if (!(--fentry->refcount)) | 1013 | EINA_REFCOUNT_UNREF(fentry) |
1012 | eina_hash_del(_file_entries, fentry->hkey, fentry); | 1014 | eina_hash_del(_file_entries, fentry->hkey, fentry); |
1013 | free(dentry); | 1015 | free(dentry); |
1014 | return 0; | 1016 | return 0; |
@@ -1023,7 +1025,7 @@ _image_open_server_send(Image_Entry *ie) | |||
1023 | { | 1025 | { |
1024 | ERR("Couldn't send message to server."); | 1026 | ERR("Couldn't send message to server."); |
1025 | free(dentry); | 1027 | free(dentry); |
1026 | if (!(--fentry->refcount)) | 1028 | EINA_REFCOUNT_UNREF(fentry) |
1027 | eina_hash_del(_file_entries, fentry->hkey, fentry); | 1029 | eina_hash_del(_file_entries, fentry->hkey, fentry); |
1028 | return 0; | 1030 | return 0; |
1029 | } | 1031 | } |
@@ -1131,7 +1133,7 @@ _image_close_server_send(Image_Entry *ie) | |||
1131 | msg->base.type = CSERVE2_CLOSE; | 1133 | msg->base.type = CSERVE2_CLOSE; |
1132 | msg->file_id = fentry->file_id; | 1134 | msg->file_id = fentry->file_id; |
1133 | 1135 | ||
1134 | if (!(--fentry->refcount)) | 1136 | EINA_REFCOUNT_UNREF(fentry) |
1135 | eina_hash_del(_file_entries, fentry->hkey, fentry); | 1137 | eina_hash_del(_file_entries, fentry->hkey, fentry); |
1136 | ie->data1 = NULL; | 1138 | ie->data1 = NULL; |
1137 | 1139 | ||
@@ -1422,8 +1424,8 @@ struct _CS_Glyph_Out | |||
1422 | unsigned int size; | 1424 | unsigned int size; |
1423 | unsigned int hint; | 1425 | unsigned int hint; |
1424 | Eina_Bool used; | 1426 | Eina_Bool used; |
1425 | int refcount; | ||
1426 | int pending_ref; | 1427 | int pending_ref; |
1428 | EINA_REFCOUNT; | ||
1427 | }; | 1429 | }; |
1428 | 1430 | ||
1429 | static void | 1431 | static void |
@@ -1684,13 +1686,12 @@ _glyph_map_remap_check(Glyph_Map *map, const char *idxpath, const char *datapath | |||
1684 | eina_strlcpy(map->index.path, idxpath, SHARED_BUFFER_PATH_MAX); | 1686 | eina_strlcpy(map->index.path, idxpath, SHARED_BUFFER_PATH_MAX); |
1685 | 1687 | ||
1686 | // Reopen mempool | 1688 | // Reopen mempool |
1687 | if (map->mempool.refcount > 0) | 1689 | if (EINA_REFCOUNT_GET(&map->mempool) > 0) |
1688 | { | 1690 | { |
1689 | oldbuf = calloc(1, sizeof(Glyph_Map)); | 1691 | oldbuf = calloc(1, sizeof(Glyph_Map)); |
1690 | oldbuf->f = map->mempool.f; | 1692 | oldbuf->f = map->mempool.f; |
1691 | oldbuf->data = map->mempool.data; | 1693 | oldbuf->data = map->mempool.data; |
1692 | oldbuf->size = map->mempool.size; | 1694 | oldbuf->size = map->mempool.size; |
1693 | oldbuf->refcount = map->mempool.refcount; | ||
1694 | eina_strlcpy(oldbuf->path, map->mempool.path, SHARED_BUFFER_PATH_MAX); | 1695 | eina_strlcpy(oldbuf->path, map->mempool.path, SHARED_BUFFER_PATH_MAX); |
1695 | map->mempool_lru = eina_list_append(map->mempool_lru, oldbuf); | 1696 | map->mempool_lru = eina_list_append(map->mempool_lru, oldbuf); |
1696 | } | 1697 | } |
@@ -1704,18 +1705,21 @@ _glyph_map_remap_check(Glyph_Map *map, const char *idxpath, const char *datapath | |||
1704 | map->mempool.f = eina_file_open(datapath, EINA_TRUE); | 1705 | map->mempool.f = eina_file_open(datapath, EINA_TRUE); |
1705 | map->mempool.data = eina_file_map_all(map->mempool.f, EINA_FILE_RANDOM); | 1706 | map->mempool.data = eina_file_map_all(map->mempool.f, EINA_FILE_RANDOM); |
1706 | map->mempool.size = eina_file_size_get(map->mempool.f); | 1707 | map->mempool.size = eina_file_size_get(map->mempool.f); |
1707 | map->mempool.refcount = 0; | 1708 | EINA_REFCOUNT_GET(&map->mempool) = 0; |
1708 | 1709 | ||
1709 | EINA_CLIST_FOR_EACH_ENTRY_SAFE(gl, cursor, &map->glyphs, | 1710 | EINA_CLIST_FOR_EACH_ENTRY_SAFE(gl, cursor, &map->glyphs, |
1710 | CS_Glyph_Out, map_entry) | 1711 | CS_Glyph_Out, map_entry) |
1711 | { | 1712 | { |
1712 | if (!gl->refcount) | 1713 | if (!EINA_REFCOUNT_GET(gl)) |
1713 | { | 1714 | { |
1714 | gl->sb = NULL; | 1715 | gl->sb = NULL; |
1715 | gl->base.bitmap.buffer = NULL; | 1716 | gl->base.bitmap.buffer = NULL; |
1716 | } | 1717 | } |
1717 | else | 1718 | else |
1718 | gl->sb = oldbuf; | 1719 | { |
1720 | gl->sb = oldbuf; | ||
1721 | EINA_REFCOUNT_REF(gl->sb); | ||
1722 | } | ||
1719 | } | 1723 | } |
1720 | 1724 | ||
1721 | if (!eina_clist_count(&map->glyphs)) | 1725 | if (!eina_clist_count(&map->glyphs)) |
@@ -1738,13 +1742,12 @@ _glyph_map_remap_check(Glyph_Map *map, const char *idxpath, const char *datapath | |||
1738 | // after some glyphs have been requested but not all for the current | 1742 | // after some glyphs have been requested but not all for the current |
1739 | // draw. | 1743 | // draw. |
1740 | 1744 | ||
1741 | if (map->mempool.refcount > 0) | 1745 | if (EINA_REFCOUNT_GET(&map->mempool) > 0) |
1742 | { | 1746 | { |
1743 | oldbuf = calloc(1, sizeof(Glyph_Map)); | 1747 | oldbuf = calloc(1, sizeof(Glyph_Map)); |
1744 | oldbuf->f = eina_file_dup(map->mempool.f); | 1748 | oldbuf->f = eina_file_dup(map->mempool.f); |
1745 | oldbuf->data = map->mempool.data; | 1749 | oldbuf->data = map->mempool.data; |
1746 | oldbuf->size = map->mempool.size; | 1750 | oldbuf->size = map->mempool.size; |
1747 | //oldbuf->refcount = map->mempool.refcount; | ||
1748 | eina_strlcpy(oldbuf->path, map->mempool.path, SHARED_BUFFER_PATH_MAX); | 1751 | eina_strlcpy(oldbuf->path, map->mempool.path, SHARED_BUFFER_PATH_MAX); |
1749 | map->mempool_lru = eina_list_append(map->mempool_lru, oldbuf); | 1752 | map->mempool_lru = eina_list_append(map->mempool_lru, oldbuf); |
1750 | } | 1753 | } |
@@ -1752,13 +1755,13 @@ _glyph_map_remap_check(Glyph_Map *map, const char *idxpath, const char *datapath | |||
1752 | eina_file_map_free(map->mempool.f, map->mempool.data); | 1755 | eina_file_map_free(map->mempool.f, map->mempool.data); |
1753 | map->mempool.data = eina_file_map_all(map->mempool.f, EINA_FILE_RANDOM); | 1756 | map->mempool.data = eina_file_map_all(map->mempool.f, EINA_FILE_RANDOM); |
1754 | map->mempool.size = eina_file_size_get(map->mempool.f); | 1757 | map->mempool.size = eina_file_size_get(map->mempool.f); |
1755 | map->mempool.refcount = 0; | 1758 | EINA_REFCOUNT_GET(&map->mempool) = 0; |
1756 | 1759 | ||
1757 | // Remap unused but loaded glyphs | 1760 | // Remap unused but loaded glyphs |
1758 | EINA_CLIST_FOR_EACH_ENTRY(gl, &map->glyphs, | 1761 | EINA_CLIST_FOR_EACH_ENTRY(gl, &map->glyphs, |
1759 | CS_Glyph_Out, map_entry) | 1762 | CS_Glyph_Out, map_entry) |
1760 | { | 1763 | { |
1761 | if (!gl->refcount) | 1764 | if (!EINA_REFCOUNT_GET(gl)) |
1762 | { | 1765 | { |
1763 | gl->sb = &map->mempool; | 1766 | gl->sb = &map->mempool; |
1764 | gl->base.bitmap.buffer = (unsigned char *) gl->sb->data + gl->offset; | 1767 | gl->base.bitmap.buffer = (unsigned char *) gl->sb->data + gl->offset; |
@@ -1766,7 +1769,7 @@ _glyph_map_remap_check(Glyph_Map *map, const char *idxpath, const char *datapath | |||
1766 | else if (oldbuf) | 1769 | else if (oldbuf) |
1767 | { | 1770 | { |
1768 | gl->sb = oldbuf; | 1771 | gl->sb = oldbuf; |
1769 | gl->sb->refcount++; | 1772 | EINA_REFCOUNT_REF(gl->sb); |
1770 | } | 1773 | } |
1771 | else | 1774 | else |
1772 | ERR("Invalid refcounting here."); | 1775 | ERR("Invalid refcounting here."); |
@@ -2139,7 +2142,7 @@ evas_cserve2_font_glyph_request(Font_Entry *fe, unsigned int idx, Font_Hint_Flag | |||
2139 | // Check map is still valid, otherwise we want to request the glyph again | 2142 | // Check map is still valid, otherwise we want to request the glyph again |
2140 | if (glyph && glyph->map && (&glyph->map->mempool != glyph->sb)) | 2143 | if (glyph && glyph->map && (&glyph->map->mempool != glyph->sb)) |
2141 | { | 2144 | { |
2142 | if (!glyph->refcount) | 2145 | if (!EINA_REFCOUNT_GET(glyph)) |
2143 | { | 2146 | { |
2144 | fash_gl_del(fash, idx); | 2147 | fash_gl_del(fash, idx); |
2145 | glyph = NULL; | 2148 | glyph = NULL; |
@@ -2201,7 +2204,7 @@ evas_cserve2_font_glyph_used(Font_Entry *fe, unsigned int idx, Font_Hint_Flags h | |||
2201 | // Glyph was stored in a dead buffer. Need to reload it :) | 2204 | // Glyph was stored in a dead buffer. Need to reload it :) |
2202 | if (&glyph->map->mempool != glyph->sb) | 2205 | if (&glyph->map->mempool != glyph->sb) |
2203 | { | 2206 | { |
2204 | if (!glyph->refcount) | 2207 | if (!EINA_REFCOUNT_GET(glyph)) |
2205 | { | 2208 | { |
2206 | fash_gl_del(fash, idx); | 2209 | fash_gl_del(fash, idx); |
2207 | return EINA_FALSE; | 2210 | return EINA_FALSE; |
@@ -2261,7 +2264,7 @@ try_again: | |||
2261 | if (out->map && (&out->map->mempool != out->sb)) | 2264 | if (out->map && (&out->map->mempool != out->sb)) |
2262 | { | 2265 | { |
2263 | // If the map is not valid, this is a good time to reload the glyph. | 2266 | // If the map is not valid, this is a good time to reload the glyph. |
2264 | if (!out->refcount) | 2267 | if (!EINA_REFCOUNT_GET(out)) |
2265 | { | 2268 | { |
2266 | fash_gl_del(fash, idx); | 2269 | fash_gl_del(fash, idx); |
2267 | if (!evas_cserve2_font_glyph_request(fe, idx, hints)) | 2270 | if (!evas_cserve2_font_glyph_request(fe, idx, hints)) |
@@ -2311,18 +2314,20 @@ evas_cserve2_font_glyph_ref(RGBA_Font_Glyph_Out *glyph, Eina_Bool incref) | |||
2311 | glout->pending_ref++; | 2314 | glout->pending_ref++; |
2312 | return; | 2315 | return; |
2313 | } | 2316 | } |
2314 | else if (!glout->refcount) | 2317 | else if (!EINA_REFCOUNT_GET(glout)) |
2315 | glout->sb->refcount++; | 2318 | EINA_REFCOUNT_REF(glout->sb); |
2316 | if (glout->pending_ref) | 2319 | if (glout->pending_ref) |
2317 | { | 2320 | { |
2318 | glout->refcount += glout->pending_ref; | 2321 | EINA_REFCOUNT_GET(glout) += glout->pending_ref; |
2319 | glout->pending_ref = 0; | 2322 | glout->pending_ref = 0; |
2320 | } | 2323 | } |
2321 | glout->refcount++; | 2324 | EINA_REFCOUNT_REF(glout); |
2322 | return; | 2325 | return; |
2323 | } | 2326 | } |
2324 | 2327 | ||
2325 | EINA_SAFETY_ON_FALSE_RETURN((glout->refcount + glout->pending_ref) > 0); | 2328 | EINA_SAFETY_ON_FALSE_RETURN |
2329 | ((EINA_REFCOUNT_GET(glout) + glout->pending_ref) > 0); | ||
2330 | |||
2326 | if (!glout->sb) | 2331 | if (!glout->sb) |
2327 | { | 2332 | { |
2328 | glout->pending_ref--; | 2333 | glout->pending_ref--; |
@@ -2331,23 +2336,26 @@ evas_cserve2_font_glyph_ref(RGBA_Font_Glyph_Out *glyph, Eina_Bool incref) | |||
2331 | 2336 | ||
2332 | if (glout->pending_ref) | 2337 | if (glout->pending_ref) |
2333 | { | 2338 | { |
2334 | if (!glout->refcount && (glout->pending_ref > 0)) | 2339 | if (!EINA_REFCOUNT_GET(glout) && (glout->pending_ref > 0)) |
2335 | glout->sb->refcount++; | 2340 | EINA_REFCOUNT_REF(glout->sb); |
2336 | glout->refcount += glout->pending_ref; | 2341 | EINA_REFCOUNT_GET(glout) += glout->pending_ref; |
2337 | glout->pending_ref = 0; | 2342 | glout->pending_ref = 0; |
2338 | } | 2343 | } |
2339 | 2344 | ||
2340 | glout->refcount--; | 2345 | EINA_REFCOUNT_UNREF(glout) |
2341 | if (!glout->refcount) | ||
2342 | { | 2346 | { |
2343 | EINA_SAFETY_ON_FALSE_RETURN(glout->sb->refcount > 0); | 2347 | Eina_Bool noref = EINA_FALSE; |
2344 | glout->sb->refcount--; | 2348 | |
2349 | EINA_SAFETY_ON_FALSE_RETURN(EINA_REFCOUNT_GET(glout->sb) > 0); | ||
2350 | EINA_REFCOUNT_UNREF(glout->sb) | ||
2351 | noref = EINA_TRUE; | ||
2345 | 2352 | ||
2346 | if (glout->sb != &glout->map->mempool) | 2353 | if (glout->sb != &glout->map->mempool) |
2347 | { | 2354 | { |
2348 | if (!glout->sb->refcount) | 2355 | if (noref) |
2349 | { | 2356 | { |
2350 | DBG("Glyph shared buffer reached refcount 0. Unmapping %p from %s", | 2357 | DBG("Glyph shared buffer reached refcount 0. " |
2358 | "Unmapping %p from %s", | ||
2351 | glout->sb->data, glout->sb->path); | 2359 | glout->sb->data, glout->sb->path); |
2352 | glout->map->mempool_lru = | 2360 | glout->map->mempool_lru = |
2353 | eina_list_remove(glout->map->mempool_lru, glout->sb); | 2361 | eina_list_remove(glout->map->mempool_lru, glout->sb); |
diff --git a/src/lib/evas/cserve2/evas_cs2_private.h b/src/lib/evas/cserve2/evas_cs2_private.h index 253c7e303c..2d4aeb435b 100644 --- a/src/lib/evas/cserve2/evas_cs2_private.h +++ b/src/lib/evas/cserve2/evas_cs2_private.h | |||
@@ -56,7 +56,7 @@ struct _Shared_Buffer | |||
56 | Eina_File *f; | 56 | Eina_File *f; |
57 | char *data; | 57 | char *data; |
58 | int size; | 58 | int size; |
59 | int refcount; | 59 | EINA_REFCOUNT; |
60 | }; | 60 | }; |
61 | 61 | ||
62 | struct _Index_Table | 62 | struct _Index_Table |