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
0573b66d
Commit
0573b66d
authored
Jun 29, 2002
by
monty@hundin.mysql.fi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added support for rw_tryrdlock() and rw_trywrlock()
parent
66f86faa
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
73 additions
and
42 deletions
+73
-42
include/my_pthread.h
include/my_pthread.h
+6
-0
include/my_sys.h
include/my_sys.h
+0
-7
mysys/thr_rwlock.c
mysys/thr_rwlock.c
+51
-20
sql/log.cc
sql/log.cc
+4
-4
sql/log_event.cc
sql/log_event.cc
+7
-4
sql/log_event.h
sql/log_event.h
+5
-6
sql/slave.cc
sql/slave.cc
+0
-1
No files found.
include/my_pthread.h
View file @
0573b66d
...
...
@@ -485,6 +485,8 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
#define my_rwlock_init(A,B) pthread_mutex_init((A),(B))
#define rw_rdlock(A) pthread_mutex_lock((A))
#define rw_wrlock(A) pthread_mutex_lock((A))
#define rw_tryrdlock(A) pthread_mutex_trylock((A))
#define rw_trywrlock(A) pthread_mutex_trylock((A))
#define rw_unlock(A) pthread_mutex_unlock((A))
#define rwlock_destroy(A) pthread_mutex_destroy((A))
#elif defined(HAVE_PTHREAD_RWLOCK_RDLOCK)
...
...
@@ -492,6 +494,8 @@ int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp,
#define my_rwlock_init(A,B) pthread_rwlock_init((A),(B))
#define rw_rdlock(A) pthread_rwlock_rdlock(A)
#define rw_wrlock(A) pthread_rwlock_wrlock(A)
#define rw_tryrdlock(A) pthread_mutex_tryrdlock((A))
#define rw_trywrlock(A) pthread_mutex_trywrlock((A))
#define rw_unlock(A) pthread_rwlock_unlock(A)
#define rwlock_destroy(A) pthread_rwlock_destroy(A)
#elif defined(HAVE_RWLOCK_INIT)
...
...
@@ -512,6 +516,8 @@ typedef struct _my_rw_lock_t {
#define rw_lock_t my_rw_lock_t
#define rw_rdlock(A) my_rw_rdlock((A))
#define rw_wrlock(A) my_rw_wrlock((A))
#define rw_tryrdlock(A) my_rw_tryrdlock((A))
#define rw_trywrlock(A) my_rw_trywrlock((A))
#define rw_unlock(A) my_rw_unlock((A))
#define rwlock_destroy(A) my_rwlock_destroy((A))
...
...
include/my_sys.h
View file @
0573b66d
...
...
@@ -750,13 +750,6 @@ byte *my_compress_alloc(const byte *packet, ulong *len, ulong *complen);
ulong
checksum
(
const
byte
*
mem
,
uint
count
);
uint
my_bit_log2
(
ulong
value
);
#if defined(SAFE_MUTEX) && !defined(DBUG_OFF)
#define DBUG_ASSERT_LOCK(lock) DBUG_ASSERT((lock)->count == 1 && \
(lock)->thread == pthread_self())
#else
#define DBUG_ASSERT_LOCK(lock)
#endif
#if defined(_MSC_VER) && !defined(__WIN__)
extern
void
sleep
(
int
sec
);
#endif
...
...
mysys/thr_rwlock.c
View file @
0573b66d
...
...
@@ -19,11 +19,13 @@
#include "mysys_priv.h"
#include <my_pthread.h>
#if defined(THREAD) && !defined(HAVE_PTHREAD_RWLOCK_RDLOCK) && !defined(HAVE_RWLOCK_INIT)
#include <errno.h>
/*
* Source base from Sun Microsystems SPILT, simplified
* for MySQL use -- Joshua Chamas
*/
Source base from Sun Microsystems SPILT, simplified for MySQL use
-- Joshua Chamas
Some cleanup and additional code by Monty
*/
/*
* Multithreaded Demo Source
...
...
@@ -71,7 +73,7 @@ int my_rwlock_init(rw_lock_t *rwp, void *arg __attribute__((unused)))
rwp
->
state
=
0
;
rwp
->
waiters
=
0
;
return
(
0
);
return
(
0
);
}
...
...
@@ -80,8 +82,7 @@ int my_rwlock_destroy(rw_lock_t *rwp)
pthread_mutex_destroy
(
&
rwp
->
lock
);
pthread_cond_destroy
(
&
rwp
->
readers
);
pthread_cond_destroy
(
&
rwp
->
writers
);
return
(
0
);
return
(
0
);
}
...
...
@@ -95,33 +96,64 @@ int my_rw_rdlock(rw_lock_t *rwp)
rwp
->
state
++
;
pthread_mutex_unlock
(
&
rwp
->
lock
);
return
(
0
);
}
return
(
0
);
int
my_rw_tryrdlock
(
rw_lock_t
*
rwp
)
{
int
res
;
pthread_mutex_lock
(
&
rwp
->
lock
);
if
((
rwp
->
state
<
0
)
||
rwp
->
waiters
)
res
=
EBUSY
;
/* Can't get lock */
else
{
res
=
0
;
rwp
->
state
++
;
}
pthread_mutex_unlock
(
&
rwp
->
lock
);
return
(
res
);
}
int
my_rw_wrlock
(
rw_lock_t
*
rwp
)
{
pthread_mutex_lock
(
&
rwp
->
lock
);
rwp
->
waiters
++
;
/* another writer queued */
while
(
rwp
->
state
)
pthread_cond_wait
(
&
rwp
->
writers
,
&
rwp
->
lock
);
while
(
rwp
->
state
)
pthread_cond_wait
(
&
rwp
->
writers
,
&
rwp
->
lock
);
rwp
->
state
=
-
1
;
--
rwp
->
waiters
;
pthread_mutex_unlock
(
&
rwp
->
lock
);
rwp
->
waiters
--
;
pthread_mutex_unlock
(
&
rwp
->
lock
);
return
(
0
);
}
int
my_rw_trywrlock
(
rw_lock_t
*
rwp
)
{
int
res
;
pthread_mutex_lock
(
&
rwp
->
lock
);
if
(
rwp
->
state
)
res
=
EBUSY
;
/* Can't get lock */
else
{
res
=
0
;
rwp
->
state
=
-
1
;
}
pthread_mutex_unlock
(
&
rwp
->
lock
);
return
(
res
);
}
int
my_rw_unlock
(
rw_lock_t
*
rwp
)
{
DBUG_PRINT
(
"rw_unlock"
,
(
"state: %d waiters: %d"
,
rwp
->
state
,
rwp
->
waiters
));
pthread_mutex_lock
(
&
rwp
->
lock
);
if
(
rwp
->
state
==
-
1
)
{
/* writer releasing */
rwp
->
state
=
0
;
/* mark as available */
if
(
rwp
->
state
==
-
1
)
/* writer releasing */
{
rwp
->
state
=
0
;
/* mark as available */
if
(
rwp
->
waiters
)
/* writers queued */
pthread_cond_signal
(
&
rwp
->
writers
);
...
...
@@ -135,8 +167,7 @@ int my_rw_unlock(rw_lock_t *rwp)
}
pthread_mutex_unlock
(
&
rwp
->
lock
);
return
(
0
);
return
(
0
);
}
#endif
sql/log.cc
View file @
0573b66d
...
...
@@ -888,15 +888,15 @@ bool MYSQL_LOG::write(THD *thd,enum enum_server_command command,
bool
MYSQL_LOG
::
write
(
Log_event
*
event_info
)
{
/* In most cases this is only called if 'is_open()' is true */
bool
error
=
0
;
bool
should_rotate
=
0
;
if
(
!
inited
)
// Can't use mutex if not init
return
0
;
VOID
(
pthread_mutex_lock
(
&
LOCK_log
));
/* In most cases this is only called if 'is_open()' is true */
if
(
is_open
())
{
bool
should_rotate
=
0
;
THD
*
thd
=
event_info
->
thd
;
const
char
*
db
=
event_info
->
get_db
();
#ifdef USING_TRANSACTIONS
...
...
@@ -985,9 +985,9 @@ err:
}
if
(
file
==
&
log_file
)
signal_update
();
}
if
(
should_rotate
)
new_file
(
1
);
// inside mutex
}
VOID
(
pthread_mutex_unlock
(
&
LOCK_log
));
return
error
;
}
...
...
sql/log_event.cc
View file @
0573b66d
...
...
@@ -1022,16 +1022,19 @@ char* sql_ex_info::init(char* buf,char* buf_end,bool use_new_format)
#ifndef MYSQL_CLIENT
Load_log_event
::
Load_log_event
(
THD
*
thd
,
sql_exchange
*
ex
,
const
char
*
db_arg
,
const
char
*
table_name_arg
,
List
<
Item
>&
fields_arg
,
enum
enum_duplicates
handle_dup
)
List
<
Item
>&
fields_arg
,
enum
enum_duplicates
handle_dup
)
:
Log_event
(
thd
),
thread_id
(
thd
->
thread_id
),
num_fields
(
0
),
fields
(
0
),
field_lens
(
0
),
field_block_len
(
0
),
table_name
(
table_name_arg
),
field_lens
(
0
),
field_block_len
(
0
),
table_name
(
table_name_arg
?
table_name_arg
:
""
),
db
(
db_arg
),
fname
(
ex
->
file_name
)
{
time_t
end_time
;
time
(
&
end_time
);
exec_time
=
(
ulong
)
(
end_time
-
thd
->
start_time
);
db_len
=
(
db
)
?
(
uint32
)
strlen
(
db
)
:
0
;
table_name_len
=
(
table_name
)
?
(
uint32
)
strlen
(
table_name
)
:
0
;
/* db can never be a zero pointer in 4.0 */
db_len
=
(
uint32
)
strlen
(
db
);
table_name_len
=
(
uint32
)
strlen
(
table_name
);
fname_len
=
(
fname
)
?
(
uint
)
strlen
(
fname
)
:
0
;
sql_ex
.
field_term
=
(
char
*
)
ex
->
field_term
->
ptr
();
sql_ex
.
field_term_len
=
(
uint8
)
ex
->
field_term
->
length
();
...
...
sql/log_event.h
View file @
0573b66d
...
...
@@ -423,8 +423,7 @@ public:
Load_log_event
(
const
char
*
buf
,
int
event_len
,
bool
old_format
);
~
Load_log_event
()
{
}
{}
Log_event_type
get_type_code
()
{
return
sql_ex
.
new_format
()
?
NEW_LOAD_EVENT:
LOAD_EVENT
;
}
int
write_data_header
(
IO_CACHE
*
file
);
...
...
sql/slave.cc
View file @
0573b66d
...
...
@@ -405,7 +405,6 @@ int terminate_slave_thread(THD* thd, pthread_mutex_t* term_lock,
*/
struct
timespec
abstime
;
set_timespec
(
abstime
,
2
);
DBUG_ASSERT_LOCK
(
cond_lock
);
pthread_cond_timedwait
(
term_cond
,
cond_lock
,
&
abstime
);
if
(
*
slave_running
)
{
...
...
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