1
/* Copyright (C) 2003 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
17
#include <ndb_global.h>
18
#include <NdbThread.h>
19
#include <my_pthread.h>
22
#define MAX_THREAD_NAME 16
24
/*#define USE_PTHREAD_EXTRAS*/
26
#ifdef NDB_SHM_TRANSPORTER
27
int g_ndb_shm_signum= 0;
33
char thread_name[MAX_THREAD_NAME];
34
NDB_THREAD_FUNC * func;
39
#ifdef NDB_SHM_TRANSPORTER
40
void NdbThread_set_shm_sigmask(my_bool block)
42
DBUG_ENTER("NdbThread_set_shm_sigmask");
46
DBUG_PRINT("info",("Block signum %d",g_ndb_shm_signum));
48
sigaddset(&mask, g_ndb_shm_signum);
50
pthread_sigmask(SIG_BLOCK, &mask, 0);
52
pthread_sigmask(SIG_UNBLOCK, &mask, 0);
61
ndb_thread_wrapper(void* _ss){
64
DBUG_ENTER("ndb_thread_wrapper");
65
#ifdef NDB_SHM_TRANSPORTER
66
NdbThread_set_shm_sigmask(TRUE);
70
* Block all signals to thread by default
71
* let them go to main process instead
75
pthread_sigmask(SIG_BLOCK, &mask, 0);
80
struct NdbThread * ss = (struct NdbThread *)_ss;
81
ret= (* ss->func)(ss->object);
85
/* will never be reached */
91
struct NdbThread* NdbThread_Create(NDB_THREAD_FUNC *p_thread_func,
92
NDB_THREAD_ARG *p_thread_arg,
93
const NDB_THREAD_STACKSIZE _thread_stack_size,
94
const char* p_thread_name,
95
NDB_THREAD_PRIO thread_prio)
97
struct NdbThread* tmpThread;
99
pthread_attr_t thread_attr;
100
NDB_THREAD_STACKSIZE thread_stack_size= _thread_stack_size * SIZEOF_CHARP/4;
102
DBUG_ENTER("NdbThread_Create");
104
(void)thread_prio; /* remove warning for unused parameter */
106
if (p_thread_func == NULL)
109
tmpThread = (struct NdbThread*)NdbMem_Allocate(sizeof(struct NdbThread));
110
if (tmpThread == NULL)
113
DBUG_PRINT("info",("thread_name: %s", p_thread_name));
115
strnmov(tmpThread->thread_name,p_thread_name,sizeof(tmpThread->thread_name));
117
pthread_attr_init(&thread_attr);
118
#ifdef PTHREAD_STACK_MIN
119
if (thread_stack_size < PTHREAD_STACK_MIN)
120
thread_stack_size = PTHREAD_STACK_MIN;
122
pthread_attr_setstacksize(&thread_attr, thread_stack_size);
123
#ifdef USE_PTHREAD_EXTRAS
124
/* Guard stack overflow with a 2k databuffer */
125
pthread_attr_setguardsize(&thread_attr, 2048);
128
#ifdef PTHREAD_CREATE_JOINABLE /* needed on SCO */
129
pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE);
131
tmpThread->func= p_thread_func;
132
tmpThread->object= p_thread_arg;
133
result = pthread_create(&tmpThread->thread,
139
NdbMem_Free((char *)tmpThread);
143
pthread_attr_destroy(&thread_attr);
144
DBUG_PRINT("exit",("ret: 0x%lx", (long) tmpThread));
145
DBUG_RETURN(tmpThread);
149
void NdbThread_Destroy(struct NdbThread** p_thread)
151
DBUG_ENTER("NdbThread_Destroy");
152
if (*p_thread != NULL){
153
DBUG_PRINT("enter",("*p_thread: 0x%lx", (long) *p_thread));
161
int NdbThread_WaitFor(struct NdbThread* p_wait_thread, void** status)
165
if (p_wait_thread == NULL)
168
if (p_wait_thread->thread == 0)
171
result = pthread_join(p_wait_thread->thread, status);
177
void NdbThread_Exit(void *status)
180
pthread_exit(status);
184
int NdbThread_SetConcurrencyLevel(int level)
186
#ifdef USE_PTHREAD_EXTRAS
187
return pthread_setconcurrency(level);
189
(void)level; /* remove warning for unused parameter */