当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_CreateSemaphore函数代码示例

本文整理汇总了C++中SDL_CreateSemaphore函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_CreateSemaphore函数的具体用法?C++ SDL_CreateSemaphore怎么用?C++ SDL_CreateSemaphore使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_CreateSemaphore函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: vid_open

t_stat vid_open (DEVICE *dptr, uint32 width, uint32 height)
{
    if (!vid_active) {
        vid_active = TRUE;
        vid_width = width;
        vid_height = height;
        vid_mouse_captured = FALSE;

        vid_key_events.head = 0;
        vid_key_events.tail = 0;
        vid_key_events.count = 0;
        vid_key_events.sem = SDL_CreateSemaphore (1);
        vid_mouse_events.head = 0;
        vid_mouse_events.tail = 0;
        vid_mouse_events.count = 0;
        vid_mouse_events.sem = SDL_CreateSemaphore (1);

        vid_dev = dptr;

        vid_thread_handle = SDL_CreateThread (vid_thread, NULL);
        if (vid_thread_handle == NULL) {
            vid_close ();
            return SCPE_OPENERR;
        }

        sim_debug (SIM_VID_DBG_VIDEO|SIM_VID_DBG_KEY|SIM_VID_DBG_MOUSE, vid_dev, "vid_open() - Success\n");
    }
    return SCPE_OK;
}
开发者ID:charlesUnixPro,项目名称:dps8m,代码行数:29,代码来源:sim_video.c

示例2: fprintf

bool SoundSDL::init(long sampleRate)
{
	SDL_AudioSpec audio;
	audio.freq = sampleRate;
	audio.format = AUDIO_S16SYS;
	audio.channels = 2;
	audio.samples = 1024;
	audio.callback = soundCallback;
	audio.userdata = this;

	if(SDL_OpenAudio(&audio, NULL))
	{
		fprintf(stderr,"Failed to open audio: %s\n", SDL_GetError());
		return false;
	}

	_rbuf.reset(_delay * sampleRate * 2);

	_mutex          = SDL_CreateMutex();
#if !JS
	_semBufferFull  = SDL_CreateSemaphore (0);
	_semBufferEmpty = SDL_CreateSemaphore (1);
#endif
	_initialized    = true;

	return true;
}
开发者ID:akerl,项目名称:demos,代码行数:27,代码来源:SoundSDL.cpp

示例3: init_worker_threads

int init_worker_threads(graphics_state *state){
    state->sema_start_render = SDL_CreateSemaphore(0);
    state->sema_finish_render = SDL_CreateSemaphore(0);
    assert(state->sema_start_render != NULL);
    assert(state->sema_finish_render != NULL);
    state->num_workers = NUM_WORKER_THREADS;
    state->worker_threads = (SDL_Thread**)
        malloc(sizeof(SDL_Thread*)*state->num_workers);
    state->worker_pixel_ranges = (int*)
        malloc(sizeof(int)*4*state->num_workers);
    graphics_worker_arg *worker_args = (graphics_worker_arg*)
        malloc(sizeof(graphics_worker_arg)*state->num_workers);
    
    int i;
    for(i = 0; i < state->num_workers; i++){
        state->worker_pixel_ranges[i*4 + 0] = i*state->width/state->num_workers;
        state->worker_pixel_ranges[i*4 + 1] = 0;
        state->worker_pixel_ranges[i*4 + 2] = (i+1)*state->width/state->num_workers;
        state->worker_pixel_ranges[i*4 + 3] = state->height;
        worker_args[i] = (graphics_worker_arg){i, state};
        state->worker_threads[i] = SDL_CreateThread((int(*)(void*))graphics_worker_thread, worker_args+i);
        if(state->worker_threads[i] == NULL){
            perror("could not create worker thread");
            return -1;
        }
    }

    return 0;
}
开发者ID:dcposch,项目名称:simple_spheres,代码行数:29,代码来源:demo.c

示例4: SDL_OpenAudioDevice

