diff options
author | Björn Gustavsson <[email protected]> | 2019-02-15 09:55:33 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2019-02-15 09:55:33 +0100 |
commit | 595c159823089d0186ec2617c174356d1ff2de65 (patch) | |
tree | 5c0a7ec7cf13c699b10daf284011a7a881e69eed /erts/emulator | |
parent | 741109889b96e92c2edc38f4068e27ac5cd53fb8 (diff) | |
parent | 0ab6149067a82d89e584f862604c1c63578fd5fa (diff) | |
download | otp-595c159823089d0186ec2617c174356d1ff2de65.tar.gz otp-595c159823089d0186ec2617c174356d1ff2de65.tar.bz2 otp-595c159823089d0186ec2617c174356d1ff2de65.zip |
Merge pull request #2140 from bjorng/bjorn/erts/persistent_term-default/ERL-843/OTP-15576
Add persistent_term:get(Key, DefaultValue)
Diffstat (limited to 'erts/emulator')
-rw-r--r-- | erts/emulator/beam/bif.tab | 1 | ||||
-rw-r--r-- | erts/emulator/beam/erl_bif_persistent.c | 17 | ||||
-rw-r--r-- | erts/emulator/test/persistent_term_SUITE.erl | 5 |
3 files changed, 21 insertions, 2 deletions
diff --git a/erts/emulator/beam/bif.tab b/erts/emulator/beam/bif.tab index c96278b10c..8419244832 100644 --- a/erts/emulator/beam/bif.tab +++ b/erts/emulator/beam/bif.tab @@ -738,3 +738,4 @@ bif erts_internal:spawn_system_process/3 bif erlang:integer_to_list/2 bif erlang:integer_to_binary/2 +bif persistent_term:get/2 diff --git a/erts/emulator/beam/erl_bif_persistent.c b/erts/emulator/beam/erl_bif_persistent.c index 9dca768a18..5a78a043ce 100644 --- a/erts/emulator/beam/erl_bif_persistent.c +++ b/erts/emulator/beam/erl_bif_persistent.c @@ -332,6 +332,23 @@ BIF_RETTYPE persistent_term_get_1(BIF_ALIST_1) BIF_ERROR(BIF_P, BADARG); } +BIF_RETTYPE persistent_term_get_2(BIF_ALIST_2) +{ + Eterm key = BIF_ARG_1; + Eterm result = BIF_ARG_2; + HashTable* hash_table = (HashTable *) erts_atomic_read_nob(&the_hash_table); + Uint entry_index; + Eterm term; + + entry_index = lookup(hash_table, key); + term = hash_table->term[entry_index]; + if (is_boxed(term)) { + ASSERT(is_tuple_arity(term, 2)); + result = tuple_val(term)[2]; + } + BIF_RET(result); +} + BIF_RETTYPE persistent_term_erase_1(BIF_ALIST_1) { Eterm key = BIF_ARG_1; diff --git a/erts/emulator/test/persistent_term_SUITE.erl b/erts/emulator/test/persistent_term_SUITE.erl index 58038e24b7..93eb026ced 100644 --- a/erts/emulator/test/persistent_term_SUITE.erl +++ b/erts/emulator/test/persistent_term_SUITE.erl @@ -6,7 +6,7 @@ %% Licensed under the Apache License, Version 2.0 (the "License"); %% you may not use this file except in compliance with the License. %% You may obtain a copy of the License at -%5 +%% %% http://www.apache.org/licenses/LICENSE-2.0 %% %% Unless required by applicable law or agreed to in writing, software @@ -60,7 +60,8 @@ basic(_Config) -> Key = {?MODULE,{key,I}}, true = persistent_term:erase(Key), false = persistent_term:erase(Key), - {'EXIT',{badarg,_}} = (catch persistent_term:get(Key)) + {'EXIT',{badarg,_}} = (catch persistent_term:get(Key)), + {not_present,Key} = persistent_term:get(Key, {not_present,Key}) end || I <- Seq], [] = [P || {{?MODULE,_},_}=P <- pget(Chk)], chk(Chk). |