GNU libmicrohttpd 1.0.2
Loading...
Searching...
No Matches
mhd_threads.h File Reference

Header for platform-independent threads abstraction. More...

#include "mhd_options.h"
#include <stdio.h>
Include dependency graph for mhd_threads.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  MHD_thread_handle_struct_
struct  MHD_thread_ID_struct_
struct  _MHD_thread_handle_ID_

Macros

#define MHD_thread_handle_set_invalid_(handle_ptr)
#define MHD_thread_handle_set_native_(handle_ptr, native_val)
#define MHD_thread_handle_is_valid_(handle_var)
#define MHD_thread_handle_get_native_(handle_var)
#define MHD_thread_ID_native_is_current_thread_(id)
#define MHD_thread_ID_set_invalid_(ID_ptr)
#define MHD_thread_ID_set_native_(ID_ptr, native_val)
#define MHD_thread_ID_is_valid_(ID_var)
#define MHD_thread_ID_get_native_(ID_var)
#define MHD_thread_ID_is_current_thread_(ID_var)
#define MHD_thread_ID_set_current_thread_(ID_ptr)
#define MHD_thread_handle_ID_set_invalid_(hndl_id_ptr)
#define MHD_thread_handle_ID_is_valid_handle_(hndl_id)
#define MHD_thread_handle_ID_set_native_handle_(hndl_id_ptr, native_val)
#define MHD_thread_handle_ID_get_native_handle_(hndl_id)
#define MHD_thread_handle_ID_is_valid_ID_(hndl_id)
#define MHD_thread_handle_ID_set_current_thread_ID_(hndl_id_ptr)
#define MHD_thread_handle_ID_is_current_thread_(hndl_id)
#define MHD_thread_handle_ID_join_thread_(hndl_id)
#define MHD_create_named_thread_(t, n, s, r, a)

Typedefs

typedef struct MHD_thread_handle_struct_ MHD_thread_handle_
typedef struct MHD_thread_ID_struct_ MHD_thread_ID_
typedef struct _MHD_thread_handle_ID_ MHD_thread_handle_ID_
typedef MHD_THRD_RTRN_TYPE_(MHD_THRD_CALL_SPEC_ * MHD_THREAD_START_ROUTINE_) (void *cls)

Functions

int MHD_create_thread_ (MHD_thread_handle_ID_ *handle_id, size_t stack_size, MHD_THREAD_START_ROUTINE_ start_routine, void *arg)

Detailed Description

Header for platform-independent threads abstraction.

Author
Karlson2k (Evgeny Grin)

Provides basic abstraction for threads. Any functions can be implemented as macro on some platforms unless explicitly marked otherwise. Any function argument can be skipped in macro, so avoid variable modification in function parameters.

Warning
Unlike pthread functions, most of functions return nonzero on success.

Definition in file mhd_threads.h.

Macro Definition Documentation

◆ MHD_create_named_thread_

#define MHD_create_named_thread_ ( t,
n,
s,
r,
a )
Value:
MHD_create_thread_ ((t),(s),(r),(a))
int MHD_create_thread_(MHD_thread_handle_ID_ *handle_id, size_t stack_size, MHD_THREAD_START_ROUTINE_ start_routine, void *arg)

Definition at line 545 of file mhd_threads.h.

Referenced by MHD_start_daemon_va(), and new_connection_process_().

◆ MHD_thread_handle_get_native_

#define MHD_thread_handle_get_native_ ( handle_var)
Value:
((handle_var).native)

Get native handle value from handle_var variable

Definition at line 181 of file mhd_threads.h.

◆ MHD_thread_handle_ID_get_native_handle_

#define MHD_thread_handle_ID_get_native_handle_ ( hndl_id)
Value:
#define MHD_thread_handle_get_native_(handle_var)

Get native thread handle from MHD_thread_handle_ID_ variable.

Definition at line 467 of file mhd_threads.h.

