Code Review
/
src
/
libhomescreen.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
review
|
tree
raw
|
inline
| side by side
Improve safety of link to event loop
[src/libhomescreen.git]
/
src
/
libhomescreen.cpp
diff --git
a/src/libhomescreen.cpp
b/src/libhomescreen.cpp
index
84e3472
..
121def7
100644
(file)
--- a/
src/libhomescreen.cpp
+++ b/
src/libhomescreen.cpp
@@
-25,6
+25,7
@@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cstring>
+#include <thread>
#include <libhomescreen.hpp>
#include "hmi-debug.h"
#include <libhomescreen.hpp>
#include "hmi-debug.h"
@@
-87,6
+88,12
@@
static void _on_reply_static(void *closure, struct afb_wsj1_msg *msg)
}
}
+static void event_loop_run(struct sd_event* loop){
+ sd_event_loop(loop);
+ sd_event_unref(loop);
+}
+
+
/**
* constructor
*/
/**
* constructor
*/
@@
-99,14
+106,14
@@
LibHomeScreen::LibHomeScreen()
*/
LibHomeScreen::~LibHomeScreen()
{
*/
LibHomeScreen::~LibHomeScreen()
{
- if(mploop)
- {
- sd_event_unref(mploop);
- }
if(sp_websock != NULL)
{
afb_wsj1_unref(sp_websock);
}
if(sp_websock != NULL)
{
afb_wsj1_unref(sp_websock);
}
+ if(mploop)
+ {
+ sd_event_exit(mploop, 0);
+ }
}
/**
}
/**
@@
-177,13
+184,19
@@
int LibHomeScreen::initialize_websocket()
mploop = NULL;
onEvent = nullptr;
onReply = nullptr;
mploop = NULL;
onEvent = nullptr;
onReply = nullptr;
- int ret = sd_event_
default
(&mploop);
+ int ret = sd_event_
new
(&mploop);
if(ret < 0)
{
HMI_ERROR("libhomescreen","Failed to create event loop");
goto END;
}
if(ret < 0)
{
HMI_ERROR("libhomescreen","Failed to create event loop");
goto END;
}
+ {
+ // enforce context to avoid initialization/goto error
+ std::thread th(event_loop_run, mploop);
+ th.detach();
+ }
+
/* Initialize interface from websocket */
minterface.on_hangup = _on_hangup_static;
minterface.on_call = _on_call_static;
/* Initialize interface from websocket */
minterface.on_hangup = _on_hangup_static;
minterface.on_call = _on_call_static;
@@
-201,10
+214,6
@@
int LibHomeScreen::initialize_websocket()
return 0;
END:
return 0;
END:
- if(mploop)
- {
- sd_event_unref(mploop);
- }
return -1;
}
return -1;
}