MySQL  8.0.17
Source Code Documentation
thread.c File Reference
#include "config.h"
#include "memcached.h"
#include <assert.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <signal.h>
#include <pthread.h>
#include <fcntl.h>

Classes

struct  conn_queue_item
 
struct  conn_queue
 

Macros

#define ITEMS_PER_ALLOC   64
 
#define INNODB_MEMCACHED
 

Typedefs

typedef struct conn_queue_item CQ_ITEM
 
typedef struct conn_queue CQ
 

Functions

void my_thread_end ()
 Deallocate memory used by the thread for book-keeping. More...
 
void my_thread_init ()
 Allocate thread specific memory for the thread, used by mysys and dbug. More...
 
static void thread_libevent_process (int fd, short which, void *arg)
 
static void libevent_tap_process (int fd, short which, void *arg)
 
static void cq_init (CQ *cq)
 
static CQ_ITEMcq_pop (CQ *cq)
 
static void cq_push (CQ *cq, CQ_ITEM *item)
 
static CQ_ITEMcqi_new (void)
 
static void cqi_free (CQ_ITEM *item)
 
static void create_worker (void *(*func)(void *), void *arg, pthread_t *id)
 
bool create_notification_pipe (LIBEVENT_THREAD *me)
 
static void setup_dispatcher (struct event_base *main_base, void(*dispatcher_callback)(int, short, void *))
 
static void setup_thread (LIBEVENT_THREAD *me, bool tap)
 
static void * worker_libevent (void *arg)
 
int number_of_pending (conn *c, conn *list)
 
bool has_cycle (conn *c)
 
bool list_contains (conn *haystack, conn *needle)
 
connlist_remove (conn *haystack, conn *needle)
 
size_t list_to_array (conn **dest, size_t max_items, conn **l)
 
void enlist_conn (conn *c, conn **list)
 
void finalize_list (conn **list, size_t items)
 
static bool is_thread_me (LIBEVENT_THREAD *thr)
 
void notify_io_complete (const void *cookie, ENGINE_ERROR_CODE status)
 
void dispatch_conn_new (SOCKET sfd, STATE_FUNC init_state, int event_flags, int read_buffer_size, enum network_transport transport)
 
int is_listen_thread ()
 
void notify_dispatcher (void)
 
void STATS_LOCK ()
 
void STATS_UNLOCK ()
 
void threadlocal_stats_clear (struct thread_stats *stats)
 
void threadlocal_stats_reset (struct thread_stats *thread_stats)
 
void threadlocal_stats_aggregate (struct thread_stats *thread_stats, struct thread_stats *stats)
 
void slab_stats_aggregate (struct thread_stats *stats, struct slab_stats *out)
 
void thread_init (int nthr, struct event_base *main_base, void(*dispatcher_callback)(int, short, void *))
 
void threads_shutdown (void)
 
void notify_thread (LIBEVENT_THREAD *thread)
 

Variables

static char devnull [8192]
 
volatile sig_atomic_t memcached_shutdown
 
pthread_mutex_t conn_lock = PTHREAD_MUTEX_INITIALIZER
 
static pthread_mutex_t stats_lock
 
static CQ_ITEMcqi_freelist
 
static pthread_mutex_t cqi_freelist_lock
 
static LIBEVENT_THREAD dispatcher_thread
 
static int nthreads
 
static LIBEVENT_THREADthreads
 
static pthread_t * thread_ids
 
LIBEVENT_THREADtap_thread
 
static int init_count = 0
 
static pthread_mutex_t init_lock
 
static pthread_cond_t init_cond
 
volatile rel_time_t current_time
 
static int last_thread = -1
 

Macro Definition Documentation

◆ INNODB_MEMCACHED

#define INNODB_MEMCACHED

◆ ITEMS_PER_ALLOC

#define ITEMS_PER_ALLOC   64

Typedef Documentation

◆ CQ

typedef struct conn_queue CQ

◆ CQ_ITEM

typedef struct conn_queue_item CQ_ITEM

Function Documentation

◆ cq_init()

static void cq_init ( CQ cq)
static

◆ cq_pop()

static CQ_ITEM* cq_pop ( CQ cq)
static

◆ cq_push()

static void cq_push ( CQ cq,
CQ_ITEM item 
)
static

◆ cqi_free()

static void cqi_free ( CQ_ITEM item)
static

◆ cqi_new()

static CQ_ITEM* cqi_new ( void  )
static

◆ create_notification_pipe()

