mirror of
https://github.com/lammertb/libhttp.git
synced 2026-01-27 08:02:47 +03:00
Moved start_thread_with_id to own file
This commit is contained in:
1
Makefile
1
Makefile
@@ -167,6 +167,7 @@ LIB_SOURCES = src/libhttp.c \
|
||||
src/httplib_ssl_use_pem_file.c \
|
||||
src/httplib_sslize.c \
|
||||
src/httplib_start.c \
|
||||
src/httplib_start_thread_with_id.c \
|
||||
src/httplib_stop.c \
|
||||
src/httplib_store_body.c \
|
||||
src/httplib_substitute_index_file.c \
|
||||
|
||||
76
src/httplib_start_thread_with_id.c
Normal file
76
src/httplib_start_thread_with_id.c
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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"
|
||||
|
||||
|
||||
|
||||
#if defined(_WIN32)
|
||||
|
||||
/* Start a thread storing the thread context. */
|
||||
int XX_httplib_start_thread_with_id( unsigned(__stdcall *f)(void *), void *p, pthread_t *threadidptr ) {
|
||||
|
||||
uintptr_t uip;
|
||||
HANDLE threadhandle;
|
||||
int result = -1;
|
||||
|
||||
uip = _beginthreadex(NULL, 0, (unsigned(__stdcall *)(void *))f, p, 0, NULL);
|
||||
threadhandle = (HANDLE)uip;
|
||||
if ((uip != (uintptr_t)(-1L)) && (threadidptr != NULL)) {
|
||||
*threadidptr = threadhandle;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} /* XX_httplib_start_thread_with_id */
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/* Start a thread storing the thread context. */
|
||||
int XX_httplib_start_thread_with_id( mg_thread_func_t func, void *param, pthread_t *threadidptr ) {
|
||||
|
||||
pthread_t thread_id;
|
||||
pthread_attr_t attr;
|
||||
int result;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
|
||||
#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
|
||||
/* Compile-time option to control stack size,
|
||||
* e.g. -DUSE_STACK_SIZE=16384 */
|
||||
pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
|
||||
#endif /* defined(USE_STACK_SIZE) && USE_STACK_SIZE > 1 */
|
||||
|
||||
result = pthread_create(&thread_id, &attr, func, param);
|
||||
pthread_attr_destroy(&attr);
|
||||
if ((result == 0) && (threadidptr != NULL)) *threadidptr = thread_id;
|
||||
return result;
|
||||
|
||||
} /* XX_httplib_start_thread_with_id */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
@@ -2181,26 +2181,6 @@ mg_start_thread(mg_thread_func_t f, void *p)
|
||||
#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
|
||||
}
|
||||
|
||||
|
||||
/* Start a thread storing the thread context. */
|
||||
int XX_httplib_start_thread_with_id( unsigned(__stdcall *f)(void *), void *p, pthread_t *threadidptr ) {
|
||||
|
||||
uintptr_t uip;
|
||||
HANDLE threadhandle;
|
||||
int result = -1;
|
||||
|
||||
uip = _beginthreadex(NULL, 0, (unsigned(__stdcall *)(void *))f, p, 0, NULL);
|
||||
threadhandle = (HANDLE)uip;
|
||||
if ((uip != (uintptr_t)(-1L)) && (threadidptr != NULL)) {
|
||||
*threadidptr = threadhandle;
|
||||
result = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
} /* XX_httplib_start_thread_with_id */
|
||||
|
||||
|
||||
#else
|
||||
|
||||
int XX_httplib_stat( struct mg_connection *conn, const char *path, struct file *filep ) {
|
||||
@@ -2254,27 +2234,4 @@ int mg_start_thread(mg_thread_func_t func, void *param) {
|
||||
return result;
|
||||
} /* mg_start_thread */
|
||||
|
||||
|
||||
/* Start a thread storing the thread context. */
|
||||
int XX_httplib_start_thread_with_id( mg_thread_func_t func, void *param, pthread_t *threadidptr ) {
|
||||
|
||||
pthread_t thread_id;
|
||||
pthread_attr_t attr;
|
||||
int result;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
|
||||
#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
|
||||
/* Compile-time option to control stack size,
|
||||
* e.g. -DUSE_STACK_SIZE=16384 */
|
||||
pthread_attr_setstacksize(&attr, USE_STACK_SIZE);
|
||||
#endif /* defined(USE_STACK_SIZE) && USE_STACK_SIZE > 1 */
|
||||
|
||||
result = pthread_create(&thread_id, &attr, func, param);
|
||||
pthread_attr_destroy(&attr);
|
||||
if ((result == 0) && (threadidptr != NULL)) *threadidptr = thread_id;
|
||||
return result;
|
||||
|
||||
} /* XX_httplib_start_thread_with_id */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
Reference in New Issue
Block a user