Esempio n. 1
0
rt_err_t rt_mq_recv (rt_mq_t mq, void* buffer, rt_size_t size, rt_int32_t timeout)
{
	rt_err_t r;
	struct rt_mq_message *msg;

	SDL_SemWait(hmq->mutex);

	/* mq is empty */
	if (mq->entry == 0)
	{
		SDL_SemPost(hmq->mutex);

		if (timeout == RT_WAITING_FOREVER)
		{
			r = SDL_SemWait(hmq->msg);
		}
		else
		{
			r = SDL_SemWaitTimeout(hmq->msg, timeout * 10);
		}

		if (r != 0) return -RT_ERROR;

		SDL_SemWait(hmq->mutex);
	}
	else
	{
		/* take one message */
		SDL_SemWait(hmq->msg);
	}

	/* get message from queue */
	msg = (struct rt_mq_message*) mq->msg_queue_head;

	/* move message queue head */
	mq->msg_queue_head = msg->next;

	/* reach queue tail, set to NULL */
	if (mq->msg_queue_tail == msg) mq->msg_queue_tail = RT_NULL;

	/* copy message */
	rt_memcpy(buffer, msg + 1,
		size > mq->msg_size? (unsigned short)(mq->msg_size) : (unsigned short)size);

	/* put message to free list */
	msg->next = (struct rt_mq_message*)mq->msg_queue_free;
	mq->msg_queue_free = msg;

	/* decrease message entry */
	mq->entry --;

	SDL_SemPost(hmq->mutex);

	return RT_EOK;
}
Esempio n. 2
0
rt_err_t rt_mq_send (rt_mq_t mq, void* buffer, rt_size_t size)
{
	struct rt_mq_message *msg;

	/* greater than one message size */
	if (size > mq->msg_size) return -RT_ERROR;

	SDL_SemWait(hmq->mutex);

	/* get a free list, there must be an empty item */
	msg = (struct rt_mq_message*)mq->msg_queue_free;

	/* message queue is full */
	if (msg == RT_NULL)
	{
		SDL_SemPost(hmq->mutex);
		return -RT_EFULL;
	}

	/* move free list pointer */
	mq->msg_queue_free = msg->next;

	/* copy buffer */
	rt_memcpy(msg + 1, buffer, size);

	/* link msg to message queue */
	if (mq->msg_queue_tail != RT_NULL)
	{
		/* if the tail exists, */
		((struct rt_mq_message*)mq->msg_queue_tail)->next = msg;
	}
	/* the msg is the new tail of list, the next shall be NULL */
	msg->next = RT_NULL;

	/* set new tail */
	mq->msg_queue_tail = msg;

	/* if the head is empty, set head */
	if (mq->msg_queue_head == RT_NULL)mq->msg_queue_head = msg;

	/* increase message entry */
	mq->entry ++;

	/* post one message */
	SDL_SemPost(hmq->msg);
	SDL_SemPost(hmq->mutex);

	return RT_EOK;
}
Esempio n. 3
0
t_stat vid_poll_kb (SIM_KEY_EVENT *ev)
{
    if (SDL_SemTryWait (vid_key_events.sem) == 0) {         /* get lock */
        if (vid_key_events.count > 0) {                     /* events in queue? */
            *ev = vid_key_events.events[vid_key_events.head++];
            vid_key_events.count--;
            if (vid_key_events.head == MAX_EVENTS)
                vid_key_events.head = 0;
            SDL_SemPost (vid_key_events.sem);
            return SCPE_OK;
        }
        SDL_SemPost (vid_key_events.sem);
    }
    return SCPE_EOF;
}
Esempio n. 4
0
t_stat vid_poll_mouse (SIM_MOUSE_EVENT *ev)
{
    if (SDL_SemTryWait (vid_mouse_events.sem) == 0) {
        if (vid_mouse_events.count > 0) {
            *ev = vid_mouse_events.events[vid_mouse_events.head++];
            vid_mouse_events.count--;
            if (vid_mouse_events.head == MAX_EVENTS)
                vid_mouse_events.head = 0;
            SDL_SemPost (vid_mouse_events.sem);
            return SCPE_OK;
        }
        SDL_SemPost (vid_mouse_events.sem);
    }
    return SCPE_EOF;
}
/**
 * Get next item from the monitor 
 * @return the next item */
