Example #1
0
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;
	}
}
Example #2
0
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;
}
Example #3
0
//	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;
}
Example #4
0
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;
}
Example #5
0
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);
}
Example #6
0
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 */
}
Example #7
0
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);
}
Example #8
0
/* 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 */
}
Example #9
0
/* 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 */
}
Example #10
0
void
SDL_SYS_SetupThread(const char *name)
{
    // Make sure a thread ID gets assigned ASAP, for debugging purposes:
    SDL_ThreadID();
    return;
}
Example #11
0
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);
}
Example #12
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;
}
Example #13
0
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);
}
Example #14
0
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;
}
Example #15
0
/* 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 */
}
Example #16
0
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();
    }
}
Example #17
0
/*
 * 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 */
Example #18
0
/*
==================
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";
}
Example #19
0
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);
}
Example #20
0
/* 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 */
}
Example #21
0
HRESULT CDirect3D::InitializeDX(HWND wnd, bool triplebuf)
{
#if LOG_D3D
    LOG_MSG("D3D:Starting Direct3D");
#endif

	backbuffer_clear_countdown = 0;

    // Check for display window
    if(!wnd) {
	LOG_MSG("Error: No display window set!");
	return E_FAIL;
    }

    hwnd = wnd;

	if (mhmodDX9 == NULL)
		mhmodDX9 = LoadLibrary("d3d9.dll");
    if (mhmodDX9 == NULL)
		return E_FAIL;

    // Set the presentation parameters
    ZeroMemory(&d3dpp, sizeof(d3dpp));
    d3dpp.BackBufferWidth = dwWidth;
    d3dpp.BackBufferHeight = dwHeight;
    d3dpp.BackBufferCount = 1;
    d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
    d3dpp.Windowed = true;
    d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
	Section_prop * sec=static_cast<Section_prop *>(control->GetSection("vsync"));
	if(sec) {
			d3dpp.PresentationInterval = (!strcmp(sec->Get_string("vsyncmode"),"host"))?D3DPRESENT_INTERVAL_DEFAULT:D3DPRESENT_INTERVAL_IMMEDIATE;
	}


    if(triplebuf) {
	LOG_MSG("D3D:Using triple buffering");
	d3dpp.BackBufferCount = 2;
    }

    // Init Direct3D
    if(FAILED(InitD3D())) {
	DestroyD3D();
	LOG_MSG("Error: Unable to initialize DirectX9!");
	return E_FAIL;
    }

#if D3D_THREAD
#if LOG_D3D
    LOG_MSG("D3D:Starting worker thread from thread: %u", SDL_ThreadID());
#endif

    thread_run = true;
    thread_command = D3D_IDLE;
    thread = SDL_CreateThread(EntryPoint, this);
    SDL_SemWait(thread_ack);
#endif

    return S_OK;
}
Example #22
0
void
SDL_Unlock_EventThread(void)
{
    if (SDL_EventThread && (SDL_ThreadID() != event_thread)) {
        SDL_mutexV(SDL_EventLock.lock);
    }
}
Example #23
0
SDL_bool
SDL_RemoveTimer(SDL_TimerID id)
{
    SDL_TimerID t, prev = NULL;
    SDL_bool removed;

    removed = SDL_FALSE;
    SDL_mutexP(SDL_timer_mutex);
    /* Look for id in the linked list of timers */
    for (t = SDL_timers; t; prev = t, t = t->next) {
        if (t == id) {
            if (prev) {
                prev->next = t->next;
            } else {
                SDL_timers = t->next;
            }
            SDL_free(t);
            --SDL_timer_running;
            removed = SDL_TRUE;
            list_changed = SDL_TRUE;
            break;
        }
    }
#ifdef DEBUG_TIMERS
    printf("SDL_RemoveTimer(%08x) = %d num_timers = %d thread = %d\n",
           (Uint32) id, removed, SDL_timer_running, SDL_ThreadID());
#endif
    SDL_mutexV(SDL_timer_mutex);
    return removed;
}
Example #24
0
int ANDROID_VideoInit(_THIS, SDL_PixelFormat *vformat)
{
	int i;
	static SDL_PixelFormat alphaFormat;

	/* Determine the screen depth (use default 16-bit depth) */
	/* we change this during the SDL_SetVideoMode implementation... */
	if( vformat ) {
		vformat->BitsPerPixel = ANDROID_BITSPERPIXEL;
		vformat->BytesPerPixel = ANDROID_BYTESPERPIXEL;
	}

	int bpp;
	SDL_memset(&alphaFormat, 0, sizeof(alphaFormat));
	SDL_PixelFormatEnumToMasks( SDL_PIXELFORMAT_RGBA4444, &bpp,
								&alphaFormat.Rmask, &alphaFormat.Gmask, 
								&alphaFormat.Bmask, &alphaFormat.Amask );
	alphaFormat.BitsPerPixel = ANDROID_BITSPERPIXEL;
	alphaFormat.BytesPerPixel = ANDROID_BYTESPERPIXEL;
	this->displayformatalphapixel = &alphaFormat;

	this->info.hw_available = 1;
	this->info.blit_hw = 1;
	this->info.blit_hw_CC = 1;
	this->info.blit_hw_A = 1;
	this->info.blit_fill = 1;
	this->info.video_mem = 128 * 1024; // Random value
	this->info.current_w = SDL_ANDROID_sWindowWidth;
	this->info.current_h = SDL_ANDROID_sWindowHeight;
	SDL_VideoThreadID = SDL_ThreadID();

	for ( i=0; i<SDL_NUMMODES; ++i ) {
		SDL_modelist[i] = SDL_malloc(sizeof(SDL_Rect));
		SDL_modelist[i]->x = SDL_modelist[i]->y = 0;
	}
	/* Modes sorted largest to smallest */
	SDL_modelist[0]->w = SDL_ANDROID_sWindowWidth;
	SDL_modelist[0]->h = SDL_ANDROID_sWindowHeight;
	SDL_modelist[1]->w = 800; SDL_modelist[1]->h = 600; // Will likely be shrinked
	SDL_modelist[2]->w = 640; SDL_modelist[2]->h = 480; // Will likely be shrinked
	SDL_modelist[3]->w = 640; SDL_modelist[3]->h = 400; // Will likely be shrinked
	SDL_modelist[4]->w = 320; SDL_modelist[4]->h = 240; // Always available on any screen and any orientation
	SDL_modelist[5]->w = 320; SDL_modelist[5]->h = 200; // Always available on any screen and any orientation
	SDL_modelist[6]->w = 256; SDL_modelist[6]->h = 224; // For REminiscence
	SDL_modelist[7]->w = SDL_ANDROID_sWindowWidth * 2 / 3;
	SDL_modelist[7]->h = SDL_ANDROID_sWindowHeight * 2 / 3;
	SDL_modelist[8]->w = SDL_ANDROID_sWindowWidth / 2;
	SDL_modelist[8]->h = SDL_ANDROID_sWindowHeight / 2;
	SDL_modelist[9]->w = 480; SDL_modelist[9]->h = 320; // Virtual wide-screen mode
	SDL_modelist[10]->w = 800; SDL_modelist[10]->h = 480; // Virtual wide-screen mode
	SDL_modelist[11]->w = 544; SDL_modelist[11]->h = 332; // I have no idea where this videomode is used
	SDL_modelist[12] = NULL;
	
	SDL_VideoInit_1_3(NULL, 0);
	
	/* We're done! */
	return(0);
}
Example #25
0
int CDirect3D::Start(void)
{
#if LOG_D3D
    LOG_MSG("D3D:Worker thread %u starting", SDL_ThreadID());
#endif

    SDL_SemPost(thread_ack);

    EnterCriticalSection(&cs);
    while(thread_run) {

	HRESULT hr;
	D3D_state tmp = thread_command;
	LeaveCriticalSection(&cs);

	if(tmp == D3D_IDLE) {
	    SDL_SemWait(thread_sem);
	    EnterCriticalSection(&cs);
	    continue;
	}

	switch(tmp) {
	    case D3D_LOADPS: hr = LoadPixelShader(); break;
	    case D3D_LOCK: hr = LockTexture(); break;
	    case D3D_UNLOCK: (UnlockTexture() ? hr = S_OK : hr = E_FAIL); break;
	    default: hr = S_OK; break;
	}

	EnterCriticalSection(&cs);
	thread_hr = hr;
	thread_command = D3D_IDLE;
	if(wait) {
		LeaveCriticalSection(&cs);
		SDL_SemPost(thread_ack);
		EnterCriticalSection(&cs);
	}
    }

#if LOG_D3D
    LOG_MSG("D3D:Thread %u is finishing...", SDL_ThreadID());
#endif
    LeaveCriticalSection(&cs);

    return 0;
}
Example #26
0
void NetworkThread::Wait()
{
  if (thread != NULL && SDL_ThreadID() != SDL_GetThreadID(thread)) {
    SDL_WaitThread(thread, NULL);
  }

  thread = NULL;
  stop_thread = false;
}
Example #27
0
void SDL_ThreadedTimerCheck(void)
{
	Uint32 now, ms;
	SDL_TimerID t, prev, next;
	int removed;

	now = SDL_GetTicks();

	SDL_mutexP(SDL_timer_mutex);
	for ( prev = NULL, t = SDL_timers; t; t = next ) {
		removed = 0;
		ms = t->interval - SDL_TIMESLICE;
		next = t->next;
		if ( (t->last_alarm < now) && ((now - t->last_alarm) > ms) ) {
			if ( (now - t->last_alarm) < t->interval ) {
				t->last_alarm += t->interval;
			} else {
				t->last_alarm = now;
			}
			list_changed = SDL_FALSE;
#ifdef DEBUG_TIMERS
			printf("Executing timer %p (thread = %d)\n",
						t, SDL_ThreadID());
#endif
			SDL_mutexV(SDL_timer_mutex);
			ms = t->cb(t->interval, t->param);
			SDL_mutexP(SDL_timer_mutex);
			if ( list_changed ) {
				/* Abort, list of timers has been modified */
				break;
			}
			if ( ms != t->interval ) {
				if ( ms ) {
					t->interval = ROUND_RESOLUTION(ms);
				} else { /* Remove the timer from the linked list */
#ifdef DEBUG_TIMERS
					printf("SDL: Removing timer %p\n", t);
#endif
					if ( prev ) {
						prev->next = next;
					} else {
						SDL_timers = next;
					}
					free(t);
					-- num_timers;
					removed = 1;
				}
			}
		}
		/* Don't update prev if the timer has disappeared */
		if ( ! removed ) {
			prev = t;
		}
	}
	SDL_mutexV(SDL_timer_mutex);
}
Example #28
0
int sdlwindow_init(running_machine *machine)
{
	// determine if we are using multithreading or not
	multithreading_enabled = options_get_bool(mame_options(), SDLOPTION_MULTITHREADING);

	// get the main thread ID before anything else
	main_threadid = SDL_ThreadID();

	// ensure we get called on the way out
	add_exit_callback(machine, sdlwindow_exit);

	// if multithreading, create a thread to run the windows
	if (multithreading_enabled)
	{
		// create a thread to run the windows from
#ifndef SDLMAME_OS2
		work_queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_IO);
#else
		work_queue = osd_work_queue_alloc(WORK_QUEUE_FLAG_IO);
#endif
		if (work_queue == NULL)
			return 1;
		osd_work_item_queue(work_queue, &sdlwindow_thread_id, NULL, WORK_ITEM_FLAG_AUTO_RELEASE);
	}
	else
	{
		// otherwise, treat the window thread as the main thread
		//window_threadid = main_threadid;
		sdlwindow_thread_id(NULL, 0);
	}

	// initialize the drawers
