/** De-allocates the session. Must only be called once the underlying IO handle
* and timer are already closed, otherwise may leak resources. */
-static void session2_free(struct session2 *s)
+void session2_free(struct session2 *s)
{
const struct protolayer_grp *grp = &protolayer_grps[s->proto];
for (size_t i = 0; i < grp->num_layers; i++) {
free(s);
}
-void session2_inc_refs(struct session2 *s)
-{
- kr_assert(s->ref_count < INT_MAX);
- s->ref_count++;
-}
-
-void session2_dec_refs(struct session2 *s)
-{
- if (kr_fails_assert(s->ref_count > 0)) {
- session2_free(s);
- return;
- }
-
- s->ref_count--;
- if (s->ref_count <= 0)
- session2_free(s);
-}
+extern inline void session2_inc_refs(struct session2 *s);
+extern inline void session2_dec_refs(struct session2 *s);
int session2_start_read(struct session2 *session)
{
size_t layer_param_count,
bool outgoing);
+
+void session2_free(struct session2 *s);
/** Used for counting references from unclosed libUV handles owned by the session and from defer.
* Once all owned handles are closed and nothing is deferred, the session is freed. */
-void session2_inc_refs(struct session2 *s);
-void session2_dec_refs(struct session2 *s);
+inline void session2_inc_refs(struct session2 *s)
+{
+ kr_assert(s->ref_count < INT_MAX);
+ s->ref_count++;
+}
+inline void session2_dec_refs(struct session2 *s)
+{
+ if (kr_fails_assert(s->ref_count > 0)) {
+ session2_free(s);
+ return;
+ }
+
+ s->ref_count--;
+ if (s->ref_count <= 0)
+ session2_free(s);
+}
/** Allocates and initializes a new session with the specified protocol layer
* group, using a *libuv handle* as its transport. */
bool kr_dbg_assertion_abort = DBG_ASSERTION_ABORT;
int kr_dbg_assertion_fork = DBG_ASSERTION_FORK;
+
+// Non-inline instance to allow warn-free use of kr_assert() etc. in other `extern inline`.
+extern inline bool kr_assert_func(bool result, const char *expr, const char *func,
+ const char *file, int line);
+
void kr_fail(bool is_fatal, const char *expr, const char *func, const char *file, int line)
{
const int errno_orig = errno;
/** Use kr_require(), kr_assert() or kr_fails_assert() instead of directly this function. */
__attribute__ ((warn_unused_result))
-static inline bool kr_assert_func(bool result, const char *expr, const char *func,
- const char *file, int line)
+KR_EXPORT inline bool kr_assert_func(bool result, const char *expr, const char *func,
+ const char *file, int line)
{
if (!result)
kr_fail(false, expr, func, file, line);