void* SDL_IterMon_get_next(void* monitor)
{
    SDL_IterMon_t* mon;
    void* next;

    mon = monitor;

    if (-1 == SDL_mutexP(mon->mutex)) assert(FALSE);

    /* wait for the iterator to be set */
    while (!mon->iter)
        if (-1 == SDL_CondWait(
                    mon->cond_can_get_iter,
                    mon->mutex)) assert(FALSE);

    assert(mon->iter);

    if (mon->iter_has_next(mon->iter))
    {
        next = mon->iter_get_next(mon->iter);
        assert(next);
    }
    else
    {
        mon->iter_done(mon->iter);
        mon->iter = NULL;
        SDL_SemPost(mon->sem_iterating);
        next = NULL;
    }

    if (-1 == SDL_mutexV(mon->mutex)) assert(FALSE);

    return next;
}
Esempio n. 6
0
static int FIFO_Writer(void* _data)
{
    WriterData *data = (WriterData *)_data;
    SDL_EventQueue *queue = data->queue;
    int index = data->index;
    int i;
    SDL_Event event;

    event.type = SDL_USEREVENT;
    event.user.windowID = 0;
    event.user.code = 0;
    event.user.data1 = data;
    event.user.data2 = NULL;

    if (data->lock_free) {
        for (i = 0; i < EVENTS_PER_WRITER; ++i) {
            event.user.code = i;
            while (!EnqueueEvent_LockFree(queue, &event)) {
                ++data->waits;
                SDL_Delay(0);
            }
        }
    } else {
        for (i = 0; i < EVENTS_PER_WRITER; ++i) {
            event.user.code = i;
            while (!EnqueueEvent_Mutex(queue, &event)) {
                ++data->waits;
                SDL_Delay(0);
            }
        }
    }
    SDL_AtomicAdd(&writersRunning, -1);
    SDL_SemPost(writersDone);
    return 0;
}
Esempio n. 7
0
void SoundSDL::read(u16 * stream, int length)
{
	if (!_initialized || length <= 0 || !emulating)
		return;

#if !JS
	/* since this is running in a different thread, speedup and
	 * throttle can change at any time; save the value so locks
	 * stay in sync */
	bool lock = (emulating && !speedup) ? true : false;

	if (lock)
		SDL_SemWait (_semBufferFull);

	SDL_mutexP(_mutex);
#endif

	_rbuf.read(stream, std::min(static_cast<std::size_t>(length) / 2, _rbuf.used()));

#if !JS
	SDL_mutexV(_mutex);

	SDL_SemPost (_semBufferEmpty);
#endif
}
LISPBUILDERSDLGLUE_API void SDLCALL SDL_glue_SDL_CloseAudio(void) {
	/* Seems this sequence of calls is quite important, or the glue-library will hang.
		1) Bump the semaphore in case the callback is waiting on audio data.
		2) Lock the callback. In effect returns when the callback returns.
		   Also makes sure that the callback cannot be called again before we hav a chance to
		   close the audio device. */
	SDL_SemPost(audio_buffer_lock);
	SDL_LockAudio();

	if (audio_buffer_lock != NULL) {
        SDL_DestroySemaphore(audio_buffer_lock);
        audio_buffer_lock = NULL;
	}
	if (buffer_fill_lock != NULL) {
        SDL_DestroyMutex(buffer_fill_lock);
	    buffer_fill_lock = NULL;
	}
	/*	It is very likely that the audio buffer will be a different size the next time the audio device is opened
		(assuming different input parameters. */
	if (audio_buffer != NULL) {
		free(audio_buffer);
		audio_buffer = NULL;
	}
	SDL_CloseAudio();
}
Esempio n. 9
0
/* Unlock the mutex */
int
SDL_mutexV(SDL_mutex * mutex)
{
#ifdef DISABLE_THREADS
    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;
        SDL_SemPost(mutex->sem);
    }
    return 0;
