예제 #1
0
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;
}
예제 #2
0
/*
==================
Sys_CreateThread
==================
*/
void Sys_CreateThread(xthread_t function, void *parms, xthreadInfo& info, const char *name) {
	Sys_EnterCriticalSection();

#if SDL_VERSION_ATLEAST(2, 0, 0)
	SDL_Thread *t = SDL_CreateThread(function, name, parms);
#else
	SDL_Thread *t = SDL_CreateThread(function, parms);
#endif

	if (!t) {
		common->Error("ERROR: SDL_thread for '%s' failed\n", name);
		Sys_LeaveCriticalSection();
		return;
	}

	info.name = name;
	info.threadHandle = t;
	info.threadId = SDL_GetThreadID(t);

	if (thread_count < MAX_THREADS)
		thread[thread_count++] = &info;
	else
		common->DPrintf("WARNING: MAX_THREADS reached\n");

	Sys_LeaveCriticalSection();
}
예제 #3
0
HANDLE WINAPI CreateThread(
      LPSECURITY_ATTRIBUTES lpThreadAttributes,
        SIZE_T dwStackSize,
          LPTHREAD_START_ROUTINE lpStartAddress,
            LPVOID lpParameter,
        DWORD dwCreationFlags,
          LPDWORD lpThreadId
    ) {

        // a thread handle would actually contain an event
        // the event would mark if the thread is running or not. it will be used in the Wait functions.
  // DO NOT use SDL_WaitThread for waiting. it will delete the thread object.
  HANDLE h = CreateEvent(NULL, TRUE, FALSE, NULL);
  h->ChangeType(CXHandle::HND_THREAD);
  InternalThreadParam *pParam = new InternalThreadParam;
  pParam->threadFunc = lpStartAddress;
  pParam->data = lpParameter;
  pParam->handle = h;

  h->m_nRefCount++;
  h->m_hThread = SDL_CreateThread(InternalThreadFunc, (void*)pParam);
  if (lpThreadId)
    *lpThreadId = SDL_GetThreadID(h->m_hThread);
  return h;

}
예제 #4
0
파일: network.cpp 프로젝트: fluxer/warmux
void NetworkThread::Wait()
{
  if (thread != NULL && SDL_ThreadID() != SDL_GetThreadID(thread)) {
    SDL_WaitThread(thread, NULL);
  }

  thread = NULL;
  stop_thread = false;
}
예제 #5
0
static void
LocalStats (SDL_Thread *thread) {
#if defined (WIN32) || !defined(SDL_PTHREADS)
	fprintf (stderr, "Thread ID %u\n", SDL_GetThreadID (thread));
#else  /* !defined (WIN32) && defined(SDL_PTHREADS) */
	// This only works if SDL implements threads as processes
	pid_t pid;
	struct rusage ru;
	long seconds;

	pid = (pid_t) SDL_GetThreadID (thread);
	fprintf (stderr, "Pid %d\n", (int) pid);
	getrusage(RUSAGE_SELF, &ru);
	seconds = ru.ru_utime.tv_sec + ru.ru_utime.tv_sec;
	fprintf (stderr, "Used %ld.%ld minutes of processor time.\n",
			seconds / 60, seconds % 60);
#endif  /* defined (WIN32) && defined(SDL_PTHREADS) */
}
예제 #6
0
파일: download.cpp 프로젝트: Ablu/invertika
void Download::cancel()
{
    logger->log("Canceling download: %s", mUrl.c_str());

    mOptions.cancel = true;
    if (mThread && SDL_GetThreadID(mThread) != 0)
    {
        SDL_WaitThread(mThread, NULL);
        mThread = NULL;
    }
}
예제 #7
0
static void OHQ_Call(_THIS, void (*func)(SDL_VideoDevice*))
{
    if (this->VideoInit != OHQ_VideoInit) {
        func(this);
    } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) {
        func(this->hidden->real_video);
    } else {
        this->hidden->call.type = OGL_CALL_P;
        this->hidden->call.func.p = func;
        SendSyncCommand(this,OGL_CALL);
    }
}
예제 #8
0
IPC::~IPC()
{
    mListen = false;
    if (mSocket)
    {
        TcpNet::closeSocket(mSocket);
        mSocket = nullptr;
    }
    int status;
    if (mThread && SDL_GetThreadID(mThread))
        SDL_WaitThread(mThread, &status);
    mThread = nullptr;
}
예제 #9
0
static int OHQ_Call__i(_THIS, int (*func)(SDL_VideoDevice*))
{
    if (this->VideoInit != OHQ_VideoInit) {
        return func(this);
    } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) {
        return func(this->hidden->real_video);
    } else {
        this->hidden->call.type = OGL_CALL_P_I;
        this->hidden->call.func.p_i = func;
        SendSyncCommand(this,OGL_CALL);
        return (int)this->hidden->call.result;
    }
}
예제 #10
0
static void OHQ_Call_p(_THIS, void (*func)(SDL_VideoDevice*,const void*), const void* arg1)
{
    if (this->VideoInit != OHQ_VideoInit) {
        func(this,arg1);
    } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) {
        func(this->hidden->real_video,arg1);
    } else {
        this->hidden->call.type = OGL_CALL_PP;
        this->hidden->call.func.pp = func;
        this->hidden->call.args[0] = (intptr_t)arg1;
        SendSyncCommand(this,OGL_CALL);
    }
}
예제 #11
0
static void OHQ_Call_ii(_THIS, void (*func)(SDL_VideoDevice*,int,int), int arg1, int arg2)
{
    if (this->VideoInit != OHQ_VideoInit) {
        func(this,arg1,arg2);
    } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) {
        func(this->hidden->real_video,arg1,arg2);
    } else {
        this->hidden->call.type = OGL_CALL_PII;
        this->hidden->call.func.pii = func;
        this->hidden->call.args[0] = (intptr_t)arg1;
        this->hidden->call.args[1] = (intptr_t)arg2;
        SendSyncCommand(this,OGL_CALL);
    }
}
예제 #12
0
static int OHQ_Call_i_i(_THIS, int (*func)(SDL_VideoDevice*,int), int arg1)
{
    if (this->VideoInit != OHQ_VideoInit) {
        return func(this,arg1);
    } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) {
        return func(this->hidden->real_video,arg1);
    } else {
        this->hidden->call.type = OGL_CALL_PI_I;
        this->hidden->call.func.pi_i = func;
        this->hidden->call.args[0] = (intptr_t)arg1;
        SendSyncCommand(this,OGL_CALL);
        return (int)this->hidden->call.result;
    }
}
bool
BoostThreadPriority(SDL_Thread* inThread) {
#if defined(_POSIX_PRIORITY_SCHEDULING)
    pthread_t		theTargetThread = (pthread_t) SDL_GetThreadID(inThread);
    int			theSchedulingPolicy;
    struct sched_param	theSchedulingParameters;

    if(pthread_getschedparam(theTargetThread, &theSchedulingPolicy, &theSchedulingParameters) != 0)
        return false;

    theSchedulingParameters.sched_priority =
        sched_get_priority_max(theSchedulingPolicy);

    if(pthread_setschedparam(theTargetThread, theSchedulingPolicy, &theSchedulingParameters) != 0)
        return false;
#endif
    return true;
}
예제 #14
0
WhoIsOnline::~WhoIsOnline()
{
    config.removeListeners(this);

    if (mThread && SDL_GetThreadID(mThread))
        SDL_WaitThread(mThread, nullptr);

    free(mMemoryBuffer);
    mMemoryBuffer = nullptr;

    // Remove possibly leftover temporary download
    delete []mCurlError;

    FOR_EACH (std::set<OnlinePlayer*>::iterator, itd, mOnlinePlayers)
        delete *itd;
    mOnlinePlayers.clear();
    mOnlineNicks.clear();
}
예제 #15
0
static TrueThread
FindThreadInfo (Uint32 threadID)
{
	TrueThread ptr;

	SDL_mutexP (threadQueueMutex);
	ptr = threadQueue;
	while (ptr)
	{
		if (SDL_GetThreadID (ptr->native) == threadID)
		{
			SDL_mutexV (threadQueueMutex);
			return ptr;
		}
		ptr = ptr->next;
	}
	SDL_mutexV (threadQueueMutex);
	return NULL;
}
예제 #16
0
static void* OHQ_Call_ppiiii_p(_THIS, void* (*func)(SDL_VideoDevice*,const void*,const void*,int,int,int,int), const void* arg1, const void* arg2, int arg3, int arg4, int arg5, int arg6)
{
    if (this->VideoInit != OHQ_VideoInit) {
        return func(this,arg1,arg2,arg3,arg4,arg5,arg6);
    } else if (SDL_ThreadID() == SDL_GetThreadID(this->hidden->render_thread)) {
        return func(this->hidden->real_video,arg1,arg2,arg3,arg4,arg5,arg6);
    } else {
        this->hidden->call.type = OGL_CALL_PPPIIII_P;
        this->hidden->call.func.pppiiii_p = func;
        this->hidden->call.args[0] = (intptr_t)arg1;
        this->hidden->call.args[1] = (intptr_t)arg2;
        this->hidden->call.args[2] = (intptr_t)arg3;
        this->hidden->call.args[3] = (intptr_t)arg4;
        this->hidden->call.args[4] = (intptr_t)arg5;
        this->hidden->call.args[5] = (intptr_t)arg6;
        SendSyncCommand(this,OGL_CALL);
        return (void*)this->hidden->call.result;
    }
}
예제 #17
0
void Network::disconnect()
{
    mState = IDLE;

    if (mWorkerThread && SDL_GetThreadID(mWorkerThread))
    {
        SDL_WaitThread(mWorkerThread, nullptr);
        mWorkerThread = nullptr;
    }

    if (mSocket)
    {
        // need call SDLNet_TCP_DelSocket?
        SDLNet_TCP_Close(mSocket);
        mSocket = nullptr;
        int sleep = config.getIntValue("networksleep");
        if (sleep > 0)
            SDL_Delay(sleep);
    }
}
예제 #18
0
파일: mt.c 프로젝트: yoanlcq/FATE
fe_mt_thread  fe_mt_thread_create(int (*func)(void*), const char *name, void *arg) {
    SDL_Thread *th = SDL_CreateThread(func, name, arg);
    if(!th)
        return -1;
    fe_mt_mutex_lock(&pool_mutex);
    size_t i;
    for(i=0 ; i<pool.count ; ++i)
        if(!pool.slots[i].taken)
            goto allocate;
    pool.slots = fe_mem_heaprealloc(pool.slots, i+1, fe_mt_threadpool_slot, "");
    if(!pool.slots) {
        fe_mt_mutex_unlock(&pool_mutex);
        return -1;
    }
allocate:
    pool.slots[i].taken = true;
    pool.slots[i].thread = th;
    pool.slots[i].id = SDL_GetThreadID(th);
    fe_mt_mutex_unlock(&pool_mutex);
    return i;
}
예제 #19
0
	Uint32 get_id() { return SDL_GetThreadID(thread_); }
