locking: Simplify maintenance / debugging /documentation

Update the Public API equivalent of the libcoap functions that need to be
called when locked with a name suffix of _lkd.

Move matching Public API functions out of coap_threadsafe.c to be coded
just ahead of the newly renamed _lkd function.

Properly define the _lkd function in the appropriate _internal.h file for
documentation, removing the #defines from coap_threadsafe_internal.h.

Tag all the Public API functions that have a _lkd function with COAP_API.
COAP_API can then be defined as to what should be done for that function.

Check libcoap library does not call the original Public API function when
it should be calling the _lkd function by marking the Public API not _lkd
functions as deprecated during the libcoap library build.
[Done by the new COAP_API being defined as __attribute__((deprecated)).]

Work in progress for all the functions that need to be multi-thread safe.
This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2024-05-22 11:40:44 +01:00
1 parent e8e44bf6aa
commit 91d8fad663
30 files changed
+874 -523

No files matched your search

+53 -5
View File
@@ -44,10 +44,22 @@ is_cache_key(uint16_t option_type, size_t cache_ignore_count,
return 1;
}
int
COAP_API int
coap_cache_ignore_options(coap_context_t *ctx,
const uint16_t *options,
size_t count) {
int ret;
coap_lock_lock(ctx, return 0);
ret = coap_cache_ignore_options_lkd(ctx, options, count);
coap_lock_unlock(ctx);
return ret;
}
int
coap_cache_ignore_options_lkd(coap_context_t *ctx,
const uint16_t *options,
size_t count) {
coap_lock_check_locked(ctx);
if (ctx->cache_ignore_options) {
coap_free_type(COAP_STRING, ctx->cache_ignore_options);
@@ -149,11 +161,25 @@ coap_delete_cache_key(coap_cache_key_t *cache_key) {
coap_free_type(COAP_CACHE_KEY, cache_key);
}
coap_cache_entry_t *
COAP_API coap_cache_entry_t *
coap_new_cache_entry(coap_session_t *session, const coap_pdu_t *pdu,
coap_cache_record_pdu_t record_pdu,
coap_cache_session_based_t session_based,
unsigned int idle_timeout) {
coap_cache_entry_t *cache;
coap_lock_lock(session->context, return NULL);
cache = coap_new_cache_entry_lkd(session, pdu, record_pdu, session_based,
idle_timeout);
coap_lock_unlock(session->context);
return cache;
}
coap_cache_entry_t *
coap_new_cache_entry_lkd(coap_session_t *session, const coap_pdu_t *pdu,
coap_cache_record_pdu_t record_pdu,
coap_cache_session_based_t session_based,
unsigned int idle_timeout) {
coap_cache_entry_t *entry;
coap_lock_check_locked(session->context);
@@ -195,8 +221,18 @@ coap_new_cache_entry(coap_session_t *session, const coap_pdu_t *pdu,
return entry;
}
coap_cache_entry_t *
COAP_API coap_cache_entry_t *
coap_cache_get_by_key(coap_context_t *ctx, const coap_cache_key_t *cache_key) {
coap_cache_entry_t *cache;
coap_lock_lock(ctx, return NULL);
cache = coap_cache_get_by_key_lkd(ctx, cache_key);
coap_lock_unlock(ctx);
return cache;
}
coap_cache_entry_t *
coap_cache_get_by_key_lkd(coap_context_t *ctx, const coap_cache_key_t *cache_key) {
coap_cache_entry_t *cache_entry = NULL;
coap_lock_check_locked(ctx);
@@ -211,10 +247,22 @@ coap_cache_get_by_key(coap_context_t *ctx, const coap_cache_key_t *cache_key) {
return cache_entry;
}
coap_cache_entry_t *
COAP_API coap_cache_entry_t *
coap_cache_get_by_pdu(coap_session_t *session,
const coap_pdu_t *request,
coap_cache_session_based_t session_based) {
coap_cache_entry_t *entry;
coap_lock_lock(session->context, return NULL);
entry = coap_cache_get_by_pdu_lkd(session, request, session_based);
coap_lock_unlock(session->context);
return entry;
}
coap_cache_entry_t *
coap_cache_get_by_pdu_lkd(coap_session_t *session,
const coap_pdu_t *request,
coap_cache_session_based_t session_based) {
coap_cache_key_t *cache_key = coap_cache_derive_key(session, request, session_based);
coap_cache_entry_t *cache_entry;
@@ -222,7 +270,7 @@ coap_cache_get_by_pdu(coap_session_t *session,
return NULL;
coap_lock_check_locked(session->context);
cache_entry = coap_cache_get_by_key(session->context, cache_key);
cache_entry = coap_cache_get_by_key_lkd(session->context, cache_key);
coap_delete_cache_key(cache_key);
if (cache_entry && cache_entry->idle_timeout > 0) {
coap_ticks(&cache_entry->expire_ticks);