Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
bca33709
Commit
bca33709
authored
Mar 25, 2011
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented SDL_SetThreadPriority()
parent
0b1225e3
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
122 additions
and
13 deletions
+122
-13
SDL_thread.h
include/SDL_thread.h
+15
-0
SDL_audio.c
src/audio/SDL_audio.c
+1
-0
SDL_systhread.h
src/thread/SDL_systhread.h
+3
-0
SDL_thread.c
src/thread/SDL_thread.c
+23
-13
SDL_systhread.c
src/thread/beos/SDL_systhread.c
+14
-0
SDL_systhread.c
src/thread/generic/SDL_systhread.c
+6
-0
SDL_syscond.c
src/thread/nds/SDL_syscond.c
+2
-0
SDL_sysmutex.c
src/thread/nds/SDL_sysmutex.c
+2
-0
SDL_syssem.c
src/thread/nds/SDL_syssem.c
+2
-0
SDL_systhread.c
src/thread/nds/SDL_systhread.c
+8
-0
SDL_systhread.c
src/thread/pthread/SDL_systhread.c
+27
-0
SDL_systhread.c
src/thread/windows/SDL_systhread.c
+19
-0
No files found.
include/SDL_thread.h
View file @
bca33709
...
@@ -50,6 +50,16 @@ typedef struct SDL_Thread SDL_Thread;
...
@@ -50,6 +50,16 @@ typedef struct SDL_Thread SDL_Thread;
/* The SDL thread ID */
/* The SDL thread ID */
typedef
unsigned
long
SDL_threadID
;
typedef
unsigned
long
SDL_threadID
;
/* The SDL thread priority
*
* Note: On many systems you require special privileges to set high priority.
*/
typedef
enum
{
SDL_THREAD_PRIORITY_LOW
,
SDL_THREAD_PRIORITY_NORMAL
,
SDL_THREAD_PRIORITY_HIGH
}
SDL_ThreadPriority
;
/* The function passed to SDL_CreateThread()
/* The function passed to SDL_CreateThread()
It is passed a void* user context parameter and returns an int.
It is passed a void* user context parameter and returns an int.
*/
*/
...
@@ -146,6 +156,11 @@ extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
...
@@ -146,6 +156,11 @@ extern DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void);
*/
*/
extern
DECLSPEC
SDL_threadID
SDLCALL
SDL_GetThreadID
(
SDL_Thread
*
thread
);
extern
DECLSPEC
SDL_threadID
SDLCALL
SDL_GetThreadID
(
SDL_Thread
*
thread
);
/**
* Set the thread priority
*/
extern
DECLSPEC
int
SDLCALL
SDL_SetThreadPriority
(
SDL_Thread
*
thread
,
SDL_ThreadPriority
priority
);
/**
/**
* Wait for a thread to finish.
* Wait for a thread to finish.
*
*
...
...
src/audio/SDL_audio.c
View file @
bca33709
...
@@ -974,6 +974,7 @@ open_audio_device(const char *devname, int iscapture,
...
@@ -974,6 +974,7 @@ open_audio_device(const char *devname, int iscapture,
SDL_SetError
(
"Couldn't create audio thread"
);
SDL_SetError
(
"Couldn't create audio thread"
);
return
0
;
return
0
;
}
}
SDL_SetThreadPriority
(
device
->
thread
,
SDL_THREAD_PRIORITY_HIGH
);
}
}
return
id
+
1
;
return
id
+
1
;
...
...
src/thread/SDL_systhread.h
View file @
bca33709
...
@@ -43,6 +43,9 @@ extern int SDL_SYS_CreateThread(SDL_Thread * thread, void *args);
...
@@ -43,6 +43,9 @@ extern int SDL_SYS_CreateThread(SDL_Thread * thread, void *args);
/* This function does any necessary setup in the child thread */
/* This function does any necessary setup in the child thread */
extern
void
SDL_SYS_SetupThread
(
void
);
extern
void
SDL_SYS_SetupThread
(
void
);
/* This function sets thread priority */
extern
int
SDL_SYS_SetThreadPriority
(
SDL_Thread
*
thread
,
SDL_ThreadPriority
priority
);
/* This function waits for the thread to finish and frees any data
/* This function waits for the thread to finish and frees any data
allocated by SDL_SYS_CreateThread()
allocated by SDL_SYS_CreateThread()
*/
*/
...
...
src/thread/SDL_thread.c
View file @
bca33709
...
@@ -281,19 +281,6 @@ SDL_CreateThread(int (SDLCALL * fn) (void *), void *data)
...
@@ -281,19 +281,6 @@ SDL_CreateThread(int (SDLCALL * fn) (void *), void *data)
return
(
thread
);
return
(
thread
);
}
}
void
SDL_WaitThread
(
SDL_Thread
*
thread
,
int
*
status
)
{
if
(
thread
)
{
SDL_SYS_WaitThread
(
thread
);
if
(
status
)
{
*
status
=
thread
->
status
;
}
SDL_DelThread
(
thread
);
SDL_free
(
thread
);
}
}
SDL_threadID
SDL_threadID
SDL_GetThreadID
(
SDL_Thread
*
thread
)
SDL_GetThreadID
(
SDL_Thread
*
thread
)
{
{
...
@@ -307,4 +294,27 @@ SDL_GetThreadID(SDL_Thread * thread)
...
@@ -307,4 +294,27 @@ SDL_GetThreadID(SDL_Thread * thread)
return
id
;
return
id
;
}
}
int
SDL_SetThreadPriority
(
SDL_Thread
*
thread
,
SDL_ThreadPriority
priority
)
{
if
(
!
thread
)
{
SDL_SetError
(
"SDL_SetThreadPriority() passed NULL thread"
);
return
-
1
;
}
return
SDL_SYS_SetThreadPriority
(
thread
,
priority
);
}
void
SDL_WaitThread
(
SDL_Thread
*
thread
,
int
*
status
)
{
if
(
thread
)
{
SDL_SYS_WaitThread
(
thread
);
if
(
status
)
{
*
status
=
thread
->
status
;
}
SDL_DelThread
(
thread
);
SDL_free
(
thread
);
}
}
/* vi: set ts=4 sw=4 expandtab: */
/* vi: set ts=4 sw=4 expandtab: */
src/thread/beos/SDL_systhread.c
View file @
bca33709
...
@@ -90,6 +90,20 @@ SDL_ThreadID(void)
...
@@ -90,6 +90,20 @@ SDL_ThreadID(void)
return
((
SDL_threadID
)
find_thread
(
NULL
));
return
((
SDL_threadID
)
find_thread
(
NULL
));
}
}
int
SDL_SYS_SetThreadPriority
(
SDL_Thread
*
thread
,
SDL_ThreadPriority
priority
)
{
int32
new_priority
=
B_NORMAL_PRIORITY
;
if
(
priority
==
SDL_THREAD_PRIORITY_LOW
)
{
new_priority
=
B_LOW_PRIORITY
;
}
else
if
(
priority
==
SDL_THREAD_PRIORITY_HIGH
)
{
new_priority
=
B_URGENT_DISPLAY_PRIORITY
;
}
set_thread_priority
(
thread
->
handle
,
new_priority
);
return
0
;
}
void
void
SDL_SYS_WaitThread
(
SDL_Thread
*
thread
)
SDL_SYS_WaitThread
(
SDL_Thread
*
thread
)
{
{
...
...
src/thread/generic/SDL_systhread.c
View file @
bca33709
...
@@ -45,6 +45,12 @@ SDL_ThreadID(void)
...
@@ -45,6 +45,12 @@ SDL_ThreadID(void)
return
(
0
);
return
(
0
);
}
}
int
SDL_SYS_SetThreadPriority
(
SDL_Thread
*
thread
,
SDL_ThreadPriority
priority
)
{
return
(
0
);
}
void
void
SDL_SYS_WaitThread
(
SDL_Thread
*
thread
)
SDL_SYS_WaitThread
(
SDL_Thread
*
thread
)
{
{
...
...
src/thread/nds/SDL_syscond.c
View file @
bca33709
...
@@ -227,3 +227,5 @@ SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
...
@@ -227,3 +227,5 @@ SDL_CondWait(SDL_cond * cond, SDL_mutex * mutex)
{
{
return
SDL_CondWaitTimeout
(
cond
,
mutex
,
SDL_MUTEX_MAXWAIT
);
return
SDL_CondWaitTimeout
(
cond
,
mutex
,
SDL_MUTEX_MAXWAIT
);
}
}
/* vi: set ts=4 sw=4 expandtab: */
src/thread/nds/SDL_sysmutex.c
View file @
bca33709
...
@@ -140,3 +140,5 @@ SDL_mutexV(SDL_mutex * mutex)
...
@@ -140,3 +140,5 @@ SDL_mutexV(SDL_mutex * mutex)
return
0
;
return
0
;
#endif
/* DISABLE_THREADS */
#endif
/* DISABLE_THREADS */
}
}
/* vi: set ts=4 sw=4 expandtab: */
src/thread/nds/SDL_syssem.c
View file @
bca33709
...
@@ -226,3 +226,5 @@ SDL_SemPost(SDL_sem * sem)
...
@@ -226,3 +226,5 @@ SDL_SemPost(SDL_sem * sem)
}
}
#endif
/* DISABLE_THREADS */
#endif
/* DISABLE_THREADS */
/* vi: set ts=4 sw=4 expandtab: */
src/thread/nds/SDL_systhread.c
View file @
bca33709
...
@@ -56,8 +56,16 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
...
@@ -56,8 +56,16 @@ SDL_SYS_WaitThread(SDL_Thread * thread)
return
;
return
;
}
}
int
SDL_SYS_SetThreadPriority
(
SDL_Thread
*
thread
,
SDL_ThreadPriority
priority
)
{
return
(
0
);
}
void
void
SDL_SYS_KillThread
(
SDL_Thread
*
thread
)
SDL_SYS_KillThread
(
SDL_Thread
*
thread
)
{
{
return
;
return
;
}
}
/* vi: set ts=4 sw=4 expandtab: */
src/thread/pthread/SDL_systhread.c
View file @
bca33709
...
@@ -91,6 +91,33 @@ SDL_ThreadID(void)
...
@@ -91,6 +91,33 @@ SDL_ThreadID(void)
return
((
SDL_threadID
)
pthread_self
());
return
((
SDL_threadID
)
pthread_self
());
}
}
int
SDL_SYS_SetThreadPriority
(
SDL_Thread
*
thread
,
SDL_ThreadPriority
priority
)
{
struct
sched_param
sched
;
int
policy
;
if
(
pthread_getschedparam
(
thread
->
handle
,
&
policy
,
&
sched
)
<
0
)
{
SDL_SetError
(
"pthread_getschedparam() failed"
);
return
-
1
;
}
if
(
priority
==
SDL_THREAD_PRIORITY_LOW
)
{
sched
.
sched_priority
=
sched_get_priority_min
(
policy
);
}
else
if
(
priority
==
SDL_THREAD_PRIORITY_HIGH
)
{
sched
.
sched_priority
=
sched_get_priority_max
(
policy
);
}
else
{
int
min_priority
=
sched_get_priority_min
(
policy
);
int
max_priority
=
sched_get_priority_max
(
policy
);
int
priority
=
(
min_priority
+
(
max_priority
-
min_priority
)
/
2
);
sched
.
sched_priority
=
priority
;
}
if
(
pthread_setschedparam
(
thread
->
handle
,
policy
,
&
sched
)
<
0
)
{
SDL_SetError
(
"pthread_setschedparam() failed"
);
return
-
1
;
}
return
0
;
}
void
void
SDL_SYS_WaitThread
(
SDL_Thread
*
thread
)
SDL_SYS_WaitThread
(
SDL_Thread
*
thread
)
{
{
...
...
src/thread/windows/SDL_systhread.c
View file @
bca33709
...
@@ -155,6 +155,25 @@ SDL_ThreadID(void)
...
@@ -155,6 +155,25 @@ SDL_ThreadID(void)
return
((
SDL_threadID
)
GetCurrentThreadId
());
return
((
SDL_threadID
)
GetCurrentThreadId
());
}
}
int
SDL_SYS_SetThreadPriority
(
SDL_Thread
*
thread
,
SDL_ThreadPriority
priority
)
{
BOOL
result
;
if
(
priority
==
SDL_THREAD_PRIORITY_LOW
)
{
result
=
SetThreadPriority
(
thread
->
handle
,
THREAD_PRIORITY_LOWEST
);
}
else
if
(
priority
==
SDL_THREAD_PRIORITY_HIGH
)
{
result
=
SetThreadPriority
(
thread
->
handle
,
THREAD_PRIORITY_HIGHEST
);
}
else
{
result
=
SetThreadPriority
(
thread
->
handle
,
THREAD_PRIORITY_NORMAL
);
}
if
(
!
result
)
{
WIN_SetError
(
"SetThreadPriority()"
);
return
-
1
;
}
return
0
;
}
void
void
SDL_SYS_WaitThread
(
SDL_Thread
*
thread
)
SDL_SYS_WaitThread
(
SDL_Thread
*
thread
)
{
{
...
...
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