bool SoundSDL::init(long sampleRate)
{
	SDL_AudioSpec audio;
	audio.freq = sampleRate;
	audio.format = AUDIO_S16SYS;
	audio.channels = 2;
	audio.samples = 1024;
	audio.callback = soundCallback;
	audio.userdata = this;

	if (!SDL_WasInit(SDL_INIT_AUDIO)) SDL_Init(SDL_INIT_AUDIO);

	_dev = SDL_OpenAudioDevice(NULL, 0, &audio, NULL, SDL_AUDIO_ALLOW_ANY_CHANGE);
	if(_dev < 0)
	{
		fprintf(stderr,"Failed to open audio: %s\n", SDL_GetError());
		return false;
	}

	_rbuf.reset(_delay * sampleRate * 2);

	if (!_initialized)
	{
		_mutex = SDL_CreateMutex();
		_semBufferFull  = SDL_CreateSemaphore (0);
		_semBufferEmpty = SDL_CreateSemaphore (1);
		_initialized    = true;
	}

	return true;
}
开发者ID:ElementW,项目名称:visualboyadvance-m,代码行数:31,代码来源:SoundSDL.cpp

示例5: InitThreads

void InitThreads (void)
{
if (gameStates.app.bMultiThreaded) {
	int	i;
	for (i = 0; i < 2; i++) {
#if MULTI_THREADED_LIGHTS
		gameData.threads.vertColor.info [i].done = SDL_CreateSemaphore (0);
		gameData.threads.vertColor.info [i].exec = SDL_CreateSemaphore (0);
		gameData.threads.vertColor.info [i].bDone =
		gameData.threads.vertColor.info [i].bExec =
		gameData.threads.vertColor.info [i].bQuit = 0;
		gameData.threads.vertColor.info [i].nId = i;
		gameData.threads.vertColor.info [i].pThread = SDL_CreateThread (VertexColorThread, &gameData.threads.vertColor.info [i].nId);
#endif
#if MULTI_THREADED_SHADOWS
		gameData.threads.clipDist.info [i].done = SDL_CreateSemaphore (0);
		gameData.threads.clipDist.info [i].exec = SDL_CreateSemaphore (0);
		gameData.threads.clipDist.info [i].nId = i;
		gameData.threads.clipDist.info [i].pThread = SDL_CreateThread (ClipDistThread, &gameData.threads.clipDist.info [i].nId);
#endif
		}
	}
gameData.render.vertColor.matAmbient[R] = 
gameData.render.vertColor.matAmbient[G] = 
gameData.render.vertColor.matAmbient[B] = AMBIENT_LIGHT;
gameData.render.vertColor.matAmbient[A] = 1.0f;
gameData.render.vertColor.matDiffuse [R] = 
gameData.render.vertColor.matDiffuse [G] = 
gameData.render.vertColor.matDiffuse [B] = DIFFUSE_LIGHT;
gameData.render.vertColor.matDiffuse [A] = 1.0f;
gameData.render.vertColor.matSpecular[R] = 
gameData.render.vertColor.matSpecular[G] = 
gameData.render.vertColor.matSpecular[B] = 0.0f;
gameData.render.vertColor.matSpecular[A] = 1.0f;
}
开发者ID:paud,项目名称:d2x-xl,代码行数:35,代码来源:descent.cpp

示例6: main

