Skip to content

Commit f649bee

Browse files
Tomas Winklerwenlingz
authored andcommitted
dm: mevent: implement enable/disable functions
Current mevent mevent_del/add() implementations are incomplete and buggy. It's easier to implement mevent_enable/disable() required for mei virtualization. Other user of these functions, which were previously empty stubs is the uart mediator, so far it looks working well. Add few style issues fix on the way. Tracked-On: #1416 Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Acked-by: Yu Wang <yu1.wang@intel.com>
1 parent 018aba9 commit f649bee

File tree

1 file changed

+39
-11
lines changed

1 file changed

+39
-11
lines changed

devicemodel/core/mevent.c

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
* Micro event library for FreeBSD, designed for a single i/o thread
3131
* using EPOLL, and having events be persistent by default.
3232
*/
33-
3433
#include <assert.h>
3534
#include <errno.h>
3635
#include <stdlib.h>
@@ -59,8 +58,8 @@ static pthread_mutex_t mevent_lmutex = PTHREAD_MUTEX_INITIALIZER;
5958
struct mevent {
6059
void (*me_func)(int, enum ev_type, void *);
6160
int me_fd;
62-
enum ev_type me_type;
63-
void *me_param;
61+
enum ev_type me_type;
62+
void *me_param;
6463
int me_cq;
6564
int me_state;
6665
int me_closefd;
@@ -125,11 +124,12 @@ mevent_kq_filter(struct mevent *mevp)
125124

126125
if (mevp->me_type == EVF_WRITE)
127126
retval = EPOLLOUT;
127+
128128
return retval;
129129
}
130130

131131
static void
132-
mevent_destroy()
132+
mevent_destroy(void)
133133
{
134134
struct mevent *mevp, *tmpp;
135135
struct epoll_event ee;
@@ -142,9 +142,8 @@ mevent_destroy()
142142
ee.data.ptr = mevp;
143143
epoll_ctl(epoll_fd, EPOLL_CTL_DEL, mevp->me_fd, &ee);
144144

145-
if ((mevp->me_type == EVF_READ ||
146-
mevp->me_type == EVF_WRITE)
147-
&& mevp->me_fd != STDIN_FILENO)
145+
if ((mevp->me_type == EVF_READ || mevp->me_type == EVF_WRITE) &&
146+
mevp->me_fd != STDIN_FILENO)
148147
close(mevp->me_fd);
149148

150149
free(mevp);
@@ -221,13 +220,42 @@ mevent_add(int tfd, enum ev_type type,
221220
int
222221
mevent_enable(struct mevent *evp)
223222
{
224-
return 0;
223+
int ret;
224+
struct epoll_event ee;
225+
struct mevent *lp, *mevp = NULL;
226+
227+
mevent_qlock();
228+
/* Verify that the fd/type tuple is not present in the list */
229+
LIST_FOREACH(lp, &global_head, me_list) {
230+
if (lp == evp) {
231+
mevp = lp;
232+
break;
233+
}
234+
}
235+
mevent_qunlock();
236+
237+
if (!mevp)
238+
return -1;
239+
240+
ee.events = mevent_kq_filter(mevp);
241+
ee.data.ptr = mevp;
242+
ret = epoll_ctl(epoll_fd, EPOLL_CTL_ADD, mevp->me_fd, &ee);
243+
if (ret < 0 && errno == EEXIST)
244+
ret = 0;
245+
246+
return ret;
225247
}
226248

227249
int
228250
mevent_disable(struct mevent *evp)
229251
{
230-
return 0;
252+
int ret;
253+
254+
ret = epoll_ctl(epoll_fd, EPOLL_CTL_DEL, evp->me_fd, NULL);
255+
if (ret < 0 && errno == ENOENT)
256+
ret = 0;
257+
258+
return ret;
231259
}
232260

233261
static int
@@ -333,8 +361,8 @@ mevent_dispatch(void)
333361
suspend_mode = vm_get_suspend_mode();
334362

335363
if ((suspend_mode != VM_SUSPEND_NONE) &&
336-
(suspend_mode != VM_SUSPEND_SYSTEM_RESET) &&
337-
(suspend_mode != VM_SUSPEND_SUSPEND))
364+
(suspend_mode != VM_SUSPEND_SYSTEM_RESET) &&
365+
(suspend_mode != VM_SUSPEND_SUSPEND))
338366
break;
339367
}
340368
}

0 commit comments

Comments
 (0)