MCPcopy Create free account
hub / github.com/DreamSourceLab/DSView / di_thread

Function di_thread

libsigrokdecode4DSL/instance.c:1064–1151  ·  view source on GitHub ↗

* Worker thread (per PD-stack). * * @param data Pointer to the lowest-level PD's device instance. * Must not be NULL. * * @return NULL if there was an error. */

Source from the content-addressed store, hash-verified

1062 * @return NULL if there was an error.
1063 */
1064static gpointer di_thread(gpointer data)
1065{
1066 PyObject *py_res;
1067 struct srd_decoder_inst *di;
1068 int wanted_term = 0;
1069 PyGILState_STATE gstate;
1070 int is_task_stop_signal = FALSE;
1071
1072 assert(data);
1073
1074 di = data;
1075
1076 srd_dbg("%s: Starting thread routine for decoder.", di->inst_id);
1077
1078 gstate = PyGILState_Ensure();
1079
1080 /*
1081 * Call self.decode(). Only returns if the PD throws an exception.
1082 * "Regular" termination of the decode() method is not expected.
1083 */
1084 srd_dbg("%s: Calling decode().", di->inst_id);
1085 py_res = PyObject_CallMethod(di->py_inst, "decode", NULL);
1086 srd_dbg("%s: decode() terminated.", di->inst_id);
1087
1088 is_task_stop_signal = di->is_task_stop_signal;
1089 //srd_err("get flag:%d", is_task_stop_signal);
1090
1091 /**
1092 * decode() returns a error!
1093 * before the send thread exits, write the error
1094 *
1095 */
1096 if (py_res){
1097
1098 di->decoder_state = SRD_ERR;
1099
1100 if (PyUnicode_Check(py_res))
1101 {
1102 PyObject *py_bytes = PyUnicode_AsUTF8String(py_res);
1103 char *err_str = PyBytes_AsString(py_bytes);
1104 srd_err("python method decode() returns an error:\n %s", err_str);
1105 di->python_proc_error = g_strdup(err_str);
1106 }
1107 else{
1108 di->python_proc_error = g_strdup("python method decode() returns an unknown type error!");
1109 }
1110
1111 Py_DecRef(py_res);
1112 }
1113
1114 /**
1115 * decode() throw an except!
1116 * before the send thread exits, write the error
1117 *
1118 */
1119 if (!py_res && !is_task_stop_signal)
1120 {
1121 srd_exception_catch(&di->python_proc_error, "Protocol decoder instance %s: ", di->inst_id);

Callers

nothing calls this directly

Calls 1

srd_exception_catchFunction · 0.85

Tested by

no test coverage detected