#endif /* DISABLE_THREADS */
}
Esempio n. 10
0
int graphics_worker_thread(graphics_worker_arg *arg){
    graphics_state *state = arg->state;
    int x0 = state->worker_pixel_ranges[4*arg->i];
    int y0 = state->worker_pixel_ranges[4*arg->i + 1];
    int x1 = state->worker_pixel_ranges[4*arg->i + 2];
    int y1 = state->worker_pixel_ranges[4*arg->i + 3];

    /* raytrace */
    while(1){
        SDL_SemWait(state->sema_start_render);

        int x, y;
        for(y = y0; y < y1; y++) 
        {
            int ytimesw = y * state->width;
            for(x = x0; x < x1; x++) 
            {
                if(!state->stencil[x + ytimesw]){
                    set_pixel(state, x, ytimesw, 0, 0, 0);
                    continue;
                }

                f3 color = graphics_render_pixel(state, x, y);
                set_pixel(state, x, ytimesw, 
                    (Uint8)(color.x*255.9f),
                    (Uint8)(color.y*255.9f),
                    (Uint8)(color.z*255.9f));
            }
        }

        /* let the main thread know we're done rendering */
        SDL_SemPost(state->sema_finish_render);
    }
    return 0;
}
Esempio n. 11
0
// Runs on main thread
void free_particles_thread()
{
	if (!threads) return;

	int i;
	for (i = 0; i < MAX_THREADS; i++)
	{
		int status;
		int sem_res;
		particle_thread *pt = &threads[i];

		printf("Destroying particle thread %d (waiting for mutex)\n", i);
		SDL_mutexP(pt->lock);
		pt->running = FALSE;
		SDL_mutexV(pt->lock);

		printf("Destroying particle thread %d\n", i);
		sem_res = SDL_SemPost(pt->keyframes);
		if (sem_res) printf("Error while waiting for particle thread to die: %s\n", SDL_GetError());
		printf("Destroying particle thread %d (waiting for thread %x)\n", i, (int)pt->thread);
		SDL_WaitThread(pt->thread, &status);
		printf("Destroyed particle thread %d (%d)\n", i, status);
	}
	nb_threads = 0;
	free(threads);
	threads = NULL;
}
Esempio n. 12
0
void CCamera::init( CameraType cameraType, float X, float Y, float Z, float AspecRatio, float Angle_of_vision ){
    semaphore = SDL_CreateSemaphore( 1 );

    SDL_SemWait( semaphore ); 

    this->cameraType = cameraType; 

    camera_position[0] = X; camera_position[1] = Y; camera_position[2] = Z;
    radius = sqrt( camera_position[0] * camera_position[0] + camera_position[1] * camera_position[1] + camera_position[2] * camera_position[2] );

    x_eye=0.0;  y_eye=0.0;  z_eye=0.0;
    up_vector[0] = 0.0; up_vector[1] = 0.0; up_vector[2] = 1.0;
    axle_vector[0] = 1.0;  axle_vector[1] = 0.0; axle_vector[2] = 0.0;

    const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo( ); 
    float GW = vidInfo->current_w; 
    float GH = vidInfo->current_h; 
    vp_x1 = 0.0; 	vp_x2 = GW;
    vp_y1 = 0.0; 	vp_y2 = GH;

    angle_of_vision = Angle_of_vision;
    this->aspecRatio=AspecRatio;

    redraw = true;

    SDL_SemPost( semaphore ); 

    return;
}
Esempio n. 13
0
void CCamera::init( CameraType cameraType, float X, float Y, float Z, float Width, float Height, float Depth ){ 
    semaphore = SDL_CreateSemaphore( 1 );

    SDL_SemWait( semaphore ); 

    this->cameraType = cameraType; 

    camera_position[0] = X; camera_position[1] = Y; camera_position[2] = Z;

    x_eye=0.0;  y_eye=0.0;  z_eye=0.0;
    up_vector[0] = 0.0; up_vector[1] = 0.0; up_vector[2] = 1.0;
    axle_vector[0] = 1.0;  axle_vector[1] = 0.0; axle_vector[2] = 0.0;

    const SDL_VideoInfo* vidInfo = SDL_GetVideoInfo( ); 
    float GW = vidInfo->current_w; 
    float GH = vidInfo->current_h; 
    vp_x1 = 0.0; 	vp_x2 = GW;
    vp_y1 = 0.0; 	vp_y2 = GH;

    width = Width; 
    height = Height; 
    depth = Depth; 

    redraw = true; 

    SDL_SemPost( semaphore ); 

    return;
}
Esempio n. 14
0
void CCamera::sidewind( int direction, float amount ) {
    SDL_SemWait( semaphore ); 

    switch( direction ) {
    	case UP :
		camera_position[2] += amount;
		z_eye += amount;
		break;

    	case DOWN :
		camera_position[2] -= amount;
		z_eye -= amount;
		break;

    	case LEFT :
		camera_position[0] -= amount;
		x_eye -= amount;
		break;

    	case RIGHT :
		camera_position[0] += amount;
		x_eye += amount;
		break;

    }
	
    redraw = true;
    SDL_SemPost( semaphore ); 

    return;
}
Esempio n. 15
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);
}
void Sprite::UpdateReadiness(string newLocationId, bool *pLoadSprite, bool *pDeleteSprite)
{
    vector<string> parentLocationList = Case::GetInstance()->GetParentLocationListForSpriteSheetId(spriteSheetImageId);
    bool isNeeded = false;

    *pLoadSprite = false;
    *pDeleteSprite = false;

    for (unsigned int i = 0; i < parentLocationList.size(); i++)
    {
        if (parentLocationList[i] == newLocationId ||
            parentLocationList[i] == CommonFilesId ||
            parentLocationList[i] == Case::GetInstance()->GetPartnerManager()->GetCurrentPartnerId())
        {
            isNeeded = true;
        }
    }

    bool isReady = IsReady();

    if (isNeeded && !isReady)
    {
        *pLoadSprite = true;
    }
    else if (!isNeeded && isReady)
    {
        *pDeleteSprite = true;

        SDL_SemWait(pSpriteSheetSemaphore);
        pSpriteSheetImage = NULL;
        SDL_SemPost(pSpriteSheetSemaphore);
    }
}
Esempio n. 17
0
void thread_sdl_shutdown(void)
{
    int i;

    /* Tell all threads jump back to their start routines, unlock and exit
       gracefully - we'll check each one in turn for it's status. Threads
       _could_ terminate via remove_thread or multiple threads could exit
       on each unlock but that is safe. */

    /* Do this before trying to acquire lock */
    threads_exit = true;

    /* Take control */
    SDL_LockMutex(m);

    for (i = 0; i < MAXTHREADS; i++)
    {
        struct thread_entry *thread = &threads[i];
        if (thread->context.t != NULL)
        {
            /* Signal thread on delay or block */
            SDL_Thread *t = thread->context.t;
            SDL_SemPost(thread->context.s);
            SDL_UnlockMutex(m);
            /* Wait for it to finish */
            SDL_WaitThread(t, NULL);
            /* Relock for next thread signal */
            SDL_LockMutex(m);
        }        
    }

    SDL_UnlockMutex(m);
    SDL_DestroyMutex(m);
}
Esempio n. 18
0
void FlcPlayer::audioCallback(void *userData, Uint8 *stream, int len)
{
	AudioData *audio = (AudioData*)userData;

	AudioBuffer *playBuff = audio->playingBuffer;

	while (len > 0)
	{
		if (playBuff->sampleCount > 0)
		{
			int bytesToCopy = std::min(len, playBuff->sampleCount * 2);
			memcpy(stream, playBuff->samples + playBuff->currSamplePos, bytesToCopy);

			playBuff->currSamplePos += bytesToCopy / 2;
			playBuff->sampleCount -= bytesToCopy / 2;
			len -= bytesToCopy;

			assert(playBuff->sampleCount >= 0);
		}

		if (len > 0)
		{
			/* Need to swap buffers */
			playBuff->currSamplePos = 0;
			SDL_SemWait(audio->sharedLock);
			AudioBuffer *tempBuff = playBuff;
			audio->playingBuffer = playBuff = audio->loadingBuffer;
			audio->loadingBuffer = tempBuff;
			SDL_SemPost(audio->sharedLock);

			if (playBuff->sampleCount == 0)
				break;
		}
	}
}
Esempio n. 19
0
/**
 * Kludge a mouse event by taking advantage of unprotected global funcs 
 *
 * \param ev An analog joystick event
 */