#if USE_OPENGL
	if (video_config.mode == VIDEO_MODE_OPENGL)
	{
		if (drawogl_init(&draw))
			video_config.mode = VIDEO_MODE_SOFT;
	}
#endif
#if	SDL_VERSION_ATLEAST(1,3,0)
	if (video_config.mode == VIDEO_MODE_SDL13)
	{
		if (draw13_init(&draw))
			video_config.mode = VIDEO_MODE_SOFT;
	}
#endif
	if (video_config.mode == VIDEO_MODE_SOFT)
	{
		if (drawsdl_init(&draw))
			return 1;
	}

	// set up the window list
	last_window_ptr = &sdl_window_list;
	return 0;
}
Example #29
0
void SDL_Lock_EventThread(void)
{
	if ( SDL_EventThread && (SDL_ThreadID() != event_thread) ) {
		
		SDL_mutexP(SDL_EventLock.lock);
		while ( ! SDL_EventLock.safe ) {
			SDL_Delay(1);
		}
	}
}
Example #30
0
void osd_lock_acquire(osd_lock *lock)
{
	hidden_mutex_t *mutex = (hidden_mutex_t *) lock;

	LOG(("osd_lock_acquire"));
	/* get the lock */
	mutex->locked++; /* signal that we are *about* to lock - prevent osd_lock_try */
	SDL_mutexP(mutex->id);
	mutex->threadid = SDL_ThreadID();
}