MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
myrg_locking.c
1 /* Copyright (C) 2000-2002 MySQL AB
2 
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.
6 
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.
11 
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */
15 
16 /*
17  Lock databases against read or write.
18 */
19 
20 #include "myrg_def.h"
21 
22 int myrg_lock_database(MYRG_INFO *info, int lock_type)
23 {
24  int error,new_error;
26 
27  error=0;
28  for (file=info->open_tables ; file != info->end_table ; file++)
29  {
30 #ifdef __WIN__
31  /*
32  Make sure this table is marked as owned by a merge table.
33  The semaphore is never released as long as table remains
34  in memory. This should be refactored into a more generic
35  approach (observer pattern)
36  */
37  (file->table)->owned_by_merge = TRUE;
38 #endif
39  if ((new_error=mi_lock_database(file->table,lock_type)))
40  {
41  error=new_error;
42  if (lock_type != F_UNLCK)
43  {
44  while (--file >= info->open_tables)
45  mi_lock_database(file->table, F_UNLCK);
46  break;
47  }
48  }
49  }
50  return(error);
51 }