void dc_sink_retain(struct dc_sink *sink)
{
- ASSERT(atomic_read(&sink->ref_count) > 0);
- atomic_inc(&sink->ref_count);
+ kref_get(&sink->refcount);
}
-void dc_sink_release(struct dc_sink *sink)
+static void dc_sink_free(struct kref *kref)
{
- ASSERT(atomic_read(&sink->ref_count) > 0);
- atomic_dec(&sink->ref_count);
+ struct dc_sink *sink = container_of(kref, struct dc_sink, refcount);
+ destruct(sink);
+ kfree(sink);
+}
- if (atomic_read(&sink->ref_count) == 0) {
- destruct(sink);
- kfree(sink);
- }
+void dc_sink_release(struct dc_sink *sink)
+{
+ kref_put(&sink->refcount, dc_sink_free);
}
struct dc_sink *dc_sink_create(const struct dc_sink_init_data *init_params)
if (false == construct(sink, init_params))
goto construct_fail;
- atomic_inc(&sink->ref_count);
+ kref_init(&sink->refcount);
return sink;