◆ MHD_thread_handle_ID_is_current_thread_

#define MHD_thread_handle_ID_is_current_thread_ ( hndl_id)

◆ MHD_thread_handle_ID_is_valid_handle_

#define MHD_thread_handle_ID_is_valid_handle_ ( hndl_id)
Value:
MHD_thread_handle_is_valid_((hndl_id).handle)
#define MHD_thread_handle_is_valid_(handle_var)

Check whether thread handle is valid. To be used in threads other then the thread specified by hndl_id.

Definition at line 444 of file mhd_threads.h.

Referenced by MHD_create_thread_(), MHD_get_daemon_info(), MHD_run_wait(), and MHD_stop_daemon().

◆ MHD_thread_handle_ID_is_valid_ID_

#define MHD_thread_handle_ID_is_valid_ID_ ( hndl_id)
Value:
#define MHD_thread_ID_is_valid_(ID_var)

Check whether thread ID is valid. To be used in the thread itself.

Definition at line 474 of file mhd_threads.h.

Referenced by call_handlers(), and internal_run_from_select().

◆ MHD_thread_handle_ID_join_thread_

#define MHD_thread_handle_ID_join_thread_ ( hndl_id)
Value:
MHD_join_thread_(MHD_thread_handle_ID_get_native_handle_(hndl_id))
#define MHD_thread_handle_ID_get_native_handle_(hndl_id)

Wait until specified thread is ended and free thread handle on success.

Parameters
hndl_id_handle with ID to watch
Returns
nonzero on success, zero otherwise

Definition at line 506 of file mhd_threads.h.

Referenced by close_all_connections(), MHD_cleanup_connections(), and MHD_stop_daemon().

◆ MHD_thread_handle_ID_set_current_thread_ID_

#define MHD_thread_handle_ID_set_current_thread_ID_ ( hndl_id_ptr)
Value:
MHD_thread_ID_set_current_thread_(&((hndl_id_ptr)->ID))
#define MHD_thread_ID_set_current_thread_(ID_ptr)

Set current thread ID in the variable pointed by hndl_id_ptr

Definition at line 489 of file mhd_threads.h.

◆ MHD_thread_handle_ID_set_invalid_

#define MHD_thread_handle_ID_set_invalid_ ( hndl_id_ptr)
Value:
(MHD_thread_handle_set_invalid_(&((hndl_id_ptr)->handle)), \
MHD_thread_ID_set_invalid_(&((hndl_id_ptr)->ID)))
#define MHD_thread_handle_set_invalid_(handle_ptr)

Set MHD_thread_handle_ID_ to invalid value

Definition at line 436 of file mhd_threads.h.

Referenced by MHD_create_thread_(), MHD_start_daemon_va(), and new_connection_prepare_().

◆ MHD_thread_handle_ID_set_native_handle_

#define MHD_thread_handle_ID_set_native_handle_ ( hndl_id_ptr,
native_val )
Value:
MHD_thread_handle_set_native_(&((hndl_id_ptr)->handle),native_val)
#define MHD_thread_handle_set_native_(handle_ptr, native_val)

Set native handle in variable pointed by hndl_id_ptr to native_val value

Definition at line 451 of file mhd_threads.h.

Referenced by MHD_create_thread_().

◆ MHD_thread_handle_is_valid_

#define MHD_thread_handle_is_valid_ ( handle_var)
Value:
((handle_var).valid)

Check whether native handle value is set in handle_var variable

Definition at line 176 of file mhd_threads.h.

◆ MHD_thread_handle_set_invalid_

#define MHD_thread_handle_set_invalid_ ( handle_ptr)
Value:
((handle_ptr)->valid = false)

Set variable pointed by handle_ptr to invalid (unset) value

Definition at line 165 of file mhd_threads.h.

◆ MHD_thread_handle_set_native_

#define MHD_thread_handle_set_native_ ( handle_ptr,
native_val )
Value:
((handle_ptr)->valid = true, (handle_ptr)->native = native_val)

