summaryrefslogtreecommitdiff
path: root/src/lib/ecore
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-07-20 11:44:05 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-07-20 11:55:59 +0100
commit687b06fb3ff679c8d7464c9858365ea4eae4eaa3 (patch)
tree24a9d1539b7a1ad95572ae0ef7e8531b02f3c4aa /src/lib/ecore
parentbf01c2382a9b5c37f550e3559516c1e35126e5a0 (diff)
ecore - efl thread - reduce copy & paste and merge into single func
the call and call sync stuff was almost entirely copy & paste - this moves all the common code into shared funcs that reduce code bloat. it also moved from heap to stack for sync reply struct location.
Diffstat (limited to 'src/lib/ecore')
-rw-r--r--src/lib/ecore/efl_thread.c72
1 files changed, 27 insertions, 45 deletions
diff --git a/src/lib/ecore/efl_thread.c b/src/lib/ecore/efl_thread.c
index 1545c74597..f08be0e119 100644
--- a/src/lib/ecore/efl_thread.c
+++ b/src/lib/ecore/efl_thread.c
@@ -1035,11 +1035,9 @@ _efl_thread_efl_io_writer_can_write_get(const Eo *obj EINA_UNUSED, Efl_Thread_Da
1035 return pd->fd.can_write; 1035 return pd->fd.can_write;
1036} 1036}
1037 1037
1038void 1038static void
1039_appthread_threadio_call(Eo *obj EINA_UNUSED, Efl_Appthread_Data *pd, 1039_threadio_call(int fd, void *func_data, EFlThreadIOCall func, Eina_Free_Cb func_free_cb)
1040 void *func_data, EFlThreadIOCall func, Eina_Free_Cb func_free_cb)
1041{ 1040{
1042 Thread_Data *thdat = pd->thdat;
1043 Control_Data cmd; 1041 Control_Data cmd;
1044 1042
1045 memset(&cmd, 0, sizeof(cmd)); 1043 memset(&cmd, 0, sizeof(cmd));
@@ -1047,21 +1045,41 @@ _appthread_threadio_call(Eo *obj EINA_UNUSED, Efl_Appthread_Data *pd,
1047 cmd.d.ptr[0] = func; 1045 cmd.d.ptr[0] = func;
1048 cmd.d.ptr[1] = func_data; 1046 cmd.d.ptr[1] = func_data;
1049 cmd.d.ptr[2] = func_free_cb; 1047 cmd.d.ptr[2] = func_free_cb;
1050 _efl_thread_pipe_write(thdat->ctrl.in, &cmd, sizeof(Control_Data)); 1048 _efl_thread_pipe_write(fd, &cmd, sizeof(Control_Data));
1049}
1050
1051void
1052_appthread_threadio_call(Eo *obj EINA_UNUSED, Efl_Appthread_Data *pd,
1053 void *func_data, EFlThreadIOCall func, Eina_Free_Cb func_free_cb)
1054{
1055 Thread_Data *thdat = pd->thdat;
1056 _threadio_call(thdat->ctrl.in, func_data, func, func_free_cb);
1051} 1057}
1052 1058
1053EOLIAN static void 1059EOLIAN static void
1054_efl_thread_efl_threadio_call(Eo *obj EINA_UNUSED, Efl_Thread_Data *pd, 1060_efl_thread_efl_threadio_call(Eo *obj EINA_UNUSED, Efl_Thread_Data *pd,
1055 void *func_data, EFlThreadIOCall func, Eina_Free_Cb func_free_cb) 1061 void *func_data, EFlThreadIOCall func, Eina_Free_Cb func_free_cb)
1056{ 1062{
1063 _threadio_call(pd->ctrl.in, func_data, func, func_free_cb);
1064}
1065
1066static void *
1067_threadio_call_sync(int fd, void *func_data, EFlThreadIOCallSync func, Eina_Free_Cb func_free_cb)
1068{
1057 Control_Data cmd; 1069 Control_Data cmd;
1070 Control_Reply rep;
1058 1071
1059 memset(&cmd, 0, sizeof(cmd)); 1072 memset(&cmd, 0, sizeof(cmd));
1060 cmd.d.command = CMD_CALL; 1073 cmd.d.command = CMD_CALL_SYNC;
1061 cmd.d.ptr[0] = func; 1074 cmd.d.ptr[0] = func;
1062 cmd.d.ptr[1] = func_data; 1075 cmd.d.ptr[1] = func_data;
1063 cmd.d.ptr[2] = func_free_cb; 1076 cmd.d.ptr[2] = func_free_cb;
1064 _efl_thread_pipe_write(pd->ctrl.in, &cmd, sizeof(Control_Data)); 1077 cmd.d.ptr[3] = &rep;
1078 rep.data = NULL;
1079 eina_semaphore_new(&(rep.sem), 0);
1080 _efl_thread_pipe_write(fd, &cmd, sizeof(Control_Data));
1081 eina_semaphore_lock(&(rep.sem));
1082 return rep.data;
1065} 1083}
1066 1084
1067void * 1085void *
@@ -1069,50 +1087,14 @@ _appthread_threadio_call_sync(Eo *obj EINA_UNUSED, Efl_Appthread_Data *pd,
1069 void *func_data, EFlThreadIOCallSync func, Eina_Free_Cb func_free_cb) 1087 void *func_data, EFlThreadIOCallSync func, Eina_Free_Cb func_free_cb)
1070{ 1088{
1071 Thread_Data *thdat = pd->thdat; 1089 Thread_Data *thdat = pd->thdat;
1072 Control_Data cmd; 1090 return _threadio_call_sync(thdat->ctrl.in, func_data, func, func_free_cb);
1073 Control_Reply *rep;
1074 void *data;
1075
1076 memset(&cmd, 0, sizeof(cmd));
1077 cmd.d.command = CMD_CALL_SYNC;
1078 cmd.d.ptr[0] = func;
1079 cmd.d.ptr[1] = func_data;
1080 cmd.d.ptr[2] = func_free_cb;
1081 rep = malloc(sizeof(Control_Reply));
1082 if (!rep) return NULL;
1083 cmd.d.ptr[3] = rep;
1084 rep->data = NULL;
1085 eina_semaphore_new(&(rep->sem), 0);
1086 _efl_thread_pipe_write(thdat->ctrl.in, &cmd, sizeof(Control_Data));
1087 eina_semaphore_lock(&(rep->sem));
1088 data = rep->data;
1089 free(rep);
1090 return data;
1091} 1091}
1092 1092
1093EOLIAN static void * 1093EOLIAN static void *
1094_efl_thread_efl_threadio_call_sync(Eo *obj EINA_UNUSED, Efl_Thread_Data *pd, 1094_efl_thread_efl_threadio_call_sync(Eo *obj EINA_UNUSED, Efl_Thread_Data *pd,
1095 void *func_data, EFlThreadIOCallSync func, Eina_Free_Cb func_free_cb) 1095 void *func_data, EFlThreadIOCallSync func, Eina_Free_Cb func_free_cb)
1096{ 1096{
1097 Control_Data cmd; 1097 return _threadio_call_sync(pd->ctrl.in, func_data, func, func_free_cb);
1098 Control_Reply *rep;
1099 void *data;
1100
1101 memset(&cmd, 0, sizeof(cmd));
1102 cmd.d.command = CMD_CALL_SYNC;
1103 cmd.d.ptr[0] = func;
1104 cmd.d.ptr[1] = func_data;
1105 cmd.d.ptr[2] = func_free_cb;
1106 rep = malloc(sizeof(Control_Reply));
1107 if (!rep) return NULL;
1108 cmd.d.ptr[3] = rep;
1109 rep->data = NULL;
1110 eina_semaphore_new(&(rep->sem), 0);
1111 _efl_thread_pipe_write(pd->ctrl.in, &cmd, sizeof(Control_Data));
1112 eina_semaphore_lock(&(rep->sem));
1113 data = rep->data;
1114 free(rep);
1115 return data;
1116} 1098}
1117 1099
1118////////////////////////////////////////////////////////////////////////// 1100//////////////////////////////////////////////////////////////////////////