Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
869e7893
Commit
869e7893
authored
1 year ago
by
Deucе
Browse files
Options
Downloads
Patches
Plain Diff
Fix rwlocks for Win32
Various bits of broken no longer broken.
parent
a28dffc0
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!455
Update branch with changes from master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/xpdev/rwlockwrap.c
+20
-9
20 additions, 9 deletions
src/xpdev/rwlockwrap.c
with
20 additions
and
9 deletions
src/xpdev/rwlockwrap.c
+
20
−
9
View file @
869e7893
...
...
@@ -3,6 +3,7 @@
#if defined(_WIN32)
#include
<stdlib.h>
#include
<stdio.h>
static
struct
rwlock_reader_thread
*
find_self
(
rwlock_t
*
lock
,
struct
rwlock_reader_thread
***
prev
)
...
...
@@ -12,7 +13,7 @@ find_self(rwlock_t *lock, struct rwlock_reader_thread ***prev)
if
(
prev
)
*
prev
=
&
lock
->
rthreads
;
for
(
ret
=
NULL
;
ret
;
ret
=
ret
->
next
)
{
for
(
ret
=
lock
->
rthreads
;
ret
;
ret
=
ret
->
next
)
{
if
(
ret
->
id
==
self
)
return
ret
;
if
(
prev
)
{
...
...
@@ -94,7 +95,7 @@ rwlock_tryrdlock(rwlock_t *lock)
LeaveCriticalSection
(
&
lock
->
lk
);
return
FALSE
;
}
if
(
lock
->
writers
==
0
&&
lock
->
writers_waiting
==
0
)
{
if
(
rc
->
count
||
(
lock
->
writers
==
0
&&
lock
->
writers_waiting
==
0
)
)
{
rc
->
count
++
;
lock
->
readers
++
;
ret
=
TRUE
;
...
...
@@ -106,23 +107,33 @@ rwlock_tryrdlock(rwlock_t *lock)
BOOL
rwlock_wrlock
(
rwlock_t
*
lock
)
{
BOOL
ret
=
FALSE
;
EnterCriticalSection
(
&
lock
->
lk
);
lock
->
writers_waiting
++
;
LeaveCriticalSection
(
&
lock
->
lk
);
EnterCriticalSection
(
&
lock
->
wlk
);
EnterCriticalSection
(
&
lock
->
lk
);
// No recursion
if
(
lock
->
writers
==
0
)
{
while
(
lock
->
readers
)
{
LeaveCriticalSection
(
&
lock
->
lk
);
LeaveCriticalSection
(
&
lock
->
wlk
);
Sleep
(
1
);
EnterCriticalSection
(
&
lock
->
wlk
);
EnterCriticalSection
(
&
lock
->
lk
);
}
if
(
lock
->
writers
)
{
lock
->
writers_waiting
--
;
ret
=
FALSE
;
}
else
{
lock
->
writers_waiting
--
;
lock
->
writers
++
;
lock
->
writer
=
GetCurrentThreadId
();
LeaveCriticalSection
(
&
lock
->
lk
);
// Keep holding wlk
return
TRUE
;
ret
=
TRUE
;
}
LeaveCriticalSection
(
&
lock
->
lk
);
LeaveCriticalSection
(
&
lock
->
wlk
);
return
FALSE
;
return
ret
;
}
BOOL
...
...
@@ -131,7 +142,7 @@ rwlock_trywrlock(rwlock_t *lock)
if
(
TryEnterCriticalSection
(
&
lock
->
wlk
))
{
EnterCriticalSection
(
&
lock
->
lk
);
// Prevent recursing on writer locks
if
(
lock
->
writers
==
0
)
{
if
(
lock
->
readers
==
0
&&
lock
->
writers
==
0
)
{
lock
->
writers
++
;
lock
->
writer
=
GetCurrentThreadId
();
LeaveCriticalSection
(
&
lock
->
lk
);
...
...
@@ -163,7 +174,7 @@ rwlock_unlock(rwlock_t *lock)
return
FALSE
;
}
if
(
lock
->
readers
)
{
rc
=
find_self
(
lock
,
NULL
);
rc
=
find_self
(
lock
,
&
prev
);
if
(
rc
&&
rc
->
count
)
{
rc
->
count
--
;
lock
->
readers
--
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment