summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2013-09-03 15:24:27 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2013-10-28 15:47:15 +0900
commit31a5bfb46427265cd0537c0e61146a4960b7f557 (patch)
treeb58faa530ac43fd1eead8565890d91b491f7587d /src
parent8aa4a58d5b9092f8343c7e9bddf8f35738b93206 (diff)
evas/cserve2: Reuse file entries when possible
For some reason, a new File_Entry was created whenever a new image is loaded, even if that file was already opened by the client.
Diffstat (limited to 'src')
-rw-r--r--src/lib/evas/cserve2/evas_cs2_client.c56
1 files changed, 47 insertions, 9 deletions
diff --git a/src/lib/evas/cserve2/evas_cs2_client.c b/src/lib/evas/cserve2/evas_cs2_client.c
index 59ca540..852ae08 100644
--- a/src/lib/evas/cserve2/evas_cs2_client.c
+++ b/src/lib/evas/cserve2/evas_cs2_client.c
@@ -26,6 +26,8 @@ typedef void (*Op_Callback)(void *data, const void *msg, int size);
26struct _File_Entry { 26struct _File_Entry {
27 unsigned int file_id; 27 unsigned int file_id;
28 unsigned int server_file_id; 28 unsigned int server_file_id;
29 unsigned int refcount;
30 Eina_Stringshare *hkey;
29}; 31};
30 32
31struct _Client_Request { 33struct _Client_Request {
@@ -46,6 +48,7 @@ static unsigned int _file_id = 0;
46static unsigned int _data_id = 0; 48static unsigned int _data_id = 0;
47 49
48static Eina_List *_requests = NULL; 50static Eina_List *_requests = NULL;
51static Eina_Hash *_file_entries = NULL;
49 52
50// Shared index table 53// Shared index table
51static Index_Table _index; 54static Index_Table _index;
@@ -82,6 +85,15 @@ _memory_zero_cmp(void *data, size_t len)
82} 85}
83 86
84static void 87static void
88_file_entry_free(void *data)
89{
90 File_Entry *fentry = data;
91 if (!fentry) return;
92 eina_stringshare_del(fentry->hkey);
93 free(fentry);
94}
95
96static void
85_socket_path_set(char *path) 97_socket_path_set(char *path)
86{ 98{
87 char *env; 99 char *env;
@@ -304,6 +316,7 @@ evas_cserve2_init(void)
304 return 0; 316 return 0;
305 } 317 }
306 318
319 _file_entries = eina_hash_string_superfast_new(EINA_FREE_CB(_file_entry_free));
307 return cserve2_init; 320 return cserve2_init;
308} 321}
309 322
@@ -313,6 +326,12 @@ evas_cserve2_shutdown(void)
313 const char zeros[sizeof(Msg_Index_List)] = {0}; 326 const char zeros[sizeof(Msg_Index_List)] = {0};
314 Msg_Index_List *empty = (Msg_Index_List *) zeros; 327 Msg_Index_List *empty = (Msg_Index_List *) zeros;
315 328
329 if (cserve2_init <= 0)
330 {
331 CRIT("cserve2 is already shutdown");
332 return -1;
333 }
334
316 if ((--cserve2_init) > 0) 335 if ((--cserve2_init) > 0)
317 return cserve2_init; 336 return cserve2_init;
318 337
@@ -321,6 +340,9 @@ evas_cserve2_shutdown(void)
321 _server_index_list_set((Msg_Base *) empty, sizeof(Msg_Index_List)); 340 _server_index_list_set((Msg_Base *) empty, sizeof(Msg_Index_List));
322 _server_disconnect(); 341 _server_disconnect();
323 342
343 eina_hash_free(_file_entries);
344 _file_entries = NULL;
345
324 return cserve2_init; 346 return cserve2_init;
325} 347}
326 348
@@ -674,6 +696,7 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key,
674 int size; 696 int size;
675 char *buf; 697 char *buf;
676 char filebuf[PATH_MAX]; 698 char filebuf[PATH_MAX];
699 char *file_hkey;
677 Msg_Open msg_open; 700 Msg_Open msg_open;
678 File_Entry *fentry; 701 File_Entry *fentry;
679 Data_Entry *dentry; 702 Data_Entry *dentry;
@@ -696,23 +719,35 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key,
696 flen++; 719 flen++;
697 720
698 if (!key) key = ""; 721 if (!key) key = "";
722 klen = strlen(key) + 1;
699 723
700 fentry = calloc(1, sizeof(*fentry)); 724 file_hkey = alloca(flen + klen);
725 memcpy(file_hkey, file, flen);
726 file_hkey[flen - 1] = ':';
727 memcpy(file_hkey + flen, key, klen);
728 fentry = eina_hash_find(_file_entries, file_hkey);
701 if (!fentry) 729 if (!fentry)
702 return 0; 730 {
731 fentry = calloc(1, sizeof(*fentry));
732 if (!fentry)
733 return 0;
734
735 fentry->file_id = ++_file_id;
736 fentry->hkey = eina_stringshare_add(file_hkey);
737 eina_hash_direct_add(_file_entries, fentry->hkey, fentry);
738 }
739 fentry->refcount++;
703 740
704 dentry = calloc(1, sizeof(*dentry)); 741 dentry = calloc(1, sizeof(*dentry));
705 if (!dentry) 742 if (!dentry)
706 { 743 {
707 free(fentry); 744 if (!(--fentry->refcount))
745 eina_hash_del(_file_entries, fentry->hkey, fentry);
708 return 0; 746 return 0;
709 } 747 }
710 748
711 memset(&msg_open, 0, sizeof(msg_open)); 749 memset(&msg_open, 0, sizeof(msg_open));
712 750
713 fentry->file_id = ++_file_id;
714 klen = strlen(key) + 1;
715
716 msg_open.base.rid = _next_rid(); 751 msg_open.base.rid = _next_rid();
717 msg_open.base.type = CSERVE2_OPEN; 752 msg_open.base.type = CSERVE2_OPEN;
718 msg_open.file_id = fentry->file_id; 753 msg_open.file_id = fentry->file_id;
@@ -727,7 +762,8 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key,
727 buf = malloc(size); 762 buf = malloc(size);
728 if (!buf) 763 if (!buf)
729 { 764 {
730 free(fentry); 765 if (!(--fentry->refcount))
766 eina_hash_del(_file_entries, fentry->hkey, fentry);
731 free(dentry); 767 free(dentry);
732 return 0; 768 return 0;
733 } 769 }
@@ -741,8 +777,9 @@ _image_open_server_send(Image_Entry *ie, const char *file, const char *key,
741 { 777 {
742 ERR("Couldn't send message to server."); 778 ERR("Couldn't send message to server.");
743 free(buf); 779 free(buf);
744 free(fentry);
745 free(dentry); 780 free(dentry);
781 if (!(--fentry->refcount))
782 eina_hash_del(_file_entries, fentry->hkey, fentry);
746 return 0; 783 return 0;
747 } 784 }
748 785
@@ -848,7 +885,8 @@ _image_close_server_send(Image_Entry *ie)
848 msg.base.type = CSERVE2_CLOSE; 885 msg.base.type = CSERVE2_CLOSE;
849 msg.file_id = fentry->file_id; 886 msg.file_id = fentry->file_id;
850 887
851 free(fentry); 888 if (!(--fentry->refcount))
889 eina_hash_del(_file_entries, fentry->hkey, fentry);
852 ie->data1 = NULL; 890 ie->data1 = NULL;
853 891
854 if (!_server_send(&msg, sizeof(msg), NULL, NULL)) 892 if (!_server_send(&msg, sizeof(msg), NULL, NULL))