File: my_thread.h

package info (click to toggle)
mariadb 1%3A11.8.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 772,520 kB
  • sloc: ansic: 2,414,714; cpp: 1,791,394; asm: 381,336; perl: 62,905; sh: 49,647; pascal: 40,897; java: 39,363; python: 20,791; yacc: 20,432; sql: 17,907; xml: 12,344; ruby: 8,544; cs: 6,542; makefile: 6,145; ada: 1,879; lex: 1,193; javascript: 996; objc: 80; tcl: 73; awk: 46; php: 22
file content (123 lines) | stat: -rw-r--r-- 3,063 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef STORAGE_PERFSCHEMA_MY_THREAD_INCLUDED
#define STORAGE_PERFSCHEMA_MY_THREAD_INCLUDED

#include <my_pthread.h>
#include <m_string.h>
#include "pfs_config.h"

#ifdef HAVE_SYS_GETTID
#include <sys/types.h>
#include <sys/syscall.h>
#endif

#ifdef HAVE_PTHREAD_GETTHREADID_NP
#include <pthread_np.h>
#endif

#if defined(HAVE_INTEGER_PTHREAD_SELF)
#include <cstdint>
#endif

typedef pthread_t my_thread_handle;
typedef pthread_attr_t my_thread_attr_t;
#if defined(HAVE_PTHREAD_THREADID_NP) || defined(HAVE_GETTID) || defined(HAVE_SYS_GETTID) || defined(HAVE_GETTHRID)
typedef pid_t my_thread_os_id_t;
#elif defined(_WIN32)
typedef uint32 my_thread_os_id_t;
#elif defined(HAVE_PTHREAD_GETTHREADID_NP)
typedef int my_thread_os_id_t;
#elif defined(HAVE_INTEGER_PTHREAD_SELF)
typedef uintptr_t my_thread_os_id_t;
#else
typedef unsigned long long my_thread_os_id_t;
#endif

#define LOCK_plugin_delete LOCK_plugin
static inline int my_thread_create(my_thread_handle *thread,
        const my_thread_attr_t *attr, void *(*start_routine)(void *), void *arg)
{ return pthread_create(thread, attr, start_routine, arg); }

static inline my_thread_os_id_t my_thread_os_id()
{
#ifdef HAVE_PTHREAD_THREADID_NP
  /*
    macOS.

    Be careful to use this version first, and to not use SYS_gettid on macOS,
    as SYS_gettid has a different meaning compared to linux gettid().
  */
  uint64_t tid64;
  pthread_threadid_np(nullptr, &tid64);
  return (pid_t)tid64;
#else
#ifdef HAVE_GETTID
  /* Linux glibc-2.30+ */
  return gettid();
#else
#ifdef HAVE_SYS_GETTID
  /*
    Linux before glibc-2.30
    See man gettid
  */
  return syscall(SYS_gettid);
#else
#ifdef _WIN32
  /* Windows */
  return GetCurrentThreadId();
#else
#ifdef HAVE_PTHREAD_GETTHREADID_NP
  /* FreeBSD 10.2 */
  return pthread_getthreadid_np();
#else
#ifdef HAVE_GETTHRID
  /* OpenBSD */
  return getthrid();
#else
#ifdef HAVE_INTEGER_PTHREAD_SELF
  /* NetBSD, and perhaps something else, fallback. */
  return (my_thread_os_id_t) pthread_self();
#else
  /* Feature not available. */
  return 0;
#endif /* HAVE_INTEGER_PTHREAD_SELF */
#endif /* HAVE_GETTHRID */
#endif /* HAVE_PTHREAD_GETTHREADID_NP */
#endif /* _WIN32 */
#endif /* HAVE_SYS_GETTID */
#endif /* HAVE_GETTID */
#endif /* HAVE_PTHREAD_THREADID_NP */
}

#define CHANNEL_NAME_LENGTH MAX_CONNECTION_NAME

enum enum_mysql_show_scope
{
  SHOW_SCOPE_UNDEF,
  SHOW_SCOPE_GLOBAL,
  SHOW_SCOPE_SESSION,
  SHOW_SCOPE_ALL
};
typedef enum enum_mysql_show_scope SHOW_SCOPE;

#define SHOW_VAR_MAX_NAME_LEN NAME_LEN

static inline char *my_stpnmov(char *dst, const char *src, size_t n)
{ return strnmov(dst, src, n); }

static inline size_t bin_to_hex_str(char *to, size_t to_len,
                                    const char *from, size_t from_len)
{
  if (to_len < from_len * 2 + 1)
    return 0 ;
  for (size_t i=0; i < from_len; i++, from++)
  {
    *to++=_dig_vec_upper[((unsigned char) *from) >> 4];
    *to++=_dig_vec_upper[((unsigned char) *from) & 0xF];
  }
  *to= '\0';
  return from_len * 2 + 1;
}

#define thd_get_psi(X) ((X)->get_psi())

#endif