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

Add ets:update_counter #1406

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

TheSobkiewicz
Copy link
Contributor

These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).

SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later
Added support for ets:update_counter/3 and ets:update_counter/4.
https://www.erlang.org/docs/23/man/ets#update_counter-3
Based on:
#1405
Currently this solution doesn't support list of UpdateOp to update multiple counters.

@TheSobkiewicz TheSobkiewicz changed the title Thesobkiewicz/nifs/ets/update counter Add ets:update_counter Dec 17, 2024
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/update_counter branch from 0be618b to 4d64c65 Compare December 19, 2024 13:09
EtsErrorCode ets_update_counter(term ref, term key, term operation, term default_value, term *ret, Context *ctx)
{
struct EtsTable *ets_table = term_is_atom(ref) ? ets_get_table_by_name(&ctx->global->ets, ref, TableAccessWrite) : ets_get_table_by_ref(&ctx->global->ets, term_to_ref_ticks(ref), TableAccessWrite);
if (ets_table == NULL) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the most likely outcome is a found table, I would do if (IS_NULL_PTR(ets_table)) { (that is a short hand of if (UNLIKELY(ets_table == NULL)) {).

src/libAtomVM/ets.c Outdated Show resolved Hide resolved
src/libAtomVM/ets.c Outdated Show resolved Hide resolved
src/libAtomVM/ets.c Outdated Show resolved Hide resolved
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/update_counter branch from 8f58d8e to 7c5d166 Compare January 7, 2025 12:55
Signed-off-by: Tomasz Sobkiewicz <[email protected]>
@TheSobkiewicz TheSobkiewicz force-pushed the thesobkiewicz/nifs/ets/update_counter branch from 7c5d166 to ed57a77 Compare January 7, 2025 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants