coap_cleanup: Support multiple usage

This commit is contained in:
Jon Shallow authored and Jon Shallow committed 2024-06-21 16:08:41 +01:00
1 parent b1d305c842
commit 63c5077cf0
3 files changed
+13 -7

No files matched your search

+6 -2
View File
@@ -55,8 +55,12 @@ until *coap_cleanup*() is called.
The *coap_cleanup*() function is used to cleanup / free any information set
up by the *coap_startup*() function and should be the last *coap_**() function
called. It is possible to call *coap_startup*() after *coap_cleanup*() to
re-initialize the libcoap logic.
called. The only safe function that can be called after *coap_cleanup*() is
*coap_startup*() to re-initialize the libcoap logic.
*NOTE:* Calling *coap_cleanup*() in one thread while continuing to use other
*coap_**() function calls in a different thread is not supported - even if they
are using a different coap_context_t.
*NOTE:* All other libcoap cleanups should called prior to *coap_cleanup*(), e.g.
*coap_free_context*(3).
+3 -1
View File
@@ -4453,6 +4453,9 @@ coap_startup(void) {
void
coap_cleanup(void) {
if (!coap_started)
return;
coap_started = 0;
#if defined(HAVE_WINSOCK2_H)
WSACleanup();
#elif defined(WITH_CONTIKI)
@@ -4469,7 +4472,6 @@ coap_cleanup(void) {
coap_mutex_destroy(&m_persist_add);
#endif /* COAP_CONSTRAINED_STACK */
coap_debug_reset();
coap_started = 0;
}
void
+4 -4
View File
@@ -33,8 +33,8 @@ coap_lock_unlock_func(coap_lock_t *lock, const char *file, int line) {
int
coap_lock_lock_func(coap_lock_t *lock, int force, const char *file, int line) {
if (!force && lock->being_freed) {
/* context is going away */
if ((!force && lock->being_freed) || !coap_started) {
/* context is going away or libcoap not initialized with coap_startup() */
return 0;
}
if (coap_mutex_trylock(&lock->mutex)) {
@@ -88,8 +88,8 @@ coap_lock_unlock_func(coap_lock_t *lock) {
int
coap_lock_lock_func(coap_lock_t *lock, int force) {
if (!force && lock->being_freed) {
/* context is going away */
if ((!force && lock->being_freed) || !coap_started) {
/* context is going away or libcoap not initialized with coap_startup() */
return 0;
}
/*