Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mariadb
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
mariadb
Commits
6b36860c
Commit
6b36860c
authored
Jun 27, 2002
by
monty@hundin.mysql.fi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made lock_io_cache() and unlock_io_cache() as functions.
parent
5fa5172b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
54 deletions
+59
-54
include/my_sys.h
include/my_sys.h
+5
-26
mysys/mf_iocache.c
mysys/mf_iocache.c
+54
-28
No files found.
include/my_sys.h
View file @
6b36860c
...
...
@@ -322,29 +322,6 @@ typedef struct st_io_cache_share
my_bool
alloced
;
#endif
}
IO_CACHE_SHARE
;
#define lock_io_cache(info) \
( \
(errno=pthread_mutex_lock(&((info)->share->mutex))) ? -1 : ( \
(info)->share->count ? ( \
--((info)->share->count), \
pthread_cond_wait(&((info)->share->cond), \
&((info)->share->mutex)), \
(++((info)->share->count) ? \
pthread_mutex_unlock(&((info)->share->mutex)) : 0)) \
: 1 ) \
)
#define unlock_io_cache(info) \
( \
pthread_cond_broadcast(&((info)->share->cond)), \
pthread_mutex_unlock (&((info)->share->mutex)) \
)
/* -- to catch errors
#else
#define lock_io_cache(info)
#define unlock_io_cache(info)
*/
#endif
typedef
struct
st_io_cache
/* Used when cacheing files */
...
...
@@ -686,9 +663,11 @@ extern my_bool reinit_io_cache(IO_CACHE *info,enum cache_type type,
extern
int
_my_b_read
(
IO_CACHE
*
info
,
byte
*
Buffer
,
uint
Count
);
#ifdef THREAD
extern
int
_my_b_read_r
(
IO_CACHE
*
info
,
byte
*
Buffer
,
uint
Count
);
extern
int
init_io_cache_share
(
IO_CACHE
*
info
,
extern
void
init_io_cache_share
(
IO_CACHE
*
info
,
IO_CACHE_SHARE
*
s
,
uint
num_threads
);
extern
int
remove_io_thread
(
IO_CACHE
*
info
);
extern
void
remove_io_thread
(
IO_CACHE
*
info
);
int
lock_io_cache
(
IO_CACHE
*
);
void
unlock_io_cache
(
IO_CACHE
*
);
#endif
extern
int
_my_b_seq_read
(
IO_CACHE
*
info
,
byte
*
Buffer
,
uint
Count
);
extern
int
_my_b_net_read
(
IO_CACHE
*
info
,
byte
*
Buffer
,
uint
Count
);
...
...
mysys/mf_iocache.c
View file @
6b36860c
...
...
@@ -424,32 +424,62 @@ int _my_b_read(register IO_CACHE *info, byte *Buffer, uint Count)
DBUG_RETURN
(
0
);
}
#ifdef THREAD
int
init_io_cache_share
(
IO_CACHE
*
info
,
IO_CACHE_SHARE
*
s
,
uint
num_threads
)
/* Initialzie multi-thread usage of the IO cache */
void
init_io_cache_share
(
IO_CACHE
*
info
,
IO_CACHE_SHARE
*
s
,
uint
num_threads
)
{
DBUG_ASSERT
(
info
->
type
==
READ_CACHE
);
pthread_mutex_init
(
&
s
->
mutex
,
MY_MUTEX_INIT_FAST
);
pthread_cond_init
(
&
s
->
cond
,
0
);
pthread_mutex_init
(
&
s
->
mutex
,
MY_MUTEX_INIT_FAST
);
pthread_cond_init
(
&
s
->
cond
,
0
);
s
->
count
=
num_threads
;
s
->
active
=
0
;
/* to catch errors */
info
->
share
=
s
;
info
->
read_function
=
_my_b_read_r
;
}
int
remove_io_thread
(
IO_CACHE
*
info
)
void
remove_io_thread
(
IO_CACHE
*
info
)
{
if
(
errno
=
pthread_mutex_lock
(
&
info
->
share
->
mutex
))
return
-
1
;
pthread_mutex_lock
(
&
info
->
share
->
mutex
);
if
(
!
info
->
share
->
count
--
)
pthread_cond_signal
(
&
info
->
share
->
cond
);
pthread_mutex_unlock
(
&
info
->
share
->
mutex
);
pthread_cond_signal
(
&
info
->
share
->
cond
);
pthread_mutex_unlock
(
&
info
->
share
->
mutex
);
}
int
lock_io_cache
(
IO_CACHE
*
info
)
{
pthread_mutex_lock
(
&
info
->
share
->
mutex
);
if
(
!
info
->
share
->
count
)
return
1
;
info
->
share
->
count
--
;
pthread_cond_wait
(
&
((
info
)
->
share
->
cond
),
&
((
info
)
->
share
->
mutex
));
if
(
!++
info
->
share
->
count
)
return
1
;
pthread_mutex_unlock
(
&
info
->
share
->
mutex
);
return
0
;
}
void
unlock_io_cache
(
IO_CACHE
*
info
)
{
pthread_cond_broadcast
(
&
info
->
share
->
cond
);
pthread_mutex_unlock
(
&
info
->
share
->
mutex
);
}
/*
Read from the io cache in a thread safe manner
*/
#define IO_ROUND_UP(X) (((X)+IO_SIZE-1) & ~(IO_SIZE-1))
#define IO_ROUND_DN(X) ( (X) & ~(IO_SIZE-1))
int
_my_b_read_r
(
register
IO_CACHE
*
info
,
byte
*
Buffer
,
uint
Count
)
{
my_off_t
pos_in_file
;
int
length
,
diff_length
,
read_len
;
u
int
length
,
diff_length
,
read_len
;
DBUG_ENTER
(
"_my_b_read_r"
);
if
((
read_len
=
(
uint
)
(
info
->
read_end
-
info
->
read_pos
)))
...
...
@@ -459,26 +489,23 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
Buffer
+=
read_len
;
Count
-=
read_len
;
}
#define IO_ROUND_UP(X) (((X)+IO_SIZE-1) & ~(IO_SIZE-1))
#define IO_ROUND_DN(X) ( (X) & ~(IO_SIZE-1))
while
(
Count
)
{
int
cnt
,
len
;
while
(
Count
)
{
uint
cnt
,
len
;
pos_in_file
=
info
->
pos_in_file
+
(
uint
)(
info
->
read_end
-
info
->
buffer
);
diff_length
=
pos_in_file
&
(
IO_SIZE
-
1
);
diff_length
=
(
uint
)
(
pos_in_file
&
(
IO_SIZE
-
1
)
);
length
=
IO_ROUND_UP
(
Count
+
diff_length
)
-
diff_length
;
length
=
(
length
<=
info
->
read_length
)
?
length
=
(
(
length
<=
info
->
read_length
)
?
length
+
IO_ROUND_DN
(
info
->
read_length
-
length
)
:
length
-
IO_ROUND_UP
(
length
-
info
->
read_length
)
;
length
-
IO_ROUND_UP
(
length
-
info
->
read_length
)
)
;
if
(
lock_io_cache
(
info
))
{
info
->
share
->
active
=
info
;
if
(
info
->
seek_not_done
)
/* File touched, do seek */
VOID
(
my_seek
(
info
->
file
,
pos_in_file
,
MY_SEEK_SET
,
MYF
(
0
)));
len
=
my_read
(
info
->
file
,
info
->
buffer
,
length
,
info
->
myflags
);
info
->
read_end
=
info
->
buffer
+
(
len
==
-
1
?
0
:
len
);
info
->
read_end
=
info
->
buffer
+
(
len
==
(
uint
)
-
1
?
0
:
len
);
info
->
error
=
(
len
==
length
?
0
:
len
);
info
->
pos_in_file
=
pos_in_file
;
unlock_io_cache
(
info
);
...
...
@@ -494,7 +521,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
info
->
seek_not_done
=
0
;
if
(
info
->
error
)
{
info
->
error
=
read_len
;
info
->
error
=
(
int
)
read_len
;
DBUG_RETURN
(
1
);
}
cnt
=
(
len
>
Count
)
?
Count
:
len
;
...
...
@@ -508,6 +535,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
}
#endif
/*
Do sequential read from the SEQ_READ_APPEND cache
we do this in three stages:
...
...
@@ -1072,13 +1100,11 @@ int end_io_cache(IO_CACHE *info)
#ifdef THREAD
/* simple protection against multi-close: destroying share first */
if
(
info
->
share
)
if
(
pthread_cond_destroy
(
&
info
->
share
->
cond
)
|
pthread_mutex_destroy
(
&
info
->
share
->
mutex
))
{
DBUG_RETURN
(
1
);
}
else
pthread_cond_destroy
(
&
info
->
share
->
cond
);
pthread_mutex_destroy
(
&
info
->
share
->
mutex
);
info
->
share
=
0
;
}
#endif
if
((
pre_close
=
info
->
pre_close
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment