17
17
*****************************************************************************/
19
/**************************************************//**
19
/******************************************************
21
20
The thread local storage
23
22
Created 10/5/1995 Heikki Tuuri
44
43
the thread local storage, just add it to struct thr_local_struct in the
47
/** Mutex protecting thr_local_hash */
46
/* Mutex protecting the local storage hash table */
48
47
static mutex_t thr_local_mutex;
50
/** The hash table. The module is not yet initialized when it is NULL. */
49
/* The hash table. The module is not yet initialized when it is NULL. */
51
50
static hash_table_t* thr_local_hash = NULL;
53
/** Thread local data */
54
typedef struct thr_local_struct thr_local_t;
56
/** @brief Thread local data.
57
The private data for each thread should be put to
52
/* The private data for each thread should be put to
58
53
the structure below and the accessor functions written
55
typedef struct thr_local_struct thr_local_t;
60
57
struct thr_local_struct{
61
os_thread_id_t id; /*!< id of the thread which owns this struct */
62
os_thread_t handle; /*!< operating system handle to the thread */
63
ulint slot_no;/*!< the index of the slot in the thread table
58
os_thread_id_t id; /* id of the thread which owns this struct */
59
os_thread_t handle; /* operating system handle to the thread */
60
ulint slot_no;/* the index of the slot in the thread table
65
ibool in_ibuf;/*!< TRUE if the the thread is doing an ibuf
62
ibool in_ibuf;/* TRUE if the the thread is doing an ibuf
67
hash_node_t hash; /*!< hash chain node */
68
ulint magic_n;/*!< magic number (THR_LOCAL_MAGIC_N) */
64
hash_node_t hash; /* hash chain node */
71
/** The value of thr_local_struct::magic_n */
72
68
#define THR_LOCAL_MAGIC_N 1231234
74
/*******************************************************************//**
75
Returns the local storage struct for a thread.
76
@return local storage */
70
/***********************************************************************
71
Returns the local storage struct for a thread. */
81
os_thread_id_t id) /*!< in: thread id of the thread */
76
/* out: local storage */
77
os_thread_id_t id) /* in: thread id of the thread */
83
79
thr_local_t* local;
110
/*******************************************************************//**
111
Gets the slot number in the thread table of a thread.
112
@return slot number */
106
/***********************************************************************
107
Gets the slot number in the thread table of a thread. */
115
110
thr_local_get_slot_no(
116
111
/*==================*/
117
os_thread_id_t id) /*!< in: thread id of the thread */
112
/* out: slot number */
113
os_thread_id_t id) /* in: thread id of the thread */
120
116
thr_local_t* local;
133
/*******************************************************************//**
129
/***********************************************************************
134
130
Sets the slot number in the thread table of a thread. */
137
133
thr_local_set_slot_no(
138
134
/*==================*/
139
os_thread_id_t id, /*!< in: thread id of the thread */
140
ulint slot_no)/*!< in: slot number */
135
os_thread_id_t id, /* in: thread id of the thread */
136
ulint slot_no)/* in: slot number */
142
138
thr_local_t* local;
150
146
mutex_exit(&thr_local_mutex);
153
/*******************************************************************//**
149
/***********************************************************************
154
150
Returns pointer to the 'in_ibuf' field within the current thread local
156
@return pointer to the in_ibuf field */
159
154
thr_local_get_in_ibuf_field(void)
160
155
/*=============================*/
156
/* out: pointer to the in_ibuf field */
162
158
thr_local_t* local;
170
166
return(&(local->in_ibuf));
173
/*******************************************************************//**
169
/***********************************************************************
174
170
Creates a local storage struct for the calling new thread. */
200
196
mutex_exit(&thr_local_mutex);
203
/*******************************************************************//**
199
/***********************************************************************
204
200
Frees the local storage struct for the specified thread. */
209
os_thread_id_t id) /*!< in: thread id */
205
os_thread_id_t id) /* in: thread id */
211
207
thr_local_t* local;