Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/ukfile: API improvements #1397

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ukfile/file-nops.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ const struct uk_file_ops uk_file_nops = {
.setstat = uk_file_nop_setstat,
.ctl = uk_file_nop_ctl
};

void uk_file_static_release(const struct uk_file *f __maybe_unused,
int what __unused)
{
uk_pr_warn("Destructor called on static file: %p\n", f);
}
54 changes: 47 additions & 7 deletions lib/ukfile/include/uk/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,26 @@ struct uk_file_state {
/* TODO */
};

static inline void uk_file_state_rlock(struct uk_file_state *st)
{
uk_rwlock_rlock(&st->iolock);
}

static inline void uk_file_state_runlock(struct uk_file_state *st)
{
uk_rwlock_runlock(&st->iolock);
}

static inline void uk_file_state_wlock(struct uk_file_state *st)
{
uk_rwlock_wlock(&st->iolock);
}

static inline void uk_file_state_wunlock(struct uk_file_state *st)
{
uk_rwlock_wunlock(&st->iolock);
}

/*
* We define initializers separate from an initial values.
* The former can only be used in (static) variable initializations, while the
Expand All @@ -117,6 +137,26 @@ struct uk_file_state {
((struct uk_file_state)UK_FILE_STATE_INITIALIZER(name))


static inline
uk_pollevent uk_file_state_event_clear(struct uk_file_state *st,
uk_pollevent ev)
{
return uk_pollq_clear(&st->pollq, ev);
}

static inline
uk_pollevent uk_file_state_event_set(struct uk_file_state *st, uk_pollevent ev)
{
return uk_pollq_set(&st->pollq, ev);
}

static inline
uk_pollevent uk_file_state_event_assign(struct uk_file_state *st,
uk_pollevent ev)
{
return uk_pollq_assign(&st->pollq, ev);
}

/*
* Reference count type used by uk_file.
*
Expand Down Expand Up @@ -218,22 +258,22 @@ void uk_file_release_weak(const struct uk_file *f)

static inline void uk_file_rlock(const struct uk_file *f)
{
uk_rwlock_rlock(&f->state->iolock);
uk_file_state_rlock(f->state);
}

static inline void uk_file_runlock(const struct uk_file *f)
{
uk_rwlock_runlock(&f->state->iolock);
uk_file_state_runlock(f->state);
}

static inline void uk_file_wlock(const struct uk_file *f)
{
uk_rwlock_wlock(&f->state->iolock);
uk_file_state_wlock(f->state);
}

static inline void uk_file_wunlock(const struct uk_file *f)
{
uk_rwlock_wunlock(&f->state->iolock);
uk_file_state_wunlock(f->state);
}

/* Events & polling */
Expand All @@ -260,19 +300,19 @@ uk_pollevent uk_file_poll(const struct uk_file *f, uk_pollevent req)
static inline
uk_pollevent uk_file_event_clear(const struct uk_file *f, uk_pollevent clr)
{
return uk_pollq_clear(&f->state->pollq, clr);
return uk_file_state_event_clear(f->state, clr);
}

static inline
uk_pollevent uk_file_event_set(const struct uk_file *f, uk_pollevent set)
{
return uk_pollq_set(&f->state->pollq, set);
return uk_file_state_event_set(f->state, set);
}

static inline
uk_pollevent uk_file_event_assign(const struct uk_file *f, uk_pollevent set)
{
return uk_pollq_assign(&f->state->pollq, set);
return uk_file_state_event_assign(f->state, set);
}

#endif /* __UKFILE_FILE_H__ */
3 changes: 3 additions & 0 deletions lib/ukfile/include/uk/file/nops.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ int uk_file_nop_setstat(const struct uk_file *f,
int uk_file_nop_ctl(const struct uk_file *f, int fam, int req,
uintptr_t arg1, uintptr_t arg2, uintptr_t arg3);

/* Destructor for static files; prints warning & does nothing */
void uk_file_static_release(const struct uk_file *f, int what);

#endif /* __UKFILE_FILE_NOPS_H__ */
Loading