int main(int argc, char** argv){
  if(!argv[1]){
    puts("No IP input found. Please initiate in the form ' ./Player <Server IP> '");
    exit(1);
  }

  //fgets from stdin to get clientname (and pass that into run, ezpz)
  printf("Please enter your name: ");

  fgets(clientname, 64, stdin);
  clientname[strlen(clientname) - 1] = '\0';

  printf("Hello %s!\n", clientname);

  strcat(clientname, " : ");
  namelen = strlen(clientname);
  ///


  SDL_Surface* screen = initScreen(); 

  //Initiate the semaphores and chatserver thread
  msgbuf_sem = SDL_CreateSemaphore(1);
  textSem = SDL_CreateSemaphore(1);
  chatserv = SDL_CreateThread(chatserver, screen);


  //Initiate the server connection
  int socket_id = server_setup(argv[1]);
    
  
  //Initiate the client's sprite
  Uint32 colorkey = SDL_MapRGB( screen->format, 255, 255, 255);
  initiate(socket_id, colorkey); 



  TTF_Init();
  run(screen, socket_id);


  //CEASE AND DESIST

  SDL_KillThread(chatserv);

  SDL_FreeSurface(screen);
  SDL_Quit();
  TTF_Quit();

  int i;
  for(i=0; i<numMessages; i++)
    if(text[i] != NULL)
      SDL_FreeSurface(text[i]);

  SDL_DestroySemaphore(msgbuf_sem);
  SDL_DestroySemaphore(textSem);

  return 1;
}
开发者ID:kyeah,项目名称:VizChat,代码行数:59,代码来源:player_space.c

示例7: Android_CreateWindow

int
Android_CreateWindow(_THIS, SDL_Window * window)
{
    SDL_WindowData *data;
    
    if (Android_Window) {
        return SDL_SetError("Android only supports one window");
    }
    
    Android_PauseSem = SDL_CreateSemaphore(0);
    Android_ResumeSem = SDL_CreateSemaphore(0);

    /* Adjust the window data to match the screen */
    window->x = 0;
    window->y = 0;
    window->w = Android_ScreenWidth;
    window->h = Android_ScreenHeight;

    window->flags &= ~SDL_WINDOW_RESIZABLE;     /* window is NEVER resizeable */
    window->flags |= SDL_WINDOW_FULLSCREEN;     /* window is always fullscreen */
    window->flags &= ~SDL_WINDOW_HIDDEN;
    window->flags |= SDL_WINDOW_SHOWN;          /* only one window on Android */
    window->flags |= SDL_WINDOW_INPUT_FOCUS;    /* always has input focus */

    /* One window, it always has focus */
    SDL_SetMouseFocus(window);
    SDL_SetKeyboardFocus(window);
    
    data = (SDL_WindowData *) SDL_calloc(1, sizeof(*data));
    if (!data) {
        return SDL_OutOfMemory();
    }
    
    data->native_window = Android_JNI_GetNativeWindow();
    
    if (!data->native_window) {
        SDL_free(data);
        return SDL_SetError("Could not fetch native window");
    }

    /* Do not create EGLSurface for Vulkan window since it will then make the window
       incompatible with vkCreateAndroidSurfaceKHR */
    if ((window->flags & SDL_WINDOW_VULKAN) == 0) {
        data->egl_surface = SDL_EGL_CreateSurface(_this, (NativeWindowType) data->native_window);

        if (data->egl_surface == EGL_NO_SURFACE) {
            ANativeWindow_release(data->native_window);
            SDL_free(data);
            return SDL_SetError("Could not create GLES window surface");
        }
    }

    window->driverdata = data;
    Android_Window = window;
    
    return 0;
}
开发者ID:jfiguinha,项目名称:Regards,代码行数:57,代码来源:SDL_androidwindow.c

示例8: malloc

SDL_barrier *SDL_CreateBarrier(int n) {
  struct _SDL_barrier *b = (struct _SDL_barrier*) malloc(
      sizeof(struct _SDL_barrier));
  b->count = 0;
  b->n = n;
  b->mutex = SDL_CreateMutex();
  b->turnstile = SDL_CreateSemaphore(0);
  b->turnstile2 = SDL_CreateSemaphore(0);
  return b;
}
开发者ID:pgoodman,项目名称:ece1747,代码行数:10,代码来源:SDL_barrier.cpp

示例9: rdpCreateThread

