From 7ef7142f72b59091f73fd4d23270b9399fd07789 Mon Sep 17 00:00:00 2001 From: Tobias Schlager Date: Fri, 13 Sep 2024 09:12:30 +0200 Subject: [PATCH] Restore compatibility with older OTP releases Support is ensured for OTP-24 but it should also still work for older releases (not guaranteed). --- .github/workflows/test.yml | 2 +- README.md | 4 +++- src/eipmi.erl | 20 +++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 78093d8..319e2a2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - otp: [25, 26, 27] + otp: [24, 25, 26, 27] container: image: erlang:${{ matrix.otp }} steps: diff --git a/README.md b/README.md index 0003bb7..24aa594 100644 --- a/README.md +++ b/README.md @@ -227,7 +227,9 @@ History ### Master (4.0.1) -Currently no difference to latest tag. +* Enhance performance of session lookups (thanks to @IslandUsurper) +* Drop (official) support for OTP releases older than 24.3 (currently it should + still work with older versions) ### Version 4.0.0 diff --git a/src/eipmi.erl b/src/eipmi.erl index 74bd7dc..c5e3cd0 100644 --- a/src/eipmi.erl +++ b/src/eipmi.erl @@ -1,5 +1,5 @@ %%%============================================================================= -%%% Copyright (c) 2012-2019 Lindenbaum GmbH +%%% Copyright (c) 2012-2024 Lindenbaum GmbH %%% %%% Permission to use, copy, modify, and/or distribute this software for any %%% purpose with or without fee is hereby granted, provided that the above @@ -1145,10 +1145,8 @@ poll_sel(Session) -> poll_sel(Session = {session, Target, _}, Interval, Clear) when Interval > 0 -> Result = case ets:lookup(eipmi_sessions, {session, Target}) of - [{_, Pid, _}] -> - {ok, Pid}; - [] -> - {error, no_session} + [{_, Pid, _}] -> {ok, Pid}; + [] -> {error, no_session} end, poll_sel(Result, Session, Interval, Clear). poll_sel({ok, Pid}, Session, Interval, Clear) -> @@ -1554,12 +1552,12 @@ stop(_State) -> ok. %% @private %%------------------------------------------------------------------------------ init([]) -> - ets:new(eipmi_sessions, [ - named_table, - public, - {write_concurrency, auto}, - {read_concurrency, true} - ]), + EtsOptions = [named_table, public, {read_concurrency, true}], + try + ets:new(eipmi_sessions, [{write_concurrency, auto} | EtsOptions]) + catch + error:badarg -> ets:new(eipmi_sessions, EtsOptions) + end, TrapPorts = application:get_env(?MODULE, trap_ports, []), {ok, {{one_for_one, 5, 1000}, [trap_spec(Port) || Port <- TrapPorts]}}.