Skip to content

Commit bbab4ac

Browse files
committed
EV_SET accepts an uintptr_t as ident. Directly use src.
1 parent 62245da commit bbab4ac

File tree

7 files changed

+14
-26
lines changed

7 files changed

+14
-26
lines changed

Lib/ctx.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,6 @@ static int recv_events(m_ctx_t *c, int timeout) {
175175
case M_SRC_TYPE_THRESH:
176176
msg->thresh_evt = m_mem_new(sizeof(*msg->thresh_evt), NULL);
177177
if (poll_consume_thresh(&c->ppriv, i, p, msg->thresh_evt) == 0) {
178-
msg->thresh_evt->id = p->thresh_src.thr.id;
179178
msg->thresh_evt->inactive_ms = p->thresh_src.alarm.inactive_ms;
180179
msg->thresh_evt->activity_freq = p->thresh_src.alarm.activity_freq;
181180
}

Lib/mod.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ int evaluate_module(void *data, const char *key, void *value) {
140140
}
141141
}
142142
if (alarm->activity_freq != 0 || alarm->inactive_ms != 0) {
143-
poll_notify_thresh(&mod->ctx->ppriv, src);
143+
poll_notify_userevent(&mod->ctx->ppriv, src);
144144
}
145145
})
146146
}

Lib/poll/cmn_linux.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,15 @@ static void create_eventfd(ev_src_t *tmp) {
5656
tmp->task_src.f.fd = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);
5757
}
5858

59-
int poll_notify_task(poll_priv_t *priv, ev_src_t *src) {
59+
int poll_notify_userevent(poll_priv_t *priv, ev_src_t *src) {
6060
uint64_t u = 1;
61+
/* task_src and thresh_src share memory layout, thus using task_src.f.fd is ok */
6162
if (write(src->task_src.f.fd, &u, sizeof(uint64_t)) == sizeof(uint64_t)) {
6263
return 0;
6364
}
6465
return -errno;
6566
}
6667

67-
int poll_notify_thresh(poll_priv_t *priv, ev_src_t *src) {
68-
// Inside an union: src->task_src.f.fd and src->thresh_src.f.fd share same memory
69-
return poll_notify_task(priv, src);
70-
}
71-
7268
void create_priv_fd(ev_src_t *tmp) {
7369
switch (tmp->type) {
7470
case M_SRC_TYPE_TMR:

Lib/poll/kqueue_priv.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,8 @@ int poll_set_new_evt(poll_priv_t *priv, ev_src_t *tmp, const enum op_type flag)
7171
EV_SET(_ev, tmp->pid_src.pid.pid, EVFILT_PROC, f, tmp->pid_src.pid.events, 0, tmp);
7272
break;
7373
case M_SRC_TYPE_TASK:
74-
EV_SET(_ev, tmp->task_src.tid.tid, EVFILT_USER, f, NOTE_FFNOP, 0, tmp);
75-
break;
7674
case M_SRC_TYPE_THRESH:
77-
EV_SET(_ev, tmp->thresh_src.thr.id, EVFILT_USER, f, NOTE_FFNOP, 0, tmp);
75+
EV_SET(_ev, (uintptr_t)tmp, EVFILT_USER, f, NOTE_FFNOP, 0, tmp);
7876
break;
7977
default:
8078
break;
@@ -171,16 +169,9 @@ int poll_destroy(poll_priv_t *priv) {
171169
return 0;
172170
}
173171

174-
int poll_notify_task(poll_priv_t *priv, ev_src_t *src) {
175-
GET_PRIV_DATA();
176-
struct kevent *_ev = (struct kevent *)src->ev;
177-
EV_SET(_ev, src->task_src.tid.tid, EVFILT_USER, 0, NOTE_FFNOP | NOTE_TRIGGER, 0, src);
178-
return kevent(kp->fd, _ev, 1, NULL, 0, NULL);
179-
}
180-
181-
int poll_notify_thresh(poll_priv_t *priv, ev_src_t *src) {
172+
int poll_notify_userevent(poll_priv_t *priv, ev_src_t *src) {
182173
GET_PRIV_DATA();
183174
struct kevent *_ev = (struct kevent *)src->ev;
184-
EV_SET(_ev, src->thresh_src.thr.id, EVFILT_USER, 0, NOTE_FFNOP | NOTE_TRIGGER, 0, src);
175+
EV_SET(_ev, (uintptr_t)src, EVFILT_USER, 0, NOTE_FFNOP | NOTE_TRIGGER, 0, src);
185176
return kevent(kp->fd, _ev, 1, NULL, 0, NULL);
186177
}

Lib/poll/poll_priv.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ int poll_consume_pid(poll_priv_t *priv, const int idx, ev_src_t *src, m_evt_pid_
2222
int poll_consume_task(poll_priv_t *priv, const int idx, ev_src_t *src, m_evt_task_t *task_msg);
2323
int poll_consume_thresh(poll_priv_t *priv, const int idx, ev_src_t *src, m_evt_thresh_t *thresh_msg);
2424

25-
int poll_notify_task(poll_priv_t *priv, ev_src_t *src);
26-
int poll_notify_thresh(poll_priv_t *priv, ev_src_t *src);
25+
int poll_notify_userevent(poll_priv_t *priv, ev_src_t *src);

Lib/public/module/cmn.h.in

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,12 @@ typedef struct {
114114
} m_src_pid_t;
115115

116116
typedef struct {
117-
unsigned int tid; // Unique id
117+
int tid; // Unique task id
118118
int (*fn)(void *); // Function to be run on thread
119119
m_thpool_t *thpool; // optional threadpool on which job should run
120120
} m_src_task_t;
121121

122122
typedef struct {
123-
unsigned int id; // Unique id
124123
uint64_t inactive_ms; // if != 0 -> if module is inactive for longer than this, an alarm will be received
125124
double activity_freq; // if != 0 -> if module's activity is higher than this, an alarm will be received
126125
} m_src_thresh_t;

Lib/src.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void *task_thread(void *data) {
8585
ev_src_t *src = (ev_src_t *)data;
8686
M_MOD_CTX(src->mod);
8787
src->task_src.retval = src->task_src.tid.fn((void *)src->userptr);
88-
poll_notify_task(&c->ppriv, src);
88+
poll_notify_userevent(&c->ppriv, src);
8989
pthread_exit(NULL);
9090
}
9191

@@ -135,7 +135,11 @@ static int threshcmp(void *my_data, void *node_data) {
135135
ev_src_t *src = (ev_src_t *)node_data;
136136
const m_src_thresh_t *thr = (const m_src_thresh_t *)my_data;
137137

138-
return thr->id - src->thresh_src.thr.id;
138+
long double my_val = (long double)thr->activity_freq
139+
+ (long double)thr->inactive_ms;
140+
long double their_val = (long double)src->thresh_src.thr.activity_freq
141+
+ (long double)src->thresh_src.thr.inactive_ms;
142+
return my_val - their_val;
139143
}
140144

141145
/** Private API **/

0 commit comments

Comments
 (0)