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
2426972c
Commit
2426972c
authored
Jun 30, 2002
by
bell@sanja.is.com.ua
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
semaphores replaced by rwlock
parent
e5b02fbe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
45 deletions
+31
-45
include/my_pthread.h
include/my_pthread.h
+2
-2
sql/sql_cache.cc
sql/sql_cache.cc
+27
-36
sql/sql_cache.h
sql/sql_cache.h
+1
-6
sql/sql_handler.cc
sql/sql_handler.cc
+1
-1
No files found.
include/my_pthread.h
View file @
2426972c
...
...
@@ -494,8 +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_tryrdlock(A) pthread_
rwlock
_tryrdlock((A))
#define rw_trywrlock(A) pthread_
rwlock
_trywrlock((A))
#define rw_unlock(A) pthread_rwlock_unlock(A)
#define rwlock_destroy(A) pthread_rwlock_destroy(A)
#elif defined(HAVE_RWLOCK_INIT)
...
...
sql/sql_cache.cc
View file @
2426972c
...
...
@@ -299,11 +299,15 @@ TODO list:
pthread_mutex_lock(M);}
#define MUTEX_UNLOCK(M) {DBUG_PRINT("lock", ("mutex unlock 0x%lx",\
(ulong)(M))); pthread_mutex_unlock(M);}
#define SEM_LOCK(M) { int val = 0; sem_getvalue (M, &val); \
DBUG_PRINT("lock", ("sem lock 0x%lx (%d)", (ulong)(M), val)); \
sem_wait(M); DBUG_PRINT("lock", ("sem lock ok")); }
#define SEM_UNLOCK(M) {DBUG_PRINT("info", ("sem unlock 0x%lx", (ulong)(M))); \
sem_post(M); DBUG_PRINT("info", ("sem unlock ok")); }
#define RW_WLOCK(M) {DBUG_PRINT("lock", ("rwlock wlock 0x%lx",(ulong)(M))); \
if (!rw_wrlock(M)) DBUG_PRINT("lock", ("rwlock wlock ok")) \
else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); }
#define RW_RLOCK(M) {DBUG_PRINT("lock", ("rwlock rlock 0x%lx", (ulong)(M))); \
if (!rw_rdlock(M)) DBUG_PRINT("lock", ("rwlock rlock ok")) \
else DBUG_PRINT("lock", ("rwlock wlock FAILED %d", errno)); }
#define RW_UNLOCK(M) {DBUG_PRINT("lock", ("rwlock wlock 0x%lx",(ulong)(M))); \
if (!rw_unlock(M)) DBUG_PRINT("lock", ("rwlock unlock ok")) \
else DBUG_PRINT("lock", ("rwlock unlock FAILED %d", errno)); }
#define STRUCT_LOCK(M) {DBUG_PRINT("lock", ("%d struct lock...",__LINE__)); \
pthread_mutex_lock(M);DBUG_PRINT("lock", ("struct lock OK"));}
#define STRUCT_UNLOCK(M) { \
...
...
@@ -326,8 +330,9 @@ TODO list:
#else
#define MUTEX_LOCK(M) pthread_mutex_lock(M)
#define MUTEX_UNLOCK(M) pthread_mutex_unlock(M)
#define SEM_LOCK(M) sem_wait(M)
#define SEM_UNLOCK(M) sem_post(M)
#define RW_WLOCK(M) rw_wrlock(M)
#define RW_RLOCK(M) rw_rdlock(M)
#define RW_UNLOCK(M) rw_unlock(M)
#define STRUCT_LOCK(M) pthread_mutex_lock(M)
#define STRUCT_UNLOCK(M) pthread_mutex_unlock(M)
#define BLOCK_LOCK_WR(B) B->query()->lock_writing()
...
...
@@ -445,9 +450,7 @@ void Query_cache_query::init_n_lock()
{
DBUG_ENTER
(
"Query_cache_query::init_n_lock"
);
res
=
0
;
wri
=
0
;
len
=
0
;
sem_init
(
&
lock
,
0
,
1
);
pthread_mutex_init
(
&
clients_guard
,
MY_MUTEX_INIT_FAST
);
clients
=
0
;
my_rwlock_init
(
&
lock
,
NULL
);
lock_writing
();
DBUG_PRINT
(
"qcache"
,
(
"inited & locked query for block 0x%lx"
,
((
byte
*
)
this
)
-
ALIGN_SIZE
(
sizeof
(
Query_cache_block
))));
...
...
@@ -465,8 +468,7 @@ void Query_cache_query::unlock_n_destroy()
active semaphore
*/
this
->
unlock_writing
();
sem_destroy
(
&
lock
);
pthread_mutex_destroy
(
&
clients_guard
);
rwlock_destroy
(
&
lock
);
DBUG_VOID_RETURN
;
}
...
...
@@ -479,9 +481,9 @@ void Query_cache_query::unlock_n_destroy()
Lock for read prevents only locking for write.
*/
void
Query_cache_query
::
lock_writing
()
inline
void
Query_cache_query
::
lock_writing
()
{
SEM_
LOCK
(
&
lock
);
RW_W
LOCK
(
&
lock
);
}
...
...
@@ -495,41 +497,31 @@ void Query_cache_query::lock_writing()
my_bool
Query_cache_query
::
try_lock_writing
()
{
DBUG_ENTER
(
"Query_cache_block::try_lock_writing"
);
if
(
sem_trywait
(
&
lock
)
!=
0
||
clients
!=
0
)
if
(
rw_trywrlock
(
&
lock
)
!=
0
)
{
DBUG_PRINT
(
"info"
,
(
"can't lock
semaphore
"
));
DBUG_PRINT
(
"info"
,
(
"can't lock
rwlock
"
));
DBUG_RETURN
(
0
);
}
DBUG_PRINT
(
"info"
,
(
"
mutex 'lock'
0x%lx locked"
,
(
ulong
)
&
lock
));
DBUG_PRINT
(
"info"
,
(
"
rwlock
0x%lx locked"
,
(
ulong
)
&
lock
));
DBUG_RETURN
(
1
);
}
void
Query_cache_query
::
lock_reading
()
inline
void
Query_cache_query
::
lock_reading
()
{
MUTEX_LOCK
(
&
clients_guard
);
if
(
++
clients
==
1
)
SEM_LOCK
(
&
lock
);
MUTEX_UNLOCK
(
&
clients_guard
);
RW_RLOCK
(
&
lock
);
}
void
Query_cache_query
::
unlock_writing
()
inline
void
Query_cache_query
::
unlock_writing
()
{
SEM
_UNLOCK
(
&
lock
);
RW
_UNLOCK
(
&
lock
);
}
void
Query_cache_query
::
unlock_reading
()
inline
void
Query_cache_query
::
unlock_reading
()
{
/*
To avoid unlocking semaphore before unlocking mutex (that may cause
destroying locked mutex), we use temporary boolean variable 'unlock'.
*/
MUTEX_LOCK
(
&
clients_guard
);
bool
ulock
=
((
--
clients
)
==
0
);
MUTEX_UNLOCK
(
&
clients_guard
);
if
(
ulock
)
SEM_UNLOCK
(
&
lock
);
RW_UNLOCK
(
&
lock
);
}
extern
"C"
...
...
@@ -2339,7 +2331,7 @@ Query_cache::double_linked_list_simple_include(Query_cache_block *point,
*
list_pointer
=
point
->
next
=
point
->
prev
=
point
;
else
{
// insert to
a
nd of list
// insert to
the e
nd of list
point
->
next
=
(
*
list_pointer
);
point
->
prev
=
(
*
list_pointer
)
->
prev
;
point
->
prev
->
next
=
point
;
...
...
@@ -2634,8 +2626,7 @@ my_bool Query_cache::move_by_type(byte **border,
}
while
(
result_block
!=
first_result_block
);
}
Query_cache_query
*
new_query
=
((
Query_cache_query
*
)
new_block
->
data
());
sem_init
(
&
new_query
->
lock
,
0
,
1
);
pthread_mutex_init
(
&
new_query
->
clients_guard
,
MY_MUTEX_INIT_FAST
);
my_rwlock_init
(
&
new_query
->
lock
,
NULL
);
/*
If someone is writing to this block, inform the writer that the block
...
...
sql/sql_cache.h
View file @
2426972c
...
...
@@ -63,8 +63,6 @@
#define TABLE_COUNTER_TYPE uint8
#include <my_semaphore.h>
struct
Query_cache_block
;
struct
Query_cache_block_table
;
struct
Query_cache_table
;
...
...
@@ -110,16 +108,13 @@ struct Query_cache_block
inline
Query_cache_block_table
*
table
(
TABLE_COUNTER_TYPE
n
);
};
struct
Query_cache_query
{
ulonglong
limit_found_rows
;
rw_lock_t
lock
;
Query_cache_block
*
res
;
NET
*
wri
;
ulong
len
;
sem_t
lock
;
// R/W lock of block
pthread_mutex_t
clients_guard
;
uint
clients
;
inline
void
init_n_lock
();
void
unlock_n_destroy
();
...
...
sql/sql_handler.cc
View file @
2426972c
...
...
@@ -17,9 +17,9 @@
/* HANDLER ... commands - direct access to ISAM */
#include <assert.h>
#include "mysql_priv.h"
#include "sql_select.h"
#include <assert.h>
/* TODO:
HANDLER blabla OPEN [ AS foobar ] [ (column-list) ]
...
...
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