|
|
@@ -3,7 +3,6 @@
|
|
|
#include "pocketpy/pocketpy.h"
|
|
|
|
|
|
#include "pocketpy/common/utils.h"
|
|
|
-#include "pocketpy/objects/object.h"
|
|
|
#include "pocketpy/common/sstream.h"
|
|
|
#include "pocketpy/interpreter/vm.h"
|
|
|
|
|
|
@@ -79,6 +78,46 @@ static bool pkpy_currentvm(int argc, py_Ref argv) {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
+#if PK_ENABLE_WATCHDOG
|
|
|
+void py_watchdog_begin(py_i64 timeout) {
|
|
|
+ WatchdogInfo* info = &pk_current_vm->watchdog_info;
|
|
|
+ info->timeout = timeout;
|
|
|
+ py_watchdog_reset();
|
|
|
+}
|
|
|
+
|
|
|
+void py_watchdog_reset() {
|
|
|
+ WatchdogInfo* info = &pk_current_vm->watchdog_info;
|
|
|
+ info->last_reset_time = clock() / (CLOCKS_PER_SEC / 1000);
|
|
|
+}
|
|
|
+
|
|
|
+void py_watchdog_end() {
|
|
|
+ WatchdogInfo* info = &pk_current_vm->watchdog_info;
|
|
|
+ info->timeout = 0;
|
|
|
+}
|
|
|
+
|
|
|
+static bool pkpy_watchdog_begin(int argc, py_Ref argv) {
|
|
|
+ PY_CHECK_ARGC(1);
|
|
|
+ PY_CHECK_ARG_TYPE(0, tp_int);
|
|
|
+ py_watchdog_begin(py_toint(argv));
|
|
|
+ py_newnone(py_retval());
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static bool pkpy_watchdog_reset(int argc, py_Ref argv) {
|
|
|
+ PY_CHECK_ARGC(0);
|
|
|
+ py_watchdog_reset();
|
|
|
+ py_newnone(py_retval());
|
|
|
+ return true;
|
|
|
+}
|
|
|
+
|
|
|
+static bool pkpy_watchdog_end(int argc, py_Ref argv) {
|
|
|
+ PY_CHECK_ARGC(0);
|
|
|
+ py_watchdog_end();
|
|
|
+ py_newnone(py_retval());
|
|
|
+ return true;
|
|
|
+}
|
|
|
+#endif
|
|
|
+
|
|
|
typedef struct c11_ComputeThread c11_ComputeThread;
|
|
|
|
|
|
typedef struct {
|
|
|
@@ -467,6 +506,12 @@ void pk__add_module_pkpy() {
|
|
|
|
|
|
py_bindfunc(mod, "currentvm", pkpy_currentvm);
|
|
|
|
|
|
+#if PK_ENABLE_WATCHDOG
|
|
|
+ py_bindfunc(mod, "watchdog_begin", pkpy_watchdog_begin);
|
|
|
+ py_bindfunc(mod, "watchdog_reset", pkpy_watchdog_reset);
|
|
|
+ py_bindfunc(mod, "watchdog_end", pkpy_watchdog_end);
|
|
|
+#endif
|
|
|
+
|
|
|
pk_ComputeThread__register(mod);
|
|
|
}
|
|
|
|