本文整理汇总了C++中SDL_mutexP函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_mutexP函数的具体用法?C++ SDL_mutexP怎么用?C++ SDL_mutexP使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_mutexP函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: PlaySoundClip
bool CSound::PlaySoundClip(ESound eClipType)
{
// first, grab the mutex
if (SDL_mutexP(m_pMutex) == -1) return false;
// now check to make sure we can add one more sound
if (m_uiActiveSounds == 32)
{
// error - too many sounds playing!
SDL_mutexV(m_pMutex);
return false;
}
// add it to the arrays
m_eClipType[m_uiActiveSounds] = eClipType;
m_uiClipOffset[m_uiActiveSounds] = 0;
m_uiActiveSounds++;
// that's all!
SDL_mutexV(m_pMutex);
return true;
}
示例2: StopSoundClip
void CSound::StopSoundClip(ESound eClipType)
{
// first, grab the mutex
if (SDL_mutexP(m_pMutex) == -1) return;
// now try to find the sound clip
for (unsigned int ui = 0; ui < m_uiActiveSounds; ui++)
{
if (m_eClipType[ui] == eClipType)
{
// remove this sound from our lists
memmove(m_eClipType + ui, m_eClipType + ui + 1, (m_uiActiveSounds - ui - 1) * sizeof(ESound));
memmove(m_uiClipOffset + ui, m_uiClipOffset + ui + 1, (m_uiActiveSounds - ui - 1) * sizeof(unsigned int));
m_uiActiveSounds--;
break;
}
}
// let go of the mutex
SDL_mutexV(m_pMutex);
return;
}
示例3: mem_read
static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum) //maks
{
int num;
SDL_mutexP(multipleArchiveMutEx);
if(!bInAMultipleFuncion && context == archive)
{
current = context;
if(context->stdioFilePosition != context->filePosition)
{
//Position changed by a multiple file call
//Restore
context->hidden.mem.here = context->hidden.mem.base + context->stdioFilePosition;
context->filePosition = context->stdioFilePosition;
}
}
num = maxnum;
if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop )
{
num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
}
memcpy(ptr, context->hidden.mem.here, num*size);
context->hidden.mem.here += num*size;
if(!bInAMultipleFuncion)
{
context->filePosition += num*size;
context->stdioFilePosition = context->filePosition;
}
SDL_mutexV(multipleArchiveMutEx);
return(num);
}
示例4: SDL_DelThread
static void
SDL_DelThread(SDL_Thread * thread)
{
int i;
if (!thread_lock) {
return;
}
SDL_mutexP(thread_lock);
for (i = 0; i < SDL_numthreads; ++i) {
if (thread == SDL_Threads[i]) {
break;
}
}
if (i < SDL_numthreads) {
if (--SDL_numthreads > 0) {
while (i < SDL_numthreads) {
SDL_Threads[i] = SDL_Threads[i + 1];
++i;
}
} else {
SDL_maxthreads = 0;
SDL_free(SDL_Threads);
SDL_Threads = NULL;
}
#ifdef DEBUG_THREADS
printf("Deleting thread (%d left - %d max)\n",
SDL_numthreads, SDL_maxthreads);
#endif
}
SDL_mutexV(thread_lock);
#if 0 /* There could be memory corruption if another thread is starting */
if (SDL_Threads == NULL) {
SDL_ThreadsQuit();
}
#endif
}
示例5: while
/** Handle key press events
*
* */
void draw_maint_map::key_press(SDL_KeyboardEvent *button)
{
sdl_drawmode::key_press(button);
while (SDL_mutexP(draw_mtx) == -1) {};
if (button->type == SDL_KEYDOWN)
{
switch(button->keysym.sym)
{
case SDLK_LEFT:
y--;
themap->set_hotspot(mapnum, x, y);
break;
case SDLK_RIGHT:
y++;
themap->set_hotspot(mapnum, x, y);
break;
case SDLK_UP:
x++;
themap->set_hotspot(mapnum, x, y);
break;
case SDLK_DOWN:
x--;
themap->set_hotspot(mapnum, x, y);
break;
case SDLK_PAGEUP:
mapnum++;
themap->set_hotspot(mapnum, x, y);
break;
case SDLK_PAGEDOWN:
mapnum--;
themap->set_hotspot(mapnum, x, y);
break;
default:
break;
}
}
SDL_mutexV(draw_mtx);
}
示例6: SDL_mutexP
void CDROM_Interface_Ioctl::dx_CDAudioCallBack(Bitu len) {
len *= 4; // 16 bit, stereo
if (!len) return;
if (!player.isPlaying || player.isPaused) {
player.channel->AddSilence();
return;
}
SDL_mutexP(player.mutex);
while (player.bufLen < (Bits)len) {
bool success;
if (player.targetFrame > player.currFrame)
success = player.cd->ReadSector(&player.buffer[player.bufLen], true, player.currFrame);
else success = false;
if (success) {
player.currFrame++;
player.bufLen += RAW_SECTOR_SIZE;
} else {
memset(&player.buffer[player.bufLen], 0, len - player.bufLen);
player.bufLen = len;
player.isPlaying = false;
}
}
SDL_mutexV(player.mutex);
if (player.ctrlUsed) {
Bit16s sample0,sample1;
Bit16s * samples=(Bit16s *)&player.buffer;
for (Bitu pos=0;pos<len/4;pos++) {
sample0=samples[pos*2+player.ctrlData.out[0]];
sample1=samples[pos*2+player.ctrlData.out[1]];
samples[pos*2+0]=(Bit16s)(sample0*player.ctrlData.vol[0]/255.0);
samples[pos*2+1]=(Bit16s)(sample1*player.ctrlData.vol[1]/255.0);
}
}
player.channel->AddSamples_s16(len/4,(Bit16s *)player.buffer);
memmove(player.buffer, &player.buffer[len], player.bufLen - len);
player.bufLen -= len;
}
示例7: SDL_AddThread
/* Routines for manipulating the thread list */
static void
SDL_AddThread(SDL_Thread * thread)
{
/* WARNING:
If the very first threads are created simultaneously, then
there could be a race condition causing memory corruption.
In practice, this isn't a problem because by definition there
is only one thread running the first time this is called.
*/
if (!thread_lock) {
if (SDL_ThreadsInit() < 0) {
return;
}
}
SDL_mutexP(thread_lock);
/* Expand the list of threads, if necessary */
#ifdef DEBUG_THREADS
printf("Adding thread (%d already - %d max)\n",
SDL_numthreads, SDL_maxthreads);
#endif
if (SDL_numthreads == SDL_maxthreads) {
SDL_Thread **threads;
threads = (SDL_Thread **) SDL_realloc(SDL_Threads,
(SDL_maxthreads +
ARRAY_CHUNKSIZE) *
(sizeof *threads));
if (threads == NULL) {
SDL_OutOfMemory();
goto done;
}
SDL_maxthreads += ARRAY_CHUNKSIZE;
SDL_Threads = threads;
}
SDL_Threads[SDL_numthreads++] = thread;
done:
SDL_mutexV(thread_lock);
}
示例8: SDL_PauseAudio
void SoundSDL::write(u16 * finalWave, int length)
{
if (!_initialized)
return;
if (SDL_GetAudioStatus() != SDL_AUDIO_PLAYING)
SDL_PauseAudio(0);
SDL_mutexP(_mutex);
unsigned int samples = length / 4;
std::size_t avail;
while ((avail = _rbuf.avail() / 2) < samples)
{
_rbuf.write(finalWave, avail * 2);
finalWave += avail * 2;
samples -= avail;
// If emulating and not in speed up mode, synchronize to audio
// by waiting till there is enough room in the buffer
if (emulating && !speedup)
{
SDL_CondWait(_cond, _mutex);
}
else
{
// Drop the remaining of the audio data
SDL_mutexV(_mutex);
return;
}
}
_rbuf.write(finalWave, samples * 2);
SDL_mutexV(_mutex);
}
示例9: set_background
void set_background( image_res_t *img )
{
int i;
SDL_Surface* old = background;
image_res_t *old_img = background_img;
// hide all sprites
for ( i = 0; i < 0x20; i ++ )
set_sprite( i, NULL );
SDL_mutexP(sdl_mutex);
if ( img )
{
SDL_Surface* temp_surf;
temp_surf = SDL_CreateRGBSurfaceFrom( img->data,
img->width, img->height, img->bpp, img->width * (img->bpp / 8),
0, 0, 0, 0);
background = SDL_DisplayFormat( temp_surf );
background_img = img;
SDL_FreeSurface( temp_surf );
}
else
background = NULL;
if ( old )
{
SDL_FreeSurface( old );
free( old_img->data );
free( old_img );
}
SDL_mutexV(sdl_mutex);
SDL_ExposeEvent expose = { SDL_VIDEOEXPOSE };
SDL_PushEvent( &expose );
}
示例10: push_thread_function
int push_thread_function(void* data)
{
while (push_message >= 0 || push_thread_first)
{
if (push_thread_first)
{
pThreadData thread_data = push_thread_first;
int i = 0;
if (push_message != -2)
for (; i < 3; i++)
{
int r = push_game(thread_data->player,thread_data->second_of_player,thread_data->data);
if (r == 0)
break;
if (r == 2)
return 1;
}
if (i == 3)
printf("BIG PANIC at second %i!\n",thread_data->second_of_player);
else
{
if (i != 0)
printf("Little panic... %i\n",i);
printf("Sent second %i!\n",thread_data->second_of_player);
//PULL STACK
SDL_mutexP(push_mutex);
push_thread_first = push_thread_first->next;
if (push_thread_first == NULL)
push_thread_last = NULL;
SDL_mutexV(push_mutex);
free(thread_data);
}
}
else
spSleep(100000);//100ms
}
return 0;
}
示例11: pop_save_return
static int pop_save_return(lua_State *L)
{
save_queue *q = NULL;
SDL_mutexP(main_save->lock_oqueue);
if (main_save->oqueue_head)
{
q = main_save->oqueue_head;
if (q) main_save->oqueue_head = q->next;
if (!main_save->oqueue_head) main_save->oqueue_tail = NULL;
}
SDL_mutexV(main_save->lock_oqueue);
if (q)
{
lua_pushstring(L, q->zfname);
free(q->zfname);
free(q);
}
else
lua_pushnil(L);
return 1;
}
示例12: _LOGDATA
Uint32 ChatState::processFailInternal() {
_LOGDATA("entering processFail with state %s and inflights %d", STATE_WORDS[this->_state].c_str(), this->_inflightRecons);
SDL_mutexP(this->_inflightLock);
if (this->_inflightRecons > 0) {
_LOGDATA("ProcessFail finds inflight already, no new task.");
SDL_mutexV(this->_inflightLock);
return 0;
}
this->_inflightRecons += 1;
SDL_mutexV(this->_inflightLock);
unsigned int mins = chooseRetryMins();
this->_consecFails += 1;
if ((this->_consecFails > RETRY_INTERVALS_LEN) && (this->_xmpp_expire_date < time(NULL))) {
_LOGDATA("expired and at the end of all intervals... not scheduling another delayed connect");
return 0;
}
srand(time(NULL));
unsigned int jitter = rand() % 10000;
_LOGDATA("ProcessFail after consec fail %d, launching timed chat connector with delay %d mins %d seconds of jitter", this->_consecFails, mins, jitter);
return (60000 * mins + jitter);
}
示例13: SDL_mutexP
void Network::skip(int len)
{
SDL_mutexP(mMutex);
mToSkip += len;
if (!mInSize)
{
SDL_mutexV(mMutex);
return;
}
if (mInSize >= mToSkip)
{
mInSize -= mToSkip;
memmove(mInBuffer, mInBuffer + mToSkip, mInSize);
mToSkip = 0;
}
else
{
mToSkip -= mInSize;
mInSize = 0;
}
SDL_mutexV(mMutex);
}
示例14: texasync_clear
/*
* Clear all tasks. There may still remain one currently executing task.
*/
void
texasync_clear(void)
{
SDL_mutexP(storage_mutex);
{
while (finished_tasks != NULL) {
Task *task = finished_tasks;
DL_DELETE(finished_tasks, task);
free_task(task);
/* Update finished task counter. */
assert(num_finished > 0);
num_finished--;
}
while (active_tasks != NULL) {
Task *task = active_tasks;
DL_DELETE(active_tasks, task);
free_task(task);
}
}
SDL_mutexV(storage_mutex);
}
示例15: seek_marker
bool
MPEGstream:: seek_marker(MPEGstream_marker const * marker)
{
SDL_mutexP(mutex);
if ( marker ) {
/* Release current buffer */
if(br->IsLocked())
{
br->Unlock();
marker->marked_buffer->Lock();
}
/* Reset the data positions */
br = marker->marked_buffer;
data = marker->marked_data;
stop = marker->marked_stop;
}
SDL_mutexV(mutex);
return(marker != 0);
}