本文整理汇总了C++中SDL_LockMutex函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_LockMutex函数的具体用法?C++ SDL_LockMutex怎么用?C++ SDL_LockMutex使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_LockMutex函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: tick_start
void tick_start(unsigned int interval_in_ms)
{
if (!sim_kernel_init())
{
panicf("Could not initialize kernel!");
exit(-1);
}
if (tick_timer_id != NULL)
{
SDL_RemoveTimer(tick_timer_id);
tick_timer_id = NULL;
}
else
{
start_tick = SDL_GetTicks();
}
tick_timer_id = SDL_AddTimer(interval_in_ms, tick_timer, NULL);
#ifndef HAVE_SDL_THREADS
SDL_LockMutex(wfi_mutex);
#endif
}
示例2: packet_queue_put
int packet_queue_put(PacketQueue *q, AVPacket *pkt) {
AVPacketList *pkt1;
if(av_dup_packet(pkt) < 0)
{
return -1;
}
pkt1 = (AVPacketList*)av_malloc(sizeof(AVPacketList));
if (!pkt1)
return -1;
pkt1->pkt = *pkt;
pkt1->next = NULL;
SDL_LockMutex(q->mutex);
if (!q->last_pkt)
q->first_pkt = pkt1;
else
q->last_pkt->next = pkt1;
q->last_pkt = pkt1;
q->nb_packets++;
q->size += pkt1->pkt.size;
SDL_UnlockMutex(q->mutex);
return 0;
}
示例3: packet_queue_flush
static void packet_queue_flush(PacketQueue *q)
{
AVPacketList *pkt, *pkt1;
SDL_LockMutex(q->mutex);
for(pkt = q->first_pkt; pkt != NULL; pkt = pkt1)
{
pkt1 = pkt->next;
if(pkt1->pkt.data != (uint8_t *)"FLUSH")
{
}
av_free_packet(&pkt->pkt);
av_freep(&pkt);
}
q->last_pkt = NULL;
q->first_pkt = NULL;
q->nb_packets = 0;
q->size = 0;
SDL_UnlockMutex(q->mutex);
}
示例4: resolvercheck
static bool resolvercheck(char **name, ENetAddress *address) {
SDL_LockMutex(resolvermutex);
if (!ResolverResults.empty()) {
ResolverResult &rr = ResolverResults.pop();
*name = rr.query;
*address = rr.address;
SDL_UnlockMutex(resolvermutex);
return true;
}
loopv(ResolverThreads) {
ResolverThread &rt = ResolverThreads[i];
if (rt.query) {
if (game::lastmillis() - rt.starttime > resolverlimit) {
resolverstop(rt, true);
*name = rt.query;
SDL_UnlockMutex(resolvermutex);
return true;
}
}
}
SDL_UnlockMutex(resolvermutex);
return false;
}
示例5: alloc_picture
void alloc_picture(void *userdata) {
VideoState *is = (VideoState *)userdata;
VideoPicture *vp;
vp = &is->pictq[is->pictq_windex];
if(vp->bmp) {
// we already have one make another, bigger/smaller
SDL_FreeYUVOverlay(vp->bmp);
}
// Allocate a place to put our YUV image on that screen
SDL_LockMutex(screen_mutex);
vp->bmp = SDL_CreateYUVOverlay(is->video_ctx->width,
is->video_ctx->height,
SDL_YV12_OVERLAY,
screen);
SDL_UnlockMutex(screen_mutex);
vp->width = is->video_ctx->width;
vp->height = is->video_ctx->height;
vp->allocated = 1;
}
示例6: Lock
void BXBGProcess::Resume()
{
if (!m_bPaused) return;
Lock();
std::map<int, BXBGJob*>::iterator it = m_inProgressMap.begin();
for (;it != m_inProgressMap.end(); it++) {
BXBGJob *pJob = it->second;
if (pJob) {
pJob->Resume();
}
}
Unlock();
// Lock the pause mutex
SDL_LockMutex(m_pPauseLock);
// Update the pause protected variable
m_bPaused = false;
// Signal the condition variable so that the threads would resume working
SDL_CondBroadcast(m_pPauseCond);
// Unlock the mutex back
SDL_UnlockMutex(m_pPauseLock);
}
示例7: SDL_GetTicks
int TimerManager::create(double trigger, bool shouldLoop, int handlerForLua, int luaObject) {
DGTimer timer;
timer.handle = _handles;
timer.hasTriggered = false;
timer.isEnabled = true;
timer.isLoopable = shouldLoop;
timer.lastTime = SDL_GetTicks() / 1000;
timer.type = DGTimerNormal;
timer.trigger = trigger;
timer.luaHandler = handlerForLua;
timer.luaObject = luaObject;
if (SDL_LockMutex(_mutex) == 0) {
_arrayOfTimers.push_back(timer);
SDL_UnlockMutex(_mutex);
}
_handles++;
return timer.handle;
}
示例8: SDL_OpenAudio
int shr::SDLAudio::Open(unsigned freq, unsigned samples, void *buf) {
int res;
udata = buf;
fmt.freq = freq;
fmt.format = AUDIO_S16LSB;
fmt.channels = 2;
fmt.samples = samples;
fmt.callback = cb;
fmt.userdata = this;
res = SDL_OpenAudio(&fmt, NULL);
if(res < 0) {
std::cerr << "SDLAudio::Open failed, "
<< SDL_GetError() << std::endl;
return -1;
}
SDL_LockMutex(mut);
return 0;
}
示例9: packet_queue_put
int packet_queue_put(PacketQueue *q, AVPacket *pkt)
{
AVPacketList *pkt1;
if(av_dup_packet(pkt) < 0)
{
fprintf(stderr, "dup packet filed\n");
return -1;
}
pkt1 = av_malloc(sizeof(AVPacketList));
pkt1->pkt = *pkt;
pkt1->next = NULL;
SDL_LockMutex(q->mutex);
if(!q->last_pkt)
q->first_pkt = pkt1;
else
q->last_pkt->next = pkt1;
q->last_pkt = pkt1;
q->nb_packets++;
q->size += pkt1->pkt.size;
SDL_CondSignal(q->cond);
SDL_UnlockMutex(q->mutex);
return 0;
}
示例10: SDL_ThreadID
static ErrMsg *findErrorForCurrentThread(void)
{
ErrMsg *i;
Uint32 tid;
if (error_msgs != NULL)
{
tid = SDL_ThreadID();
SDL_LockMutex(errorlist_mutex);
for (i = error_msgs; i != NULL; i = i->next)
{
if (i->tid == tid)
{
SDL_UnlockMutex(errorlist_mutex);
return(i);
} /* if */
} /* for */
SDL_UnlockMutex(errorlist_mutex);
} /* if */
return(NULL); /* no error available. */
} /* findErrorForCurrentThread */
示例11: SDL_LockMutex
void HTTPServerAgent::ProcessResponses()
{
std::queue<Response> responseQueue;
// make a copy of the response queue so we can process
// the response at our leisure
SDL_LockMutex(m_responseQueueLock);
responseQueue = m_responseQueue;
while (!m_responseQueue.empty())
m_responseQueue.pop();
SDL_UnlockMutex(m_responseQueueLock);
while (!responseQueue.empty()) {
Response &resp = responseQueue.front();
if (resp.success)
resp.onSuccess(resp.data, resp.userdata);
else
resp.onFail(resp.buffer, resp.userdata);
responseQueue.pop();
}
}
示例12: add_to_queue
int add_to_queue(PacketQueue *queue, AVPacket *pkt)
{
AVPacketList *pkt1;
pkt1 = av_malloc(sizeof(AVPacketList));
if(!pkt1)
return -1;
if(av_dup_packet(pkt))
return -1;
pkt1->pkt = *pkt;
pkt1->next = NULL;
SDL_LockMutex(queue->mutex);
if(!queue->end)
queue->header = pkt1;
else
queue->end->next = pkt1;
queue->end = pkt1;
queue->pktNum++;
queue->size += pkt1->pkt.size;
SDL_CondSignal(queue->cond);
SDL_UnlockMutex(queue->mutex);
return 0;
}
示例13: SDL_CondSignal
/* Restart one of the threads that are waiting on the condition variable */
int
SDL_CondSignal(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) {
++cond->signals;
SDL_SemPost(cond->wait_sem);
SDL_UnlockMutex(cond->lock);
SDL_SemWait(cond->wait_done);
} else {
SDL_UnlockMutex(cond->lock);
}
return 0;
}
示例14: queue_picture
static int queue_picture(FFMovie *movie, AVFrame *src_frame)
{
/*DECODE LOOP*/
AVPicture pict;
SDL_LockMutex(movie->dest_mutex);
/* if the frame movie not skipped, then display it */
if (movie->dest_overlay) {
/* get a pointer on the bitmap */
SDL_LockYUVOverlay(movie->dest_overlay);
pict.data[0] = movie->dest_overlay->pixels[0];
pict.data[1] = movie->dest_overlay->pixels[2];
pict.data[2] = movie->dest_overlay->pixels[1];
pict.linesize[0] = movie->dest_overlay->pitches[0];
pict.linesize[1] = movie->dest_overlay->pitches[2];
pict.linesize[2] = movie->dest_overlay->pitches[1];
/*
first fields of AVFrame match AVPicture, so it appears safe to
cast here (at least of ffmpeg-0.4.8, this is how ffplay does it)
AVPicture is just a container for 4 pixel pointers and 4 strides
*/
img_convert(&pict, PIX_FMT_YUV420P,
(AVPicture *)src_frame, movie->video_st->codec.pix_fmt,
movie->video_st->codec.width, movie->video_st->codec.height);
SDL_UnlockYUVOverlay(movie->dest_overlay);
video_refresh_timer(movie);
}
SDL_UnlockMutex(movie->dest_mutex);
return 0;
}
示例15: get_delay
static float get_delay(struct ao *ao)
{
struct priv *priv = ao->priv;
SDL_LockMutex(priv->buffer_mutex);
int sz = av_fifo_size(priv->buffer);
#ifdef ESTIMATE_DELAY
int64_t callback_time0 = priv->callback_time0;
int64_t callback_time1 = priv->callback_time1;
#endif
SDL_UnlockMutex(priv->buffer_mutex);
// delay component: our FIFO's length
float delay = sz / (float) ao->bps;
#ifdef ESTIMATE_DELAY
// delay component: outstanding audio living in SDL
int64_t current_time = mp_time_us();
// interval between callbacks
int64_t callback_interval = callback_time0 - callback_time1;
int64_t elapsed_interval = current_time - callback_time0;
if (elapsed_interval > callback_interval)
elapsed_interval = callback_interval;
// delay subcomponent: remaining audio from the currently played buffer
int64_t buffer_interval = callback_interval - elapsed_interval;
// delay subcomponent: remaining audio from the next played buffer, as
// provided by the callback
buffer_interval += callback_interval;
delay += buffer_interval / 1000000.0;
#endif
return delay;
}