mirror of
https://github.com/lammertb/libhttp.git
synced 2026-01-27 08:02:47 +03:00
Moved start_thread 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.c \
|
||||
src/httplib_start_thread_with_id.c \
|
||||
src/httplib_stop.c \
|
||||
src/httplib_store_body.c \
|
||||
|
||||
67
src/httplib_start_thread.c
Normal file
67
src/httplib_start_thread.c
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* 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)
|
||||
|
||||
int mg_start_thread(mg_thread_func_t f, void *p) {
|
||||
|
||||
#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
|
||||
/* Compile-time option to control stack size, e.g. -DUSE_STACK_SIZE=16384
|
||||
*/
|
||||
return ((_beginthread((void(__cdecl *)(void *))f, USE_STACK_SIZE, p) == ((uintptr_t)(-1L))) ? -1 : 0);
|
||||
#else
|
||||
return ( (_beginthread((void(__cdecl *)(void *))f, 0, p) == ((uintptr_t)(-1L))) ? -1 : 0);
|
||||
#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
|
||||
|
||||
} /* mg_start_thread */
|
||||
|
||||
#else
|
||||
|
||||
int mg_start_thread(mg_thread_func_t func, void *param) {
|
||||
|
||||
pthread_t thread_id;
|
||||
pthread_attr_t attr;
|
||||
int result;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
|
||||
#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);
|
||||
|
||||
return result;
|
||||
} /* mg_start_thread */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
@@ -2169,18 +2169,6 @@ void XX_httplib_set_close_on_exec( SOCKET sock, struct mg_connection *conn ) {
|
||||
} /* XX_httplib_set_close_on_exec */
|
||||
|
||||
|
||||
int
|
||||
mg_start_thread(mg_thread_func_t f, void *p)
|
||||
{
|
||||
#if defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1)
|
||||
/* Compile-time option to control stack size, e.g. -DUSE_STACK_SIZE=16384
|
||||
*/
|
||||
return ((_beginthread((void(__cdecl *)(void *))f, USE_STACK_SIZE, p) == ((uintptr_t)(-1L))) ? -1 : 0);
|
||||
#else
|
||||
return ( (_beginthread((void(__cdecl *)(void *))f, 0, p) == ((uintptr_t)(-1L))) ? -1 : 0);
|
||||
#endif /* defined(USE_STACK_SIZE) && (USE_STACK_SIZE > 1) */
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int XX_httplib_stat( struct mg_connection *conn, const char *path, struct file *filep ) {
|
||||
@@ -2212,26 +2200,4 @@ void XX_httplib_set_close_on_exec( SOCKET fd, struct mg_connection *conn ) {
|
||||
|
||||
} /* XX_httplib_set_close_on_exec */
|
||||
|
||||
|
||||
int mg_start_thread(mg_thread_func_t func, void *param) {
|
||||
|
||||
pthread_t thread_id;
|
||||
pthread_attr_t attr;
|
||||
int result;
|
||||
|
||||
pthread_attr_init(&attr);
|
||||
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
||||
|
||||
#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);
|
||||
|
||||
return result;
|
||||
} /* mg_start_thread */
|
||||
|
||||
#endif /* _WIN32 */
|
||||
|
||||
Reference in New Issue
Block a user