void fakemouse_event(SDL_Event ev) {
	int x, y;

	SDL_GetMouseState (&x, &y);

	switch (ev.type) {
			
		case SDL_JOYAXISMOTION:
			SDL_SemWait(sem);
			switch (ev.jaxis.axis) {
				case 0:         
					dx = ev.jaxis.value / 2048;
					break;
				case 1:         
					dy = ev.jaxis.value / 2048;
					break;
			}
			SDL_SemPost(sem);
			break;

		case SDL_JOYBUTTONUP:
			SDL_PrivateMouseButton(SDL_RELEASED, 1, x, y);
			break;

		case SDL_JOYBUTTONDOWN:
			SDL_PrivateMouseButton(SDL_PRESSED, 1, x, y);
			break;
	}
}
Esempio n. 20
0
int add_gen_task(task *t)
{
   int retval = add_to_queue(&pending_gen, t);
   if (retval)
      SDL_SemPost(pending_task_count);
   return retval;
}
Esempio n. 21
0
int AudioQueue_copy (AudioQueue* self, Uint8* buf, int size)
{
	if (size <= 0) return 0;
	if (SDL_SemValue(self->full_node) > 0) {
		if (!self->buf) self->buf = self->cur->buf;
		int cur_size = self->cur->size - (self->buf - self->cur->buf);
		int size_taken = SDL_min(size, cur_size);

		Copy(buf, self->buf, size_taken, Uint8);

		cur_size -= size_taken;
		if (cur_size <= 0) {
			// move to the next node
			SDL_SemPost(self->empty_node);
			if (++self->cur - self->nodes >= self->n) self->cur = self->nodes;
			self->buf = NULL;

			buf  += size_taken;
			size -= size_taken;
			SDL_SemWait(self->full_node); // this never blocks
			return size_taken + AudioQueue_copy(self, buf, size);
		}
		else {
			// didn't use the entire current node
			self->buf += size_taken;
			return size_taken;
		}
	}
	else {
		Zero(buf, size, Uint8);
		return 0;
	}
}
Esempio n. 22
0
void sim_thread_shutdown(void)
{
    int i;

    /* This *has* to be a push operation from a thread not in the pool
       so that they may be dislodged from their blocking calls. */

    /* Tell all threads jump back to their start routines, unlock and exit
       gracefully - we'll check each one in turn for it's status. Threads
       _could_ terminate via remove_thread or multiple threads could exit
       on each unlock but that is safe. */

    /* Do this before trying to acquire lock */
    threads_status = THREADS_EXIT;

    /* Take control */
    SDL_LockMutex(m);

    /* Signal all threads on delay or block */
    for (i = 0; i < MAXTHREADS; i++)
    {
        struct thread_entry *thread = &threads[i];
        if (thread->context.s == NULL)
            continue;
        SDL_SemPost(thread->context.s);
    }

    /* Wait for all threads to finish and cleanup old ones. */
    for (i = 0; i < MAXTHREADS; i++)
    {
        struct thread_entry *thread = &threads[i];
        SDL_Thread *t = thread->context.t;

        if (t != NULL)
        {
            SDL_UnlockMutex(m);
            /* Wait for it to finish */
            SDL_WaitThread(t, NULL);
            /* Relock for next thread signal */
            SDL_LockMutex(m);
            /* Already waited and exiting thread would have waited .told,
             * replacing it with t. */
            thread->context.told = NULL;
        }
        else
        {
            /* Wait on any previous thread in this location-- could be one not quite
             * finished exiting but has just unlocked the mutex. If it's NULL, the
             * call returns immediately.
             *
             * See remove_thread below for more information. */
            SDL_WaitThread(thread->context.told, NULL);
        }
    }

    SDL_UnlockMutex(m);

    /* Signal completion of operation */
    threads_status = THREADS_EXIT_COMMAND_DONE;
}
Esempio n. 23
0
int draw_screen(graphics_state *state){
    SDL_Surface *screen = state->screen;
    if(SDL_MUSTLOCK(screen) && SDL_LockSurface(screen) < 0) 
        return 1;

    /* calculate stencil buffer, so we don't have to raytrace the whole screen */
    memset(state->stencil, 0, state->width*state->height*sizeof(int));
    int i;
    for(i = 0; i < state->object_count; i++){
        add_sphere_to_stencil(state->object_list + i, state);
    }

    /* tell the worker threads to start rendering, then wait for them to finish */
    for(i = 0; i < state->num_workers; i++)
        SDL_SemPost(state->sema_start_render);
    for(i = 0; i < state->num_workers; i++)
        SDL_SemWait(state->sema_finish_render);

    /* swap buffers */
    if(SDL_MUSTLOCK(screen))
        SDL_UnlockSurface(screen);
    SDL_Flip(screen); 
    return 0;

}
Esempio n. 24
0
/**
 * @brief
 */
