Skip to content

Commit

Permalink
rename functions in the Toilet module
Browse files Browse the repository at this point in the history
  • Loading branch information
mat-hek committed Jan 20, 2022
1 parent c012874 commit 17e9d17
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/membrane/core/element/demand_controller.ex
Expand Up @@ -86,7 +86,7 @@ defmodule Membrane.Core.Element.DemandController do
demand =
if demand <= div(demand_request_size, 2) and auto_demands_positive?(associated_pads, state) do
if toilet do
Toilet.rinse(toilet, demand_request_size - demand)
Toilet.drain(toilet, demand_request_size - demand)
else
Membrane.Logger.debug_verbose(
"Sending auto demand of size #{demand_request_size - demand} on pad #{inspect(pad_ref)}"
Expand Down
4 changes: 2 additions & 2 deletions lib/membrane/core/element/demand_handler.ex
Expand Up @@ -140,7 +140,7 @@ defmodule Membrane.Core.Element.DemandHandler do
when toilet != nil do
%{other_demand_unit: other_demand_unit} = data
buf_size = Buffer.Metric.from_unit(other_demand_unit).buffers_size(buffers)
Toilet.urinate(toilet, buf_size)
Toilet.fill(toilet, buf_size)
state
end

Expand Down Expand Up @@ -220,7 +220,7 @@ defmodule Membrane.Core.Element.DemandHandler do
state = PadModel.update_data!(state, pad_ref, :demand, &(&1 - size))

if toilet = PadModel.get_data!(state, pad_ref, :toilet) do
Toilet.rinse(toilet, size)
Toilet.drain(toilet, size)
end

BufferController.exec_buffer_callback(pad_ref, buffers, state)
Expand Down
10 changes: 5 additions & 5 deletions lib/membrane/core/element/toilet.ex
@@ -1,7 +1,7 @@
defmodule Membrane.Core.Element.Toilet do
@moduledoc false

# Toilet is an entity that can be urinated to and rinsed. If it's not rinsed on
# Toilet is an entity that can be filled and drained. If it's not drained on
# time and exceeds its capacity, it overflows by logging an error and killing
# the responsible process (passed on the toilet creation).

Expand All @@ -22,15 +22,15 @@ defmodule Membrane.Core.Element.Toilet do
{__MODULE__, :atomics.new(1, []), capacity, responsible_process}
end

@spec urinate(t, non_neg_integer) :: :ok
def urinate({__MODULE__, atomic, capacity, responsible_process}, amount) do
@spec fill(t, non_neg_integer) :: :ok
def fill({__MODULE__, atomic, capacity, responsible_process}, amount) do
size = :atomics.add_get(atomic, 1, amount)
if size > capacity, do: overflow(size, capacity, responsible_process)
:ok
end

@spec rinse(t, non_neg_integer) :: :ok
def rinse({__MODULE__, atomic, _capacity, _responsible_process}, amount) do
@spec drain(t, non_neg_integer) :: :ok
def drain({__MODULE__, atomic, _capacity, _responsible_process}, amount) do
:atomics.sub(atomic, 1, amount)
end

Expand Down

0 comments on commit 17e9d17

Please sign in to comment.