예제 #20
0
		Uint32 GetThreadID(Thread *thread)
		{
			return SDL_GetThreadID(thread);
		}
예제 #21
0
int main(int m_argc, char **m_argv)
{

	int
		terminated;

	SDL_Event
		evert;

	argc = m_argc;
	argv = m_argv;

	//
	// Initialise SDL
	//

	atexit(SDL_Quit);

	if( SDL_Init(SDL_INIT_EVERYTHING) != 0 ) {
		debug_fatal("Unable to initialise SDL: %s", SDL_GetError());
		return 1;
	}

	//
	// Install our own exception handler!
	//

	initialise_application_exception_handler ();

	//
	// Set the current directory to where the executable is located
	//

	set_application_current_directory ();

	//
	// Unlink the debug.log file here.
	//

	unlink ( "debug.log" );

	system_thread_id = SDL_ThreadID ();

	application_debug_fatal = FALSE;

	application_active = TRUE;

	//
	// Initialise the memory statistics
	//

	initialise_memory_totals ();

	if ( !initialise_windows ( 1 ) )
	{

		deinitialise_windows ();

		return ( FALSE );
	}

	number_user_message_functions = 0;

	number_system_message_functions = 0;

	register_system_message_function ( SDL_USEREVENT, call_user_function_routine );

	// register_system_message_function ( WM_SETCURSOR, windows_cursor_routine );

	register_system_message_function ( SDL_VIDEOEXPOSE, windows_paint_routine  );

	register_system_message_function ( SDL_VIDEORESIZE, windows_sizemove_routine );

	register_system_message_function ( SDL_SYSWMEVENT, windows_systemcommand_routine );

	register_system_message_function ( SDL_QUIT, windows_close_request_routine );

	initialise_cdrom_system ();

	initialise_system_thread_calling_function ();

	exit_message_id = get_unique_message_id ();

	register_user_message_function ( exit_message_id, windows_exit_routine );

	//
	// The graphics / 3d / 2d systems need the maths fpu to round to zero
	//

	set_fpu_rounding_mode_zero ();

	set_fpu_exceptions ();

	initialise_event_system ();

	initialise_timers_system ();

	initialise_file_system ();

	terminated = FALSE;

	application_thread_handle = (SDL_Thread *) SDL_CreateThread ( start_application, NULL );
											  
	application_thread_id = SDL_GetThreadID ( application_thread_handle );

	// SetThreadPriority ( GetCurrentThread (), THREAD_PRIORITY_ABOVE_NORMAL );

	while(SDL_WaitEvent( &evert ))
	{

		if(!application_window_proc(&evert)) {
			generate_keyboard_events ( &evert );
			generate_mouse_events ( &evert );
		}
	}

	return ( 0 );
}
예제 #22
0
파일: thread.cpp 프로젝트: ArtBears/wesnoth
boost::uint32_t threading::thread::get_id() { return SDL_GetThreadID(thread_); }
예제 #23
0
 unsigned int Thread::get_id() {
   return SDL_GetThreadID(m_impl);
 }