Skip to content

Commit d56ecd5

Browse files
MarcusJGStreetsathoelke
authored andcommitted
Updated following discussion with AT
Updated statements regarding stability of the iterator. Signed-off-by: Marcus Streets <[email protected]>
1 parent 225a337 commit d56ecd5

File tree

1 file changed

+9
-30
lines changed

1 file changed

+9
-30
lines changed

doc/storage/api/api.rst

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -798,13 +798,15 @@ These definitions must be defined in the header file :file:`psa/protected_storag
798798

799799
A caller may initialize multiple iteration contexts at the same time. Each iteration shall be independent. Calling ``psa_ps_iterator_next()`` on one iterator MUST not effect any other open iteration.
800800

801+
An iterator MUST return all data objects whose `uid` matches the filter that are extant when the filter was created, unless these are deleted or renamed before the iteration would return them, or the caller stops before all matching objects have been returned.
802+
803+
A caller may delete a `uid` with ``psa_ps_remove(uid)`` without invalidating the iteration context. the iterator MUST never return a `uid` that has been deleted. However, if the caller is multi-threaded it ia possible another thread may delete a `uid`.
804+
801805
A caller may read the contents of any `uid` with ``psa_ps_get()`` or write with ``psa_ps_set()`` or ``psa_ps_set_extended()`` without invalidating the iteration context.
802806

803-
A caller may create a `uid` with ``psa_ps_set()`` or ``psa_ps_create()`` without invalidating the iteration context, provided the `uid` does *NOT* match the filter. However, if the `uid` matches the filter then any later call to `psa_ps_iterator_next()` fails with `PSA_ERROR_DATA_CORRUPT`.
807+
A caller may create a `uid` with ``psa_ps_set()`` or ``psa_ps_create()`` without invalidating the iteration context. However, the iterator is NOT guaranteed to return the new object, `uid`, the behaviour is dependent on both implementation and identity. In particular, the iterator is not expected to return `uid` if the iteration is already past the point at which it would naturally be returned.
804808

805-
A caller may delete a `uid` with ``psa_ps_remove(uid)`` without invalidating the iteration context, provided the `uid` does *NOT* match the filter. However, if the `uid` matches the filter then any later call to `psa_ps_iterator_next()` fails with `PSA_ERROR_DATA_CORRUPT`.
806-
807-
A caller may call `psa_ps_rename(uid, uid_new)` without invalidating the iteration context, provided the `uid` does *NOT* match the filter, as this is equivalent to calling `psa_ps_remove(uid)`. However, if the `uid` matches the filter then any later call to `psa_ps_iterator_next()` fails with `PSA_ERROR_DATA_CORRUPT`.
809+
A caller may call `psa_ps_rename(uid, uid_new)` without invalidating the iteration context. The iterator must not return `uid`. The iterator is not guaranteed to return `uid_new`, the behaviour is dependent on both implementation and identity.
808810

809811
The following code snippet uses a linked list to store the matching files before iterating over that list and removing them.
810812

@@ -814,23 +816,11 @@ These definitions must be defined in the header file :file:`psa/protected_storag
814816
my_filter = 0x1111 0000 0000 0000
815817
my_length = 0x0020
816818
my_result = NULL
817-
// define a linked list
818-
typedef struct node {
819-
int val;
820-
struct node * next;
821-
} node_t;
822-
// instantiate the head
823-
node_t * head = NULL;
824-
head = (node_t *) malloc(sizeof(node_t));
825-
// and a current item
826-
node_t * current = head;
827819
if psa_ps_iterator_start(my_context, my_filter, my-length, my_result) == PSA_SUCCESS
828820
{
829821
do
830822
{
831-
current->next = (node_t *) malloc(sizeof(node_t));
832-
current->next->val = my_result;
833-
current->next->next = NULL;
823+
// do something with my_result
834824
psa_ps_iterator_next(my_context, my_result)
835825
// we will get an does not exist error when we reach the last item, any other error is a storage fialure
836826
if my_reult <> PSA_ERROR_DOES_NOT_EXIST
@@ -839,19 +829,8 @@ These definitions must be defined in the header file :file:`psa/protected_storag
839829
}
840830
}
841831
while my_result == PSA_SUCCES ;
842-
}
843-
else { /* error handling */}
844-
// we got here so there cannot have been an error and we have the full list.
845-
// now we can iterate over the list and delete the file and throw away the list item
846-
node_t * current = head;
847-
while (current != NULL)
848-
{
849-
psa_ps_remove(current-> val)
850-
head = current
851-
current = current->next;
852-
free(head)
853-
}
854-
};
832+
};
833+
855834
856835
857836

0 commit comments

Comments
 (0)