void rdpCreateThread()
{
  if (!rdpCommandSema) {
    rdpCommandSema = SDL_CreateSemaphore(0);
    rdpCommandCompleteSema = SDL_CreateSemaphore(0);
  }
  if (!rdpThread) {
    LOG("Creating rdp thread\n");
    rdpThread = SDL_CreateThread(rdpThreadFunc, 0);
  }
}
开发者ID:cxd4,项目名称:z64,代码行数:11,代码来源:maingl.cpp

示例10: rglGlutCreateThread

void rglGlutCreateThread(int recreate)
{
  if (!thread) {
    commandSem = SDL_CreateSemaphore(0);
    commandCond = SDL_CreateCond();
    commandMutex = SDL_CreateMutex();
    commandFinishedSem = SDL_CreateSemaphore(0);
    
    thread = SDL_CreateThread(rglGlutThread, 0);
  } else if (recreate)
    rglGlutPostCommand(rglGlutRecreateWindow);
}
开发者ID:TaylanUB,项目名称:mupen64plus-video-z64,代码行数:12,代码来源:rgl_glut.cpp

示例11: rt_mq_init

rt_err_t rt_mq_init(rt_mq_t mq, const char* name, void *msgpool, rt_size_t msg_size, rt_size_t pool_size, rt_uint8_t flag)
{
	size_t index;
	struct rt_mq_message* head;

	/* parameter check */
	RT_ASSERT(mq != RT_NULL);

	/* set parent flag */
	mq->flag = flag;

	for (index = 0; index < RT_NAME_MAX; index ++)
	{
		mq->name[index] = name[index];
	}

	/* append to mq list */
	SDL_mutexP(_mq_list_mutex);
	rt_list_insert_after(&(_mq_list), &(mq->list));
	SDL_mutexV(_mq_list_mutex);

	/* set message pool */
	mq->msg_pool 	= msgpool;

	/* get correct message size */
	mq->msg_size	= RT_ALIGN(msg_size,  RT_ALIGN_SIZE);
	mq->max_msgs	= pool_size / (mq->msg_size + sizeof(struct rt_mq_message));

	/* init message list */
	mq->msg_queue_head = RT_NULL;
	mq->msg_queue_tail = RT_NULL;

	/* init message empty list */
	mq->msg_queue_free = RT_NULL;

	for (index = 0; index < mq->max_msgs; index ++)
	{
		head = (struct rt_mq_message*)((rt_uint8_t*)mq->msg_pool +
			index * (mq->msg_size + sizeof(struct rt_mq_message)));
		head->next = mq->msg_queue_free;
		mq->msg_queue_free = head;
	}

	/* the initial entry is zero */
	mq->entry		= 0;

	/* init mutex */
	mq->host_mq		= (void*) malloc(sizeof(struct host_mq));
	hmq->mutex		= SDL_CreateSemaphore(1);
	hmq->msg		= SDL_CreateSemaphore(0);

	return RT_EOK;
}
开发者ID:sharpglasses,项目名称:ServerSkeleton,代码行数:53,代码来源:mq.c

示例12: playback_init

static void playback_init(void)
{
    mode = MODE_PLAY;
    if (SDL_Init(SDL_INIT_AUDIO)) {
        fprintf(stderr, "error: Can't initialize SDL: %s\n", SDL_GetError());
        exit(1);
    }
    playback_play_ind = 1;
    playback_play_pos = PLAYBACK_BUFFER_SIZE;
    playback_decode_ind = 0;
    playback_decode_pos = 0;
    playback_play_sema = SDL_CreateSemaphore(0);
    playback_decode_sema = SDL_CreateSemaphore(0);
}
开发者ID:UMadeIt,项目名称:rockbox-cygwin,代码行数:14,代码来源:warble.c

示例13: rdpCreateThread

