本文整理汇总了C++中SDL_ThreadID函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_ThreadID函数的具体用法?C++ SDL_ThreadID怎么用?C++ SDL_ThreadID使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_ThreadID函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: osd_lock_try
int osd_lock_try(osd_lock *lock)
{
hidden_mutex_t *mutex = (hidden_mutex_t *) lock;
LOG(("osd_lock_try"));
if (mutex->locked && mutex->threadid == SDL_ThreadID())
{
/* get the lock */
SDL_mutexP(mutex->id);
mutex->locked++;
mutex->threadid = SDL_ThreadID();
return 1;
}
else if ((mutex->locked == 0))
{
/* get the lock */
mutex->locked++;
SDL_mutexP(mutex->id);
mutex->threadid = SDL_ThreadID();
return 1;
}
else
{
/* fail */
return 0;
}
}
示例2: MSG_DEBUG
int NetworkThread::ThreadRun(void* /*no_param*/)
{
MSG_DEBUG("network.thread", "Thread created: %u", SDL_ThreadID());
ReceiveActions();
MSG_DEBUG("network.thread", "Thread finished: %u", SDL_ThreadID());
return 0;
}
示例3: SDL_ThreadID
// The evil singelton mechanism.
//
Achievements_System * Achievements_System::get_instance(void)
{
static Achievements_System as;
static Uint32 creation_thread = SDL_ThreadID();
if (SDL_ThreadID() != creation_thread)
std::cerr << __FUNCTION__ << ": Achievements system called by non-creator thread." << std::endl;
return &as;
}
示例4: InternalThreadFunc
static int InternalThreadFunc(void *data)
{
#ifdef __APPLE__
pthread_once(&keyOnce, MakeTlsKey);
pthread_setspecific(tlsParamKey, data);
// Save the Mach port with the handle.
((InternalThreadParam* )data)->handle->m_machThreadPort = mach_thread_self();
#else
pParam = (InternalThreadParam *)data;
#endif
int nRc = -1;
// assign termination handler
struct sigaction action;
action.sa_handler = handler;
sigemptyset (&action.sa_mask);
action.sa_flags = 0;
//sigaction (SIGABRT, &action, NULL);
//sigaction (SIGSEGV, &action, NULL);
#ifdef __APPLE__
void* pool = InitializeAutoReleasePool();
#endif
try {
CLog::Log(LOGDEBUG,"Running thread %lu", (unsigned long)SDL_ThreadID());
nRc = GET_PARAM()->threadFunc(GET_PARAM()->data);
}
catch(...) {
CLog::Log(LOGERROR,"thread 0x%x raised an exception. terminating it.", SDL_ThreadID());
}
#ifdef __APPLE__
DestroyAutoReleasePool(pool);
#endif
if (OwningCriticalSection(g_graphicsContext))
{
CLog::Log(LOGERROR,"thread terminated and still owns graphic context. releasing it.");
ExitCriticalSection(g_graphicsContext);
}
SetEvent(GET_PARAM()->handle);
CloseHandle(GET_PARAM()->handle);
delete GET_PARAM();
return nRc;
}
示例5: SDL_Delay
void
SDL_Delay(Uint32 ms)
{
Uint32 now, then, elapsed;
#if !SDL_THREADS_DISABLED
int is_event_thread;
if (riscos_using_threads) {
is_event_thread = 0;
if (SDL_EventThreadID()) {
if (SDL_EventThreadID() == SDL_ThreadID())
is_event_thread = 1;
} else if (SDL_ThreadID() == riscos_main_thread)
is_event_thread = 1;
} else
is_event_thread = 1;
#endif
/*TODO: Next version of Unixlib may allow us to use usleep here */
/* for non event threads */
/* Set the timeout interval - Linux only needs to do this once */
then = SDL_GetTicks();
do {
/* Do background tasks required while sleeping as we are not multithreaded */
#if SDL_THREADS_DISABLED
RISCOS_BackgroundTasks();
#else
/* For threaded build only run background tasks in event thread */
if (is_event_thread)
RISCOS_BackgroundTasks();
#endif
/* Calculate the time interval left (in case of interrupt) */
now = SDL_GetTicks();
elapsed = (now - then);
then = now;
if (elapsed >= ms) {
break;
}
ms -= elapsed;
#if !SDL_THREADS_DISABLED
/* Need to yield to let other threads have a go */
if (riscos_using_threads)
pthread_yield();
#endif
} while (1);
}
示例6: main
int
main(int argc, char *argv[])
{
int i;
int maxproc = 6;
/* Enable standard application logging */
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO);
/* Load the SDL library */
if (SDL_Init(0) < 0) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "%s\n", SDL_GetError());
exit(1);
}
atexit(SDL_Quit_Wrapper);
if ((mutex = SDL_CreateMutex()) == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create mutex: %s\n", SDL_GetError());
exit(1);
}
mainthread = SDL_ThreadID();
SDL_Log("Main thread: %lu\n", mainthread);
atexit(printid);
for (i = 0; i < maxproc; ++i) {
char name[64];
SDL_snprintf(name, sizeof (name), "Worker%d", i);
if ((threads[i] = SDL_CreateThread(Run, name, NULL)) == NULL)
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create thread!\n");
}
signal(SIGINT, terminate);
Run(NULL);
return (0); /* Never reached */
}
示例7: SDL_RunThread
void SDL_RunThread(void *data)
{
thread_args *args;
int (*userfunc)(void *);
void *userdata;
int *statusloc;
/* Perform any system-dependent setup
- this function cannot fail, and cannot use SDL_SetError()
*/
SDL_SYS_SetupThread();
/* Get the thread id */
args = (thread_args *)data;
args->info->threadid = SDL_ThreadID();
/* Figure out what function to run */
userfunc = args->func;
userdata = args->data;
statusloc = &args->info->status;
/* Wake up the parent thread */
SDL_SemPost(args->wait);
/* Run the function */
*statusloc = userfunc(userdata);
}
示例8: SDL_mutexP
/* Lock the semaphore */
int SDL_mutexP(SDL_mutex *mutex)
{
#ifdef DISABLE_THREADS
return 0;
#else
Uint32 this_thread;
if ( mutex == NULL ) {
//SDL_SetError("Passed a NULL mutex"); //maks: no errors
return -1;
}
this_thread = SDL_ThreadID();
if ( mutex->owner == this_thread ) {
++mutex->recursive;
} else {
/* The order of operations is important.
We set the locking thread id after we obtain the lock
so unlocks from other threads will fail.
*/
SDL_SemWait(mutex->sem);
mutex->owner = this_thread;
mutex->recursive = 0;
}
return 0;
#endif /* DISABLE_THREADS */
}
示例9: SDL_TryLockMutex
/* try Lock the mutex */
int
SDL_TryLockMutex(SDL_mutex * mutex)
{
#if SDL_THREADS_DISABLED
return 0;
#else
int retval = 0;
SDL_threadID this_thread;
if (mutex == NULL) {
return SDL_SetError("Passed a NULL mutex");
}
this_thread = SDL_ThreadID();
if (mutex->owner == this_thread) {
++mutex->recursive;
} else {
/* The order of operations is important.
We set the locking thread id after we obtain the lock
so unlocks from other threads will fail.
*/
retval = SDL_SemWait(mutex->sem);
if (retval == 0) {
mutex->owner = this_thread;
mutex->recursive = 0;
}
}
return retval;
#endif /* SDL_THREADS_DISABLED */
}
示例10: SDL_SYS_SetupThread
void
SDL_SYS_SetupThread(const char *name)
{
// Make sure a thread ID gets assigned ASAP, for debugging purposes:
SDL_ThreadID();
return;
}
示例11: SDL_SYS_CreateThread
int SDL_SYS_CreateThread(SDL_Thread *thread, void *args)
{
pthread_attr_t type;
/* Set the thread attributes */
if ( pthread_attr_init(&type) != 0 ) {
SDL_SetError("Couldn't initialize pthread attributes");
return(-1);
}
pthread_attr_setdetachstate(&type, PTHREAD_CREATE_JOINABLE);
/* Create the thread and go! */
if ( pthread_create(&thread->handle, &type, RunThread, args) != 0 ) {
SDL_SetError("Not enough resources to create thread");
return(-1);
}
if (riscos_using_threads == 0)
{
riscos_using_threads = 1;
riscos_main_thread = SDL_ThreadID();
}
return(0);
}
示例12: locktexture
HRESULT CDirect3D::LockTexture(void)
{
// Lock the surface and write the pixels
static DWORD d3dflags = D3DLOCK_NO_DIRTY_UPDATE;
lock_texture:
if(GCC_UNLIKELY(!lpTexture || deviceLost)) {
// Try to reset the device, but only when running main thread
#if D3D_THREAD
if((SDL_ThreadID() != SDL_GetThreadID(thread)))
#endif
{
Resize3DEnvironment();
}
if(GCC_UNLIKELY(!lpTexture || deviceLost)) {
LOG_MSG("D3D:Device is lost, locktexture() failed...");
return E_FAIL;
}
// Success, continue as planned...
}
if(GCC_UNLIKELY(lpTexture->LockRect(0, &d3dlr, NULL, d3dflags) != D3D_OK)) {
if(d3dflags) {
d3dflags = 0;
LOG_MSG("D3D:Cannot lock texture, fallback to compatible mode");
goto lock_texture;
} else {
LOG_MSG("D3D:Failed to lock texture!");
}
return E_FAIL;
}
return S_OK;
}
示例13: SDL_ThreadedTimerCheck
void SDL_ThreadedTimerCheck(void)
{
Uint32 now, ms;
SDL_TimerID t, prev, next;
SDL_bool removed;
SDL_mutexP(SDL_timer_mutex);
list_changed = SDL_FALSE;
now = SDL_GetTicks();
for ( prev = NULL, t = SDL_timers; t; t = next ) {
removed = SDL_FALSE;
ms = t->interval - SDL_TIMESLICE;
next = t->next;
if ( (int)(now - t->last_alarm) > (int)ms ) {
struct _SDL_TimerID timer;
if ( (now - t->last_alarm) < t->interval ) {
t->last_alarm += t->interval;
} else {
t->last_alarm = now;
}
#ifdef DEBUG_TIMERS
printf("Executing timer %p (thread = %d)\n",
t, SDL_ThreadID());
#endif
timer = *t;
SDL_mutexV(SDL_timer_mutex);
ms = timer.cb(timer.interval, timer.param);
SDL_mutexP(SDL_timer_mutex);
if ( list_changed ) {
/* Abort, list of timers modified */
/* FIXME: what if ms was changed? */
break;
}
if ( ms != t->interval ) {
if ( ms ) {
t->interval = ROUND_RESOLUTION(ms);
} else {
/* Remove timer from the list */
#ifdef DEBUG_TIMERS
printf("SDL: Removing timer %p\n", t);
#endif
if ( prev ) {
prev->next = next;
} else {
SDL_timers = next;
}
SDL_free(t);
--SDL_timer_running;
removed = SDL_TRUE;
}
}
}
/* Don't update prev if the timer has disappeared */
if ( ! removed ) {
prev = t;
}
}
SDL_mutexV(SDL_timer_mutex);
}
示例14: catch
int Thread::run_thread(Thread* t) {
int ret = 0;
sptr<Thread> sp = t;
running_threads[SDL_ThreadID()] = sp;
try {
ret = sp->run();
} catch (exception& ex) {
cout << "Thread " << SDL_ThreadID() << " caught unexpected exception: " << ex.what() << endl;
}
t->lock();
t->running = false;
t->unlock();
running_threads.erase(SDL_ThreadID());
return ret;
}
示例15: SDL_mutexP
/* Lock the semaphore */
int SDL_mutexP(SDL_mutex *mutex)
{
#if SDL_THREADS_DISABLED
return 0;
#else
Uint32 this_thread;
if ( mutex == NULL ) {
SDL_SetError("Passed a NULL mutex");
return -1;
}
this_thread = SDL_ThreadID();
if ( mutex->owner == this_thread ) {
++mutex->recursive;
} else {
/* The order of operations is important.
We set the locking thread id after we obtain the lock
so unlocks from other threads will fail.
*/
lock(&mutex->mutex);
mutex->owner = this_thread;
mutex->recursive = 0;
}
return 0;
#endif /* SDL_THREADS_DISABLED */
}