void RemoveColinearPoints(winding_t *w) {
	int32_t i;
	vec3_t v1, v2;
	int32_t nump;
	vec3_t p[MAX_POINTS_ON_WINDING];

	nump = 0;
	for (i = 0; i < w->num_points; i++) {
		const int32_t j = (i + 1) % w->num_points;
		const int32_t k = (i + w->num_points - 1) % w->num_points;
		VectorSubtract(w->points[j], w->points[i], v1);
		VectorSubtract(w->points[i], w->points[k], v2);
		VectorNormalize(v1);
		VectorNormalize(v2);
		if (DotProduct(v1, v2) < 0.999) {
			VectorCopy(w->points[i], p[nump]);
			nump++;
		}
	}

	if (nump == w->num_points) {
		return;
	}

	if (debug) {
		const int32_t j = w->num_points - nump;
		for (i = 0; i < j; i++) {
			SDL_SemPost(semaphores.removed_points);
		}
	}

	w->num_points = nump;
	memcpy(w->points, p, nump * sizeof(p[0]));
}
Esempio n. 25
0
static void STDMETHODCALLTYPE
VoiceCBOnBufferEnd(THIS_ void *data)
{
    /* Just signal the SDL audio thread and get out of XAudio2's way. */
    SDL_AudioDevice *this = (SDL_AudioDevice *) data;
    SDL_SemPost(this->hidden->semaphore);
}
Esempio n. 26
0
void resolverquery(char *name)
{
    SDL_LockMutex(resolvermutex);
    resolverqueries.add(name);
    SDL_SemPost(resolversem);
    SDL_UnlockMutex(resolvermutex);
};
Esempio n. 27
0
bool CDirect3D::LockTexture(Bit8u * & pixels,Bitu & pitch)
{
#if D3D_THREAD
    Wait(false);

    // Locks take a bit, waiting for the worker thread to do it will most certainly
    // take us waiting in the kernel mode...try to lock the texture directly...
    if(FAILED(LockTexture())) {

	// OK, let the worker thread do it...
	thread_command = D3D_LOCK;
	LeaveCriticalSection(&cs);
	SDL_SemPost(thread_sem);

	if(FAILED(Wait(false))) {
	    LeaveCriticalSection(&cs);
	    LOG_MSG("D3D:No texture to draw to!?");
	    return false;
	}
    }
    LeaveCriticalSection(&cs);
#else
    if(FAILED(LockTexture())) {
	LOG_MSG("D3D:No texture to draw to!?");
	return false;
    }
#endif

    pixels=(Bit8u *)d3dlr.pBits;
    pitch=d3dlr.Pitch;
    return true;
}
Esempio n. 28
0
void Enemy::AI(float x, float y)
{
	//SDL_LockMutex(mutex);
	//Sem Lock
	SDL_SemWait(moveLock);
	//std::cout << "AI Lock" << std::endl;

	m_dirX = 0;
	m_dirY = 0;

	if (m_x < x)
	{
		m_dirX = 1;
	}
	else if (m_x > x)
	{
		m_dirX = -1;
	}

	if (m_y < y)
	{
		m_dirY = 1;
	}
	else if (m_y > y)
	{
		m_dirY = -1;
	}

	isColliding(x,y);

	//SDL_UnlockMutex(mutex);
	SDL_SemPost(moveLock);
	//std::cout << "AI Unlock" << std::endl;
}
Esempio n. 29
0
/* Restart all threads that are waiting on the condition variable */
DECLSPEC int SDLCALL SDL_CondBroadcast(SDL_cond *cond)
{
	if ( ! cond ) {
		SDL_SetError("Passed a NULL condition variable");
		return -1;
	}

	/* If there are waiting threads not already signalled, then
	   signal the condition and wait for the thread to respond.
	*/
	SDL_LockMutex(cond->lock);
	if ( cond->waiting > cond->signals ) {
		int i, num_waiting;

		num_waiting = (cond->waiting - cond->signals);
		cond->signals = cond->waiting;
		for ( i=0; i<num_waiting; ++i ) {
			SDL_SemPost(cond->wait_sem);
		}
		/* Now all released threads are blocked here, waiting for us.
		   Collect them all (and win fabulous prizes!) :-)
		 */
		SDL_UnlockMutex(cond->lock);
		for ( i=0; i<num_waiting; ++i ) {
			SDL_SemWait(cond->wait_done);
		}
	} else {
		SDL_UnlockMutex(cond->lock);
	}

	return 0;
}
Esempio n. 30
0
void CDirect3D::DestroyD3D(void)
{
#if D3D_THREAD
    // Kill child thread
    if(thread != NULL) {
	Wait(false);
	thread_run = false;
	thread_command = D3D_IDLE;
	LeaveCriticalSection(&cs);
	SDL_SemPost(thread_sem);
	SDL_WaitThread(thread, NULL);
	thread = NULL;
    }
#endif

    InvalidateDeviceObjects();

    // Delete D3D device
    SAFE_RELEASE(pD3DDevice9);
    SAFE_RELEASE(pD3D9);

    if(modes) {
	free(modes);
	modes = NULL;
    }
}