From 516dcf8832aa7bcee5562f12a9bb68ec640407a1 Mon Sep 17 00:00:00 2001 From: Lammert Bies Date: Sat, 10 Dec 2016 10:45:55 +0100 Subject: [PATCH] Moved tls_dtor to own file --- Makefile | 1 + src/httplib_tls_dtor.c | 50 ++++++++++++++++++++++++++++++++++++++++++ src/libhttp.c | 17 +------------- 3 files changed, 52 insertions(+), 16 deletions(-) create mode 100644 src/httplib_tls_dtor.c diff --git a/Makefile b/Makefile index 5038e7ec..62a6520a 100644 --- a/Makefile +++ b/Makefile @@ -78,6 +78,7 @@ LIB_SOURCES = src/libhttp.c \ src/httplib_sslize.c \ src/httplib_start.c \ src/httplib_stop.c \ + src/httplib_tls_dtor.c \ src/httplib_uninitialize_ssl.c \ src/httplib_version.c \ src/httplib_websocket_client_thread.c \ diff --git a/src/httplib_tls_dtor.c b/src/httplib_tls_dtor.c new file mode 100644 index 00000000..61dd9657 --- /dev/null +++ b/src/httplib_tls_dtor.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2016 Lammert Bies + * Copyright (c) 2013-2016 the Civetweb developers + * Copyright (c) 2004-2013 Sergey Lyubka + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + + + +#include "libhttp-private.h" + + + +/* + * void XX_httplib_tls_dtor( void *key ); + * + * The function XX_httplib_tls_dtor() is used sets the TLS key for the thread. + */ + +void XX_httplib_tls_dtor( void *key ) { + + struct mg_workerTLS *tls = (struct mg_workerTLS *)key; + /* key == pthread_getspecific(XX_httplib_sTlsKey); */ + + if (tls) { + if (tls->is_master == 2) { + tls->is_master = -3; /* Mark memory as dead */ + XX_httplib_free(tls); + } + } + pthread_setspecific(XX_httplib_sTlsKey, NULL); + +} /* XX_httplib_tls_dtor */ diff --git a/src/libhttp.c b/src/libhttp.c index 9670e0fc..15af0b52 100644 --- a/src/libhttp.c +++ b/src/libhttp.c @@ -8331,6 +8331,7 @@ int XX_httplib_check_acl( struct mg_context *ctx, uint32_t remote_ip ) { #if !defined(_WIN32) + int XX_httplib_set_uid_option( struct mg_context *ctx ) { struct passwd *pw; @@ -8356,19 +8357,3 @@ int XX_httplib_set_uid_option( struct mg_context *ctx ) { } /* XX_httplib_set_uid_option */ #endif /* !_WIN32 */ - - -void XX_httplib_tls_dtor( void *key ) { - - struct mg_workerTLS *tls = (struct mg_workerTLS *)key; - /* key == pthread_getspecific(XX_httplib_sTlsKey); */ - - if (tls) { - if (tls->is_master == 2) { - tls->is_master = -3; /* Mark memory as dead */ - XX_httplib_free(tls); - } - } - pthread_setspecific(XX_httplib_sTlsKey, NULL); - -} /* XX_httplib_tls_dtor */