1 /*****************************************************************************
2 
3 Copyright (c) 2011, 2012, Oracle and/or its affiliates. All Rights Reserved.
4 
5 Portions of this file contain modifications contributed and copyrighted by
6 Google, Inc. Those modifications are gratefully acknowledged and are described
7 briefly in the InnoDB documentation. The contributions by Google are
8 incorporated with their permission, and subject to the conditions contained in
9 the file COPYING.Google.
10 
11 Portions of this file contain modifications contributed and copyrighted
12 by Percona Inc.. Those modifications are
13 gratefully acknowledged and are described briefly in the InnoDB
14 documentation. The contributions by Percona Inc. are incorporated with
15 their permission, and subject to the conditions contained in the file
16 COPYING.Percona.
17 
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License, version 2.0,
20 as published by the Free Software Foundation.
21 
22 This program is also distributed with certain software (including
23 but not limited to OpenSSL) that is licensed under separate terms,
24 as designated in a particular file or component or in included license
25 documentation.  The authors of MySQL hereby grant you an additional
26 permission to link the program and your derivative works with the
27 separately licensed software that they have included with MySQL.
28 
29 This program is distributed in the hope that it will be useful,
30 but WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32 GNU General Public License, version 2.0, for more details.
33 
34 You should have received a copy of the GNU General Public License along with
35 this program; if not, write to the Free Software Foundation, Inc.,
36 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
37 
38 *****************************************************************************/
39 
40 /**************************************************//**
41 @file srv/srv0conc.h
42 
43 InnoDB concurrency manager header file
44 
45 Created 2011/04/18 Sunny Bains
46 *******************************************************/
47 
48 #ifndef srv_conc_h
49 #define srv_conc_h
50 
51 /** We are prepared for a situation that we have this many threads waiting for
52 a semaphore inside InnoDB. innobase_start_or_create_for_mysql() sets the
53 value. */
54 
55 extern	ulint	srv_max_n_threads;
56 
57 /** The following controls how many threads we let inside InnoDB concurrently:
58 threads waiting for locks are not counted into the number because otherwise
59 we could get a deadlock. Value of 0 will disable the concurrency check. */
60 
61 extern ulong	srv_thread_concurrency;
62 
63 /*********************************************************************//**
64 Initialise the concurrency management data structures */
65 void
66 srv_conc_init(void);
67 /*===============*/
68 
69 /*********************************************************************//**
70 Free the concurrency management data structures */
71 void
72 srv_conc_free(void);
73 /*===============*/
74 
75 /*********************************************************************//**
76 Puts an OS thread to wait if there are too many concurrent threads
77 (>= srv_thread_concurrency) inside InnoDB. The threads wait in a FIFO queue. */
78 UNIV_INTERN
79 void
80 srv_conc_enter_innodb(
81 /*==================*/
82 	trx_t*	trx);		/*!< in: transaction object associated
83 				with the thread */
84 
85 /*********************************************************************//**
86 This lets a thread enter InnoDB regardless of the number of threads inside
87 InnoDB. This must be called when a thread ends a lock wait. */
88 UNIV_INTERN
89 void
90 srv_conc_force_enter_innodb(
91 /*========================*/
92 	trx_t*	trx);		/*!< in: transaction object associated with
93 				the thread */
94 
95 /*********************************************************************//**
96 This must be called when a thread exits InnoDB in a lock wait or at the
97 end of an SQL statement. */
98 UNIV_INTERN
99 void
100 srv_conc_force_exit_innodb(
101 /*=======================*/
102 	trx_t*	trx);		/*!< in: transaction object associated with
103 				the thread */
104 
105 /*********************************************************************//**
106 Get the count of threads waiting inside InnoDB. */
107 UNIV_INTERN
108 ulint
109 srv_conc_get_waiting_threads(void);
110 /*==============================*/
111 
112 /*********************************************************************//**
113 Get the count of threads active inside InnoDB. */
114 UNIV_INTERN
115 ulint
116 srv_conc_get_active_threads(void);
117 /*==============================*/
118 
119 #endif /* srv_conc_h */
120