homed: port to notify_recv() + convert to PidRef (#36557)
Just some refactoring/modernization
This commit is contained in:
+27
-3
@@ -457,12 +457,36 @@ bool pidref_is_automatic(const PidRef *pidref) {
|
||||
return pidref && pid_is_automatic(pidref->pid);
|
||||
}
|
||||
|
||||
static void pidref_hash_func(const PidRef *pidref, struct siphash *state) {
|
||||
void pidref_hash_func(const PidRef *pidref, struct siphash *state) {
|
||||
siphash24_compress_typesafe(pidref->pid, state);
|
||||
}
|
||||
|
||||
static int pidref_compare_func(const PidRef *a, const PidRef *b) {
|
||||
return CMP(a->pid, b->pid);
|
||||
int pidref_compare_func(const PidRef *a, const PidRef *b) {
|
||||
int r;
|
||||
|
||||
assert(a);
|
||||
assert(b);
|
||||
|
||||
r = CMP(pidref_is_set(a), pidref_is_set(b));
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
r = CMP(pidref_is_automatic(a), pidref_is_automatic(b));
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
r = CMP(pidref_is_remote(a), pidref_is_remote(b));
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
r = CMP(a->pid, b->pid);
|
||||
if (r != 0)
|
||||
return r;
|
||||
|
||||
if (a->fd_id != 0 && b->fd_id != 0)
|
||||
return CMP(a->fd_id, b->fd_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
DEFINE_HASH_OPS(pidref_hash_ops, PidRef, pidref_hash_func, pidref_compare_func);
|
||||
|
||||
@@ -108,5 +108,9 @@ int pidref_verify(const PidRef *pidref);
|
||||
|
||||
#define TAKE_PIDREF(p) TAKE_GENERIC((p), PidRef, PIDREF_NULL)
|
||||
|
||||
struct siphash;
|
||||
void pidref_hash_func(const PidRef *pidref, struct siphash *state);
|
||||
int pidref_compare_func(const PidRef *a, const PidRef *b);
|
||||
|
||||
extern const struct hash_ops pidref_hash_ops;
|
||||
extern const struct hash_ops pidref_hash_ops_free; /* Has destructor call for pidref_free(), i.e. expects heap allocated PidRef as keys */
|
||||
|
||||
Reference in New Issue
Block a user