1
- /* Copyright (C) 2003 MySQL AB
1
+ /* Copyright (C) 2003 MySQL AB, 2008-2009 Sun Microsystems, Inc
2
2
3
3
This program is free software; you can redistribute it and/or modify
4
4
it under the terms of the GNU General Public License as published by
95
95
*/
96
96
97
97
/* Variables for archive share methods */
98
- pthread_mutex_t archive_mutex;
98
+ mysql_mutex_t archive_mutex;
99
99
static HASH archive_open_tables;
100
100
101
101
/* The file extension */
@@ -145,6 +145,28 @@ static uchar* archive_get_key(ARCHIVE_SHARE *share, size_t *length,
145
145
return (uchar*) share->table_name ;
146
146
}
147
147
148
+ #ifdef HAVE_PSI_INTERFACE
149
+ PSI_mutex_key az_key_mutex_archive_mutex, az_key_mutex_ARCHIVE_SHARE_mutex;
150
+
151
+ static PSI_mutex_info all_archive_mutexes[]=
152
+ {
153
+ { &az_key_mutex_archive_mutex, " archive_mutex" , PSI_FLAG_GLOBAL},
154
+ { &az_key_mutex_ARCHIVE_SHARE_mutex, " ARCHIVE_SHARE::mutex" , 0 }
155
+ };
156
+
157
+ static void init_archive_psi_keys (void )
158
+ {
159
+ const char * category= " archive" ;
160
+ int count;
161
+
162
+ if (PSI_server == NULL )
163
+ return ;
164
+
165
+ count= array_elements (all_archive_mutexes);
166
+ PSI_server->register_mutex (category, all_archive_mutexes, count);
167
+ }
168
+
169
+ #endif /* HAVE_PSI_INTERFACE */
148
170
149
171
/*
150
172
Initialize the archive handler.
@@ -163,19 +185,24 @@ int archive_db_init(void *p)
163
185
DBUG_ENTER (" archive_db_init" );
164
186
handlerton *archive_hton;
165
187
188
+ #ifdef HAVE_PSI_INTERFACE
189
+ init_archive_psi_keys ();
190
+ #endif
191
+
166
192
archive_hton= (handlerton *)p;
167
193
archive_hton->state = SHOW_OPTION_YES;
168
194
archive_hton->db_type = DB_TYPE_ARCHIVE_DB;
169
195
archive_hton->create = archive_create_handler;
170
196
archive_hton->flags = HTON_NO_FLAGS;
171
197
archive_hton->discover = archive_discover;
172
198
173
- if (pthread_mutex_init (&archive_mutex, MY_MUTEX_INIT_FAST))
199
+ if (mysql_mutex_init (az_key_mutex_archive_mutex,
200
+ &archive_mutex, MY_MUTEX_INIT_FAST))
174
201
goto error;
175
202
if (my_hash_init (&archive_open_tables, table_alias_charset, 32 , 0 , 0 ,
176
203
(my_hash_get_key) archive_get_key, 0 , 0 ))
177
204
{
178
- pthread_mutex_destroy (&archive_mutex);
205
+ mysql_mutex_destroy (&archive_mutex);
179
206
}
180
207
else
181
208
{
@@ -199,7 +226,7 @@ int archive_db_init(void *p)
199
226
int archive_db_done (void *p)
200
227
{
201
228
my_hash_free (&archive_open_tables);
202
- pthread_mutex_destroy (&archive_mutex);
229
+ mysql_mutex_destroy (&archive_mutex);
203
230
204
231
return 0 ;
205
232
}
@@ -313,7 +340,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
313
340
uint length;
314
341
DBUG_ENTER (" ha_archive::get_share" );
315
342
316
- pthread_mutex_lock (&archive_mutex);
343
+ mysql_mutex_lock (&archive_mutex);
317
344
length=(uint ) strlen (table_name);
318
345
319
346
if (!(share=(ARCHIVE_SHARE*) my_hash_search (&archive_open_tables,
@@ -328,7 +355,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
328
355
&tmp_name, length+1 ,
329
356
NullS))
330
357
{
331
- pthread_mutex_unlock (&archive_mutex);
358
+ mysql_mutex_unlock (&archive_mutex);
332
359
*rc= HA_ERR_OUT_OF_MEM;
333
360
DBUG_RETURN (NULL );
334
361
}
@@ -346,7 +373,8 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
346
373
/*
347
374
We will use this lock for rows.
348
375
*/
349
- pthread_mutex_init (&share->mutex ,MY_MUTEX_INIT_FAST);
376
+ mysql_mutex_init (az_key_mutex_ARCHIVE_SHARE_mutex,
377
+ &share->mutex , MY_MUTEX_INIT_FAST);
350
378
351
379
/*
352
380
We read the meta file, but do not mark it dirty. Since we are not
@@ -372,7 +400,7 @@ ARCHIVE_SHARE *ha_archive::get_share(const char *table_name, int *rc)
372
400
share->use_count ));
373
401
if (share->crashed )
374
402
*rc= HA_ERR_CRASHED_ON_USAGE;
375
- pthread_mutex_unlock (&archive_mutex);
403
+ mysql_mutex_unlock (&archive_mutex);
376
404
377
405
DBUG_RETURN (share);
378
406
}
@@ -391,12 +419,12 @@ int ha_archive::free_share()
391
419
share->table_name_length , share->table_name ,
392
420
share->use_count ));
393
421
394
- pthread_mutex_lock (&archive_mutex);
422
+ mysql_mutex_lock (&archive_mutex);
395
423
if (!--share->use_count )
396
424
{
397
425
my_hash_delete (&archive_open_tables, (uchar*) share);
398
426
thr_lock_delete (&share->lock );
399
- pthread_mutex_destroy (&share->mutex );
427
+ mysql_mutex_destroy (&share->mutex );
400
428
/*
401
429
We need to make sure we don't reset the crashed state.
402
430
If we open a crashed file, wee need to close it as crashed unless
@@ -411,7 +439,7 @@ int ha_archive::free_share()
411
439
}
412
440
my_free ((uchar*) share, MYF (0 ));
413
441
}
414
- pthread_mutex_unlock (&archive_mutex);
442
+ mysql_mutex_unlock (&archive_mutex);
415
443
416
444
DBUG_RETURN (rc);
417
445
}
@@ -651,7 +679,7 @@ int ha_archive::create(const char *name, TABLE *table_arg,
651
679
*/
652
680
if ((frm_file= my_open (name_buff, O_RDONLY, MYF (0 ))) > 0 )
653
681
{
654
- if (!my_fstat (frm_file, &file_stat, MYF (MY_WME)))
682
+ if (!mysql_file_fstat (frm_file, &file_stat, MYF (MY_WME)))
655
683
{
656
684
frm_ptr= (uchar *)my_malloc (sizeof (uchar) * file_stat.st_size , MYF (0 ));
657
685
if (frm_ptr)
@@ -800,7 +828,7 @@ int ha_archive::write_row(uchar *buf)
800
828
ha_statistic_increment (&SSV::ha_write_count);
801
829
if (table->timestamp_field_type & TIMESTAMP_AUTO_SET_ON_INSERT)
802
830
table->timestamp_field ->set_time ();
803
- pthread_mutex_lock (&share->mutex );
831
+ mysql_mutex_lock (&share->mutex );
804
832
805
833
if (!share->archive_write_open )
806
834
if (init_archive_writer ())
@@ -883,7 +911,7 @@ int ha_archive::write_row(uchar *buf)
883
911
share->rows_recorded ++;
884
912
rc= real_write_row (buf, &(share->archive_write ));
885
913
error:
886
- pthread_mutex_unlock (&share->mutex );
914
+ mysql_mutex_unlock (&share->mutex );
887
915
if (read_buf)
888
916
my_free ((uchar*) read_buf, MYF (0 ));
889
917
@@ -1383,7 +1411,7 @@ int ha_archive::optimize(THD* thd, HA_CHECK_OPT* check_opt)
1383
1411
azclose (&archive);
1384
1412
1385
1413
// make the file we just wrote be our data file
1386
- rc = my_rename (writer_filename,share->data_file_name ,MYF (0 ));
1414
+ rc= my_rename (writer_filename, share->data_file_name , MYF (0 ));
1387
1415
1388
1416
1389
1417
DBUG_RETURN (rc);
@@ -1467,7 +1495,7 @@ int ha_archive::info(uint flag)
1467
1495
If dirty, we lock, and then reset/flush the data.
1468
1496
I found that just calling azflush() doesn't always work.
1469
1497
*/
1470
- pthread_mutex_lock (&share->mutex );
1498
+ mysql_mutex_lock (&share->mutex );
1471
1499
if (share->dirty == TRUE )
1472
1500
{
1473
1501
if (share->dirty == TRUE )
@@ -1483,7 +1511,7 @@ int ha_archive::info(uint flag)
1483
1511
cause the number to be inaccurate.
1484
1512
*/
1485
1513
stats.records = share->rows_recorded ;
1486
- pthread_mutex_unlock (&share->mutex );
1514
+ mysql_mutex_unlock (&share->mutex );
1487
1515
1488
1516
stats.deleted = 0 ;
1489
1517
@@ -1508,9 +1536,9 @@ int ha_archive::info(uint flag)
1508
1536
if (flag & HA_STATUS_AUTO)
1509
1537
{
1510
1538
init_archive_reader ();
1511
- pthread_mutex_lock (&share->mutex );
1539
+ mysql_mutex_lock (&share->mutex );
1512
1540
azflush (&archive, Z_SYNC_FLUSH);
1513
- pthread_mutex_unlock (&share->mutex );
1541
+ mysql_mutex_unlock (&share->mutex );
1514
1542
stats.auto_increment_value = archive.auto_increment + 1 ;
1515
1543
}
1516
1544
@@ -1578,9 +1606,9 @@ int ha_archive::check(THD* thd, HA_CHECK_OPT* check_opt)
1578
1606
1579
1607
old_proc_info= thd_proc_info (thd, " Checking table" );
1580
1608
/* Flush any waiting data */
1581
- pthread_mutex_lock (&share->mutex );
1609
+ mysql_mutex_lock (&share->mutex );
1582
1610
azflush (&(share->archive_write ), Z_SYNC_FLUSH);
1583
- pthread_mutex_unlock (&share->mutex );
1611
+ mysql_mutex_unlock (&share->mutex );
1584
1612
1585
1613
/*
1586
1614
Now we will rewind the archive file so that we are positioned at the
0 commit comments