• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ SDL_ThreadID函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中SDL_ThreadID函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_ThreadID函数的具体用法?C++ SDL_ThreadID怎么用?C++ SDL_ThreadID使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了SDL_ThreadID函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
	}
}
开发者ID:crazii,项目名称:mameplus,代码行数:27,代码来源:sync_sdl.c


示例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;
}
开发者ID:fluxer,项目名称:warmux,代码行数:7,代码来源:network.cpp


示例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;
}
开发者ID:pjbroad,项目名称:other-life,代码行数:10,代码来源:achievements.cpp


示例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;
}
开发者ID:Avoidnf8,项目名称:xbmc-fork,代码行数:49,代码来源:XThreadUtils.cpp


示例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);
}
开发者ID:AlexOteiza,项目名称:n64ios,代码行数:49,代码来源:SDL_systimer.c


示例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 */
}
开发者ID:ChickenEggSolutions,项目名称:apitest,代码行数:35,代码来源:testlock.c


示例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);
}
开发者ID:Goettsch,项目名称:game-editor,代码行数:27,代码来源:SDL_thread.c


示例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 */
}
开发者ID:Goettsch,项目名称:game-editor,代码行数:29,代码来源:SDL_sysmutex.c


示例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 */
}
开发者ID:Daft-Freak,项目名称:vogl,代码行数:32,代码来源:SDL_sysmutex.c


示例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;
}
开发者ID:wanliLiu,项目名称:BarSwipe,代码行数:7,代码来源:SDL_systhread.cpp


示例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);
}
开发者ID:0-14N,项目名称:NDroid,代码行数:25,代码来源:SDL_systhread.c


示例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;
}
开发者ID:joncampbell123,项目名称:dosbox-x,代码行数:32,代码来源:direct3d.cpp


示例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);
}
开发者ID:ahpho,项目名称:wowmapviewer,代码行数:60,代码来源:SDL_timer.c


示例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;
}
开发者ID:jspenguin,项目名称:glbumper,代码行数:16,代码来源:object.cpp


示例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 */
}
开发者ID:JQE,项目名称:libSDLXenon,代码行数:29,代码来源:SDL_sysmutex.c


示例16: SDL_ThreadID

void LevelStreamLogger::appendStream() {
    
    if (logger == NULL) {
        return;
    }
    
    bool messageMode = true;
    
    // This one just gets the thread id for display in the message
    // ie. no other functional purposes.
    unsigned int tid = SDL_ThreadID();
    
    if (!messageMode) {
        //logger->append(level, logstream.str().c_str());
        LoggerEvent* e = new LoggerEvent(logger, level,  logstream.str().c_str(), tid);
        logger->append(e);
        logstream.clear();
        logstream.str("");
    } else {
        char buffer[1024];
        logstream.clear();
        logstream.getline(buffer, sizeof(buffer), '\n');
        if (logstream.good()) {
            //logger->append(level, logstream.str().c_str());
            LoggerEvent* e = new LoggerEvent(logger, level,  logstream.str().c_str(), tid);
            //LoggerEvent* e = new LoggerEvent(logger, level, buffer);
            logger->append(e);
            logstream.str("");
        }
        logstream.clear();
    }
}
开发者ID:Knitter,项目名称:linwarrior,代码行数:32,代码来源:LevelStreamLogger.cpp


示例17: __Sound_SetError

/*
 * This is declared in the internal header.
 */
void __Sound_SetError(const char *str)
{
    ErrMsg *err;

    if (str == NULL)
        return;

    SNDDBG(("__Sound_SetError(\"%s\");%s\n", str,
              (initialized) ? "" : " [NOT INITIALIZED!]"));

    if (!initialized)
        return;

    err = findErrorForCurrentThread();
    if (err == NULL)
    {
        err = (ErrMsg *) malloc(sizeof (ErrMsg));
        if (err == NULL)
            return;   /* uhh...? */

        memset((void *) err, '\0', sizeof (ErrMsg));
        err->tid = SDL_ThreadID();

        SDL_LockMutex(errorlist_mutex);
        err->next = error_msgs;
        error_msgs = err;
        SDL_UnlockMutex(errorlist_mutex);
    } /* if */

    err->error_available = 1;
    strncpy(err->error_string, str, sizeof (err->error_string));
    err->error_string[sizeof (err->error_string) - 1] = '\0';
} /* __Sound_SetError */
开发者ID:AvelNaytroud,项目名称:libsdl-sound,代码行数:36,代码来源:SDL_sound.c


示例18: Sys_EnterCriticalSection

/*
==================
Sys_GetThreadName
find the name of the calling thread
==================
*/
const char *Sys_GetThreadName(int *index) {
	const char *name;

	Sys_EnterCriticalSection();

	unsigned int id = SDL_ThreadID();

	for (int i = 0; i < thread_count; i++) {
		if (id == thread[i]->threadId) {
			if (index)
				*index = i;

			name = thread[i]->name;

			Sys_LeaveCriticalSection();

			return name;
		}
	}

	if (index)
		*index = -1;

	Sys_LeaveCriticalSection();

	return "main";
}
开发者ID:Salamek,项目名称:Shadow-of-Dust,代码行数:33,代码来源:threads.cpp


示例19: CloseStuff

static void CloseStuff(int signum)
{
        printf(_("\nSignal %d has been caught and dealt with...\n"),signum);

	for(unsigned int x = 0; x < sizeof(SignalDefs) / sizeof(SignalInfo); x++)
	{
	 if(SignalDefs[x].number == signum)
	 {
	  printf("%s", _(SignalDefs[x].message));
	  if(SignalDefs[x].SafeTryExit)
	  {
	   SDL_Event evt;

	   memset(&evt, 0, sizeof(SDL_Event));

	   evt.user.type = SDL_QUIT;
	   SDL_PushEvent(&evt);
	   return;
	  }

	  break;
	 }
	}
        if(GameThread && SDL_ThreadID() == MainThreadID)
	{
	 SDL_KillThread(GameThread);
	 GameThread = NULL;
	}
        exit(1);
}
开发者ID:ben401,项目名称:OpenEmu,代码行数:30,代码来源:main.cpp


示例20: SDL_mutexV

/* Unlock the mutex */
int SDL_mutexV(SDL_mutex *mutex)
{
#if SDL_THREADS_DISABLED
    return 0;
#else
    if ( mutex == NULL ) {
        SDL_SetError("Passed a NULL mutex");
        return -1;
    }

    /* If we don't own the mutex, we can't unlock it */
    if ( SDL_ThreadID() != mutex->owner ) {
        SDL_SetError("mutex not owned by this thread");
        return -1;
    }

    if ( mutex->recursive ) {
        --mutex->recursive;
    } else {
        /* The order of operations is important.
           First reset the owner so another thread doesn't lock
           the mutex and set the ownership before we reset it,
           then release the lock semaphore.
         */
        mutex->owner = 0;
        unlock(&mutex->mutex);
    }
    return 0;
#endif /* SDL_THREADS_DISABLED */
}
开发者ID:JQE,项目名称:libSDLXenon,代码行数:31,代码来源:SDL_sysmutex.c



注:本文中的SDL_ThreadID函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ ScriptSourceCode函数代码示例发布时间:2022-05-30
下一篇:
C++ SDL_RWread函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap