Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
SRB2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
STJr
SRB2
Commits
28f196ad
Commit
28f196ad
authored
1 year ago
by
Hanicef
Committed by
Hanicef
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Fix potential deadlock when using cond
parent
77e83dde
No related branches found
No related tags found
2 merge requests
!2355
fix newer versions of mixerx
,
!2246
Add dedicated server build
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/dedicated/i_threads.c
+26
-0
26 additions, 0 deletions
src/dedicated/i_threads.c
with
26 additions
and
0 deletions
src/dedicated/i_threads.c
+
26
−
0
View file @
28f196ad
...
...
@@ -106,6 +106,7 @@ void I_stop_threads(void)
void
I_lock_mutex
(
I_mutex
*
anchor
)
{
pthread_mutex_lock
(
&
thread_lock
);
if
(
*
anchor
==
NULL
)
{
pthread_mutexattr_t
attr
;
...
...
@@ -117,6 +118,7 @@ void I_lock_mutex(I_mutex *anchor)
pthread_mutex_init
(
*
anchor
,
&
attr
);
pthread_mutexattr_destroy
(
&
attr
);
}
pthread_mutex_unlock
(
&
thread_lock
);
pthread_mutex_lock
(
*
anchor
);
}
...
...
@@ -128,31 +130,37 @@ void I_unlock_mutex(I_mutex id)
void
I_hold_cond
(
I_cond
*
cond_anchor
,
I_mutex
mutex_id
)
{
I_Assert
(
mutex_id
!=
NULL
);
pthread_mutex_lock
(
&
thread_lock
);
if
(
*
cond_anchor
==
NULL
)
{
*
cond_anchor
=
malloc
(
sizeof
(
pthread_cond_t
));
pthread_cond_init
(
*
cond_anchor
,
NULL
);
}
pthread_mutex_unlock
(
&
thread_lock
);
pthread_cond_wait
(
*
cond_anchor
,
mutex_id
);
}
void
I_wake_one_cond
(
I_cond
*
anchor
)
{
pthread_mutex_lock
(
&
thread_lock
);
if
(
*
anchor
==
NULL
)
{
*
anchor
=
malloc
(
sizeof
(
pthread_cond_t
));
pthread_cond_init
(
*
anchor
,
NULL
);
}
pthread_mutex_unlock
(
&
thread_lock
);
pthread_cond_signal
(
*
anchor
);
}
void
I_wake_all_cond
(
I_cond
*
anchor
)
{
pthread_mutex_lock
(
&
thread_lock
);
if
(
*
anchor
==
NULL
)
{
*
anchor
=
malloc
(
sizeof
(
pthread_t
));
pthread_cond_init
(
*
anchor
,
NULL
);
}
pthread_mutex_unlock
(
&
thread_lock
);
pthread_cond_broadcast
(
*
anchor
);
}
#elif defined (_WIN32)
...
...
@@ -253,11 +261,13 @@ void I_stop_threads(void)
void
I_lock_mutex
(
I_mutex
*
anchor
)
{
EnterCriticalSection
(
&
thread_lock
);
if
(
*
anchor
==
NULL
)
{
*
anchor
=
malloc
(
sizeof
(
CRITICAL_SECTION
));
InitializeCriticalSection
(
*
anchor
);
}
LeaveCriticalSection
(
&
thread_lock
);
EnterCriticalSection
(
*
anchor
);
}
...
...
@@ -269,21 +279,37 @@ void I_unlock_mutex(I_mutex id)
void
I_hold_cond
(
I_cond
*
cond_anchor
,
I_mutex
mutex_id
)
{
I_Assert
(
mutex_id
!=
NULL
);
EnterCriticalSection
(
&
thread_lock
);
if
(
*
cond_anchor
==
NULL
)
{
*
cond_anchor
=
malloc
(
sizeof
(
CONDITION_VARIABLE
));
InitializeConditionVariable
(
*
cond_anchor
);
}
LeaveCriticalSection
(
&
thread_lock
);
SleepConditionVariableCS
(
*
cond_anchor
,
mutex_id
,
INFINITE
);
}
void
I_wake_one_cond
(
I_cond
*
anchor
)
{
EnterCriticalSection
(
&
thread_lock
);
if
(
*
cond_anchor
==
NULL
)
{
*
cond_anchor
=
malloc
(
sizeof
(
CONDITION_VARIABLE
));
InitializeConditionVariable
(
*
cond_anchor
);
}
LeaveCriticalSection
(
&
thread_lock
);
WakeConditionVariable
(
*
anchor
);
}
void
I_wake_all_cond
(
I_cond
*
anchor
)
{
EnterCriticalSection
(
&
thread_lock
);
if
(
*
cond_anchor
==
NULL
)
{
*
cond_anchor
=
malloc
(
sizeof
(
CONDITION_VARIABLE
));
InitializeConditionVariable
(
*
cond_anchor
);
}
LeaveCriticalSection
(
&
thread_lock
);
WakeAllConditionVariable
(
*
anchor
);
}
#else
...
...
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