bool create_notification_pipe ( LIBEVENT_THREAD me)

◆ create_worker()

static void create_worker ( void *(*)(void *)  func,
void *  arg,
pthread_t *  id 
)
static

◆ dispatch_conn_new()

void dispatch_conn_new ( SOCKET  sfd,
STATE_FUNC  init_state,
int  event_flags,
int  read_buffer_size,
enum network_transport  transport 
)

◆ enlist_conn()

void enlist_conn ( conn c,
conn **  list 
)

◆ finalize_list()

void finalize_list ( conn **  list,
size_t  items 
)

◆ has_cycle()

bool has_cycle ( conn c)

◆ is_listen_thread()

int is_listen_thread ( void  )

◆ is_thread_me()

static bool is_thread_me ( LIBEVENT_THREAD thr)
static

◆ libevent_tap_process()

static void libevent_tap_process ( int  fd,
short  which,
void *  arg 
)
static

◆ list_contains()

bool list_contains ( conn haystack,
conn needle 
)

◆ list_remove()

conn* list_remove ( conn haystack,
conn needle 
)

◆ list_to_array()

size_t list_to_array ( conn **  dest,
size_t  max_items,
conn **  l 
)

◆ my_thread_end()

void my_thread_end ( void  )

Deallocate memory used by the thread for book-keeping.

Note
This may be called multiple times for a thread. This happens for example when one calls 'mysql_server_init()' mysql_server_end() and then ends with a mysql_end().

◆ my_thread_init()

void my_thread_init ( void  )

Allocate thread specific memory for the thread, used by mysys and dbug.

Note
This function may called multiple times for a thread, for example if one uses my_init() followed by mysql_server_init().
Return values
falseok
trueFatal error; mysys/dbug functions can't be used

◆ notify_dispatcher()

void notify_dispatcher ( void  )

◆ notify_io_complete()

void notify_io_complete ( const void *  cookie,
ENGINE_ERROR_CODE  status 
)

◆ notify_thread()

void notify_thread ( LIBEVENT_THREAD thread)

◆ number_of_pending()

int number_of_pending ( conn c,
conn list 
)

◆ setup_dispatcher()

static void setup_dispatcher ( struct event_base *  main_base,
void(*)(int, short, void *)  dispatcher_callback 
)
static

◆ setup_thread()

static void setup_thread ( LIBEVENT_THREAD me,
bool  tap 
)
static

◆ slab_stats_aggregate()

void slab_stats_aggregate ( struct thread_stats stats,
struct slab_stats out 
)

◆ STATS_LOCK()

void STATS_LOCK ( void  )

◆ STATS_UNLOCK()

void STATS_UNLOCK ( void  )

◆ thread_init()

void thread_init ( int  nthr,
struct event_base *  main_base,
void(*)(int, short, void *)  dispatcher_callback 
)

◆ thread_libevent_process()

static void thread_libevent_process ( int  fd,
short  which,
void *  arg 
)
static

◆ threadlocal_stats_aggregate()

void threadlocal_stats_aggregate ( struct thread_stats thread_stats,
struct thread_stats stats 
)

◆ threadlocal_stats_clear()

void threadlocal_stats_clear ( struct thread_stats stats)

◆ threadlocal_stats_reset()

void threadlocal_stats_reset ( struct thread_stats thread_stats)

◆ threads_shutdown()

void threads_shutdown ( void  )

◆ worker_libevent()

static void* worker_libevent ( void *  arg)
static

Variable Documentation

◆ conn_lock

pthread_mutex_t conn_lock = PTHREAD_MUTEX_INITIALIZER

◆ cqi_freelist

CQ_ITEM* cqi_freelist
static

◆ cqi_freelist_lock

pthread_mutex_t cqi_freelist_lock
static

◆ current_time

volatile rel_time_t current_time

◆ devnull

char devnull[8192]
static

◆ dispatcher_thread

LIBEVENT_THREAD dispatcher_thread
static

◆ init_cond

pthread_cond_t init_cond
static

◆ init_count

int init_count = 0
static

◆ init_lock

pthread_mutex_t init_lock
static

◆ last_thread

int last_thread = -1
static

◆ memcached_shutdown

volatile sig_atomic_t memcached_shutdown

◆ nthreads

int nthreads
static

◆ stats_lock

pthread_mutex_t stats_lock
static

◆ tap_thread

LIBEVENT_THREAD* tap_thread

◆ thread_ids

pthread_t* thread_ids
static

◆ threads

LIBEVENT_THREAD* threads
static