void rdpCreateThread()
{
    if (!rdpCommandSema) {
        rdpCommandSema = SDL_CreateSemaphore(0);
        rdpCommandCompleteSema = SDL_CreateSemaphore(0);
    }
    if (!rdpThread) {
        LOG("Creating rdp thread\n");
#if SDL_VERSION_ATLEAST(2,0,0)
        rdpThread = SDL_CreateThread(rdpThreadFunc, "z64rdp", 0);
#else
        rdpThread = SDL_CreateThread(rdpThreadFunc, 0);
#endif
    }
}
开发者ID:TaylanUB,项目名称:mupen64plus-video-z64,代码行数:15,代码来源:maingl.cpp

示例14: osal_TurnOnCamera

//main thread only
EXPORT int osal_TurnOnCamera(int cam_id,int w,int h,int fps){
	JNIEnv* env=(JNIEnv*)SDL_AndroidGetJNIEnv();
	TCamera* cam=&g_cameras[cam_id];
	jmethodID method_id;
	jvalue args[4];
	int ret;
	if((unsigned int)cam_id>=(unsigned int)MAX_CAMERAS)return 0;
	if(!cam->m_inited){
		cam->m_clazz=(*env)->FindClass(env,"com/spap/wrapper/camera");
		method_id=(*env)->GetMethodID(env,cam->m_clazz,"<init>","()V");
		cam->m_cam_object=(*env)->NewObjectA(env,cam->m_clazz,method_id,NULL);
		cam->m_cam_mutex=SDL_CreateMutex();
		cam->m_camdat_ready_event=SDL_CreateSemaphore(0);
		cam->m_inited=1;
	}
	if(cam->m_is_on)return 1;
	SDL_LockMutex(cam->m_cam_mutex);
	cam->m_is_on=1;
	method_id=(*env)->GetMethodID(env,cam->m_clazz,"turn_on","(IIII)I");
	//args[].l=cam->m_cam_object;
	args[0].i=cam_id;
	args[1].i=w;
	args[2].i=h;
	args[3].i=fps;
	ret=(*env)->CallIntMethodA(env,cam->m_cam_object,method_id,args);
	SDL_UnlockMutex(cam->m_cam_mutex);
	//__android_log_print(ANDROID_LOG_ERROR,"STDOUT","call method %p %p ret=%d",cam->m_clazz,method_id,ret);
	return ret;
}
开发者ID:KevinStigma,项目名称:jacy,代码行数:30,代码来源:camera_android.c

示例15: CAudioSync

/*
 * Create an CSDLAudioSync for a session.  Don't alloc any buffers until
 * config is called by codec
 */
CSDLAudioSync::CSDLAudioSync (CPlayerSession *psptr, int volume) :
  CAudioSync(psptr)
{
  //SDL_Init(SDL_INIT_AUDIO | SDL_INIT_NOPARACHUTE);
  Our_SDL_AudioInit(getenv("SDL_AUDIODRIVER"));
  m_fill_index = m_play_index = 0;
  for (int ix = 0; ix < DECODE_BUFFERS_MAX; ix++) {
    m_buffer_filled[ix] = 0;
    m_sample_buffer[ix] = NULL;
  }
  m_buffer_size = 0;
  m_config_set = 0;
  m_audio_initialized = 0;
  m_audio_paused = 1;
  m_resync_required = 0;
  m_dont_fill = 0;
  m_consec_no_buffers = 0;
  //SDL_Init(SDL_INIT_AUDIO);
  m_audio_waiting_buffer = 0;
  m_audio_waiting = SDL_CreateSemaphore(0); //NULL; // will be set by decode thread
  m_skipped_buffers = 0;
  m_didnt_fill_buffers = 0;
  m_play_time = 0         ;
  m_buffer_latency = 0;
  m_volume = (volume * SDL_MIX_MAXVOLUME)/100;
  m_first_time = 1;
  m_first_filled = 1;
  m_buffer_offset_on = 0;
  m_buffer_ts = 0;
  m_load_audio_do_next_resync = 0;
}
开发者ID:BluePandaLi,项目名称:mpeg4ip,代码行数:35,代码来源:audio_sdl_old.cpp


注:本文中的SDL_CreateSemaphore函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。