Set native handle in variable pointed by handle_ptr to native_val value

Definition at line 171 of file mhd_threads.h.

◆ MHD_thread_ID_get_native_

#define MHD_thread_ID_get_native_ ( ID_var)
Value:
((ID_var).native)

Get native ID value from ID_var variable

Definition at line 316 of file mhd_threads.h.

◆ MHD_thread_ID_is_current_thread_

#define MHD_thread_ID_is_current_thread_ ( ID_var)
Value:
MHD_thread_ID_native_is_current_thread_((ID_var).native))

Check whether ID_var variable is equal current thread

Definition at line 321 of file mhd_threads.h.

◆ MHD_thread_ID_is_valid_

#define MHD_thread_ID_is_valid_ ( ID_var)
Value:
((ID_var).valid)

Check whether native ID value is set in ID_var variable

Definition at line 311 of file mhd_threads.h.

◆ MHD_thread_ID_native_is_current_thread_

#define MHD_thread_ID_native_is_current_thread_ ( id)
Value:
MHD_thread_ID_native_equal_(id, MHD_thread_ID_native_current_())

Check whether specified thread ID matches current thread.

Parameters
idthe thread ID to match
Returns
nonzero on match, zero otherwise

Definition at line 263 of file mhd_threads.h.

◆ MHD_thread_ID_set_current_thread_

#define MHD_thread_ID_set_current_thread_ ( ID_ptr)
Value:
MHD_thread_ID_set_native_(ID_ptr,MHD_thread_ID_native_current_())
#define MHD_thread_ID_set_native_(ID_ptr, native_val)

Set current thread ID in variable pointed by ID_ptr

Definition at line 361 of file mhd_threads.h.

◆ MHD_thread_ID_set_invalid_

#define MHD_thread_ID_set_invalid_ ( ID_ptr)
Value:
((ID_ptr)->valid = false)

Set variable pointed by ID_ptr to invalid (unset) value

Definition at line 300 of file mhd_threads.h.

◆ MHD_thread_ID_set_native_

#define MHD_thread_ID_set_native_ ( ID_ptr,
native_val )
Value:
((ID_ptr)->valid = true, (ID_ptr)->native = native_val)

Set native ID in variable pointed by ID_ptr to native_val value

Definition at line 306 of file mhd_threads.h.

Typedef Documentation

◆ MHD_thread_handle_

Type with thread handle that can be set to invalid value

Definition at line 160 of file mhd_threads.h.

◆ MHD_thread_handle_ID_

Definition at line 426 of file mhd_threads.h.

◆ MHD_thread_ID_

Type with thread ID that can be set to invalid value

Definition at line 295 of file mhd_threads.h.

◆ MHD_THREAD_START_ROUTINE_

typedef MHD_THRD_RTRN_TYPE_(MHD_THRD_CALL_SPEC_ * MHD_THREAD_START_ROUTINE_) (void *cls)

Signature of main function for a thread.

Parameters
clsclosure argument for the function
Returns
termination code from the thread

Definition at line 523 of file mhd_threads.h.

Function Documentation

◆ MHD_create_thread_()

int MHD_create_thread_ ( MHD_thread_handle_ID_ * handle_id,
size_t stack_size,
MHD_THREAD_START_ROUTINE_ start_routine,
void * arg )

Create a thread and set the attributes according to our options.

If thread is created, thread handle must be freed by MHD_join_thread_().

Parameters
handle_idhandle to initialise
stack_sizesize of stack for new thread, 0 for default
start_routinemain function of thread
argargument for start_routine
Returns
non-zero on success; zero otherwise (with errno set)

Definition at line 187 of file mhd_threads.c.

References mhd_assert, MHD_thread_handle_ID_is_valid_handle_, MHD_thread_handle_ID_set_invalid_, MHD_thread_handle_ID_set_native_handle_, NULL, and UINT_MAX.