zenilib  0.5.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
SDL_systhread.c
Go to the documentation of this file.
1 /*
2  Simple DirectMedia Layer
3  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
4 
5  This software is provided 'as-is', without any express or implied
6  warranty. In no event will the authors be held liable for any damages
7  arising from the use of this software.
8 
9  Permission is granted to anyone to use this software for any purpose,
10  including commercial applications, and to alter it and redistribute it
11  freely, subject to the following restrictions:
12 
13  1. The origin of this software must not be misrepresented; you must not
14  claim that you wrote the original software. If you use this software
15  in a product, an acknowledgment in the product documentation would be
16  appreciated but is not required.
17  2. Altered source versions must be plainly marked as such, and must not be
18  misrepresented as being the original software.
19  3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "SDL_config.h"
22 
23 #ifdef SDL_THREAD_BEOS
24 
25 /* BeOS thread management routines for SDL */
26 
27 #include <stdio.h>
28 #include <signal.h>
29 #include <be/kernel/OS.h>
30 
31 #include "SDL_mutex.h"
32 #include "SDL_thread.h"
33 #include "../SDL_thread_c.h"
34 #include "../SDL_systhread.h"
35 
36 
37 static int sig_list[] = {
38  SIGHUP, SIGINT, SIGQUIT, SIGPIPE, SIGALRM, SIGTERM, SIGWINCH, 0
39 };
40 
41 void
42 SDL_MaskSignals(sigset_t * omask)
43 {
44  sigset_t mask;
45  int i;
46 
47  sigemptyset(&mask);
48  for (i = 0; sig_list[i]; ++i) {
49  sigaddset(&mask, sig_list[i]);
50  }
51  sigprocmask(SIG_BLOCK, &mask, omask);
52 }
53 
54 void
55 SDL_UnmaskSignals(sigset_t * omask)
56 {
57  sigprocmask(SIG_SETMASK, omask, NULL);
58 }
59 
60 static int32
61 RunThread(void *data)
62 {
63  SDL_RunThread(data);
64  return (0);
65 }
66 
67 int
69 {
70  /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
71  const char *threadname = thread->name ? thread->name : "SDL Thread";
72  char name[B_OS_NAME_LENGTH];
73  SDL_snprintf(name, sizeof (name), "%s", threadname);
74  name[sizeof (name) - 1] = '\0';
75 
76  /* Create the thread and go! */
77  thread->handle = spawn_thread(RunThread, name, B_NORMAL_PRIORITY, args);
78  if ((thread->handle == B_NO_MORE_THREADS) ||
79  (thread->handle == B_NO_MEMORY)) {
80  return SDL_SetError("Not enough resources to create thread");
81  }
82  resume_thread(thread->handle);
83  return (0);
84 }
85 
86 void
87 SDL_SYS_SetupThread(const char *name)
88 {
89  /* We set the thread name during SDL_SYS_CreateThread(). */
90  /* Mask asynchronous signals for this thread */
92 }
93 
95 SDL_ThreadID(void)
96 {
97  return ((SDL_threadID) find_thread(NULL));
98 }
99 
100 int
102 {
103  int32 value;
104 
105  if (priority == SDL_THREAD_PRIORITY_LOW) {
106  value = B_LOW_PRIORITY;
107  } else if (priority == SDL_THREAD_PRIORITY_HIGH) {
108  value = B_URGENT_DISPLAY_PRIORITY;
109  } else {
110  value = B_NORMAL_PRIORITY;
111  }
112  set_thread_priority(find_thread(NULL), value);
113  return 0;
114 }
115 
116 void
118 {
119  status_t the_status;
120 
121  wait_for_thread(thread->handle, &the_status);
122 }
123 
124 #endif /* SDL_THREAD_BEOS */
125 
126 /* vi: set ts=4 sw=4 expandtab: */
char * name
Definition: SDL_thread_c.h:54
DECLSPEC SDL_threadID SDLCALL SDL_ThreadID(void)
Definition: SDL_systhread.c:48
unsigned long SDL_threadID
Definition: SDL_thread.h:49
#define NULL
Definition: ftobjs.h:61
DECLSPEC int SDLCALL SDL_snprintf(char *text, size_t maxlen, const char *fmt,...)
Definition: SDL_string.c:1277
static void * RunThread(void *data)
Definition: SDL_systhread.c:64
EGLImageKHR EGLint * name
Definition: eglext.h:284
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
Definition: SDL_systhread.c:42
void SDL_UnmaskSignals(sigset_t *omask)
void SDL_SYS_WaitThread(SDL_Thread *thread)
Definition: SDL_systhread.c:60
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl2ext.h:848
int SDL_SYS_SetThreadPriority(SDL_ThreadPriority priority)
Definition: SDL_systhread.c:54
DECLSPEC int SDLCALL SDL_SetError(const char *fmt,...)
Definition: SDL_error.c:53
static const int sig_list[]
Definition: SDL_systhread.c:57
static SDL_Thread * thread
SYS_ThreadHandle handle
Definition: SDL_thread_c.h:51
EGLSurface EGLint void ** value
Definition: eglext.h:301
GLint GLint GLint GLint GLint GLint GLint GLbitfield mask
Definition: gl2ext.h:961
void SDL_RunThread(void *data)
Definition: SDL_thread.c:263
void SDL_SYS_SetupThread(const char *name)
Definition: SDL_systhread.c:42
SDL_ThreadPriority
Definition: SDL_thread.h:59
int i
Definition: pngrutil.c:1377
void SDL_MaskSignals(sigset_t *omask)