2 * OpenAL cross platform audio library
3 * Copyright (C) 1999-2007 by authors.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
18 * Or go to http://www.gnu.org/copyleft/lgpl.html
28 #define THREAD_STACK_SIZE (1*1024*1024) /* 1MB */
33 ALuint (*func
)(ALvoid
*);
38 static DWORD CALLBACK
StarterFunc(void *ptr
)
40 ThreadInfo
*inf
= (ThreadInfo
*)ptr
;
43 ret
= inf
->func(inf
->ptr
);
44 ExitThread((DWORD
)ret
);
49 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
)
52 ThreadInfo
*inf
= malloc(sizeof(ThreadInfo
));
58 inf
->thread
= CreateThread(NULL
, THREAD_STACK_SIZE
, StarterFunc
, inf
, 0, &dummy
);
68 ALuint
StopThread(ALvoid
*thread
)
70 ThreadInfo
*inf
= thread
;
73 WaitForSingleObject(inf
->thread
, INFINITE
);
74 GetExitCodeThread(inf
->thread
, &ret
);
75 CloseHandle(inf
->thread
);
87 ALuint (*func
)(ALvoid
*);
93 static void *StarterFunc(void *ptr
)
95 ThreadInfo
*inf
= (ThreadInfo
*)ptr
;
96 inf
->ret
= inf
->func(inf
->ptr
);
100 ALvoid
*StartThread(ALuint (*func
)(ALvoid
*), ALvoid
*ptr
)
103 ThreadInfo
*inf
= malloc(sizeof(ThreadInfo
));
104 if(!inf
) return NULL
;
106 if(pthread_attr_init(&attr
) != 0)
111 if(pthread_attr_setstacksize(&attr
, THREAD_STACK_SIZE
) != 0)
113 pthread_attr_destroy(&attr
);
120 if(pthread_create(&inf
->thread
, &attr
, StarterFunc
, inf
) != 0)
122 pthread_attr_destroy(&attr
);
126 pthread_attr_destroy(&attr
);
131 ALuint
StopThread(ALvoid
*thread
)
133 ThreadInfo
*inf
= thread
;
136 pthread_join(inf
->thread
, NULL
);