Exemple #1
0
void
wait_for_thread_state_change(struct thread *thread, lispobj state)
{
    sigset_t old;
    os_sem_t *wait_sem;
    block_blockable_signals(&old);
  start:
    os_sem_wait(thread->state_sem, "wait_for_thread_state_change");
    if (thread->state == state) {
        switch (state) {
        case STATE_RUNNING:
            wait_sem = thread->state_not_running_sem;
            thread->state_not_running_waitcount++;
            break;
        case STATE_STOPPED:
            wait_sem = thread->state_not_stopped_sem;
            thread->state_not_stopped_waitcount++;
            break;
        default:
            lose("Invalid state in wait_for_thread_state_change: "OBJ_FMTX"\n", state);
        }
    } else {
        wait_sem = NULL;
    }
    os_sem_post(thread->state_sem, "wait_for_thread_state_change");
    if (wait_sem) {
        os_sem_wait(wait_sem, "wait_for_thread_state_change");
        goto start;
    }
    thread_sigmask(SIG_SETMASK, &old, NULL);
}
Exemple #2
0
unsigned int ZION_CALLBACK log_thread(void* arg)
{
	LOG_CTX* ctx = (LOG_CTX*)arg;
	unsigned int msglen = ctx->stream.len;
	char buf[1000];
	int level = 0;

	for(;;) {
		os_sem_wait(&ctx->stream.inque);

		os_mutex_lock(&ctx->stream.mtx);
		if(ctx->stream.inque_size==0) { os_mutex_unlock(&ctx->stream.mtx); break; }

		stream_read(ctx, (char*)&msglen, (unsigned int)sizeof(msglen));
		stream_read(ctx, buf, msglen);
		buf[msglen] = '\0';

		if(ctx->stream.ouque_size>0) {
			ctx->stream.ouque_size--;
			os_sem_post(&ctx->stream.ouque);
		}

		ctx->stream.inque_size--;
		os_mutex_unlock(&ctx->stream.mtx);

		map[ctx->type].func_write(ctx, level, buf, msglen);
	}
	return 0;
}
Exemple #3
0
/***usart1.2发送数据   将测量结果提供给主板***/
__task void send_result(void)
{
	u8 j=0;
	u8 send_i=0;
	os_sem_init(resultsem,0);
	
	while(1)
	{
		os_sem_wait(resultsem,0xffff);
		if(send_config==1)
		{
			for(j=view_detial[send_i][0]+1;j<view_detial[send_i][0]+4;j++)
			{
				itoa(view_detial[send_i][j],view_send,10);
				usart_send_str(USART1,view_send);
				usart_send_str(USART1," ");
			}
		}
/***      ***/
		else
		{
			itoa(refresh.yy,view_send,10);
			usart_send_str(USART1,view_send);
			usart_send_str(USART1," ");
			itoa(refresh.wj,view_send,10);
			usart_send_str(USART1,view_send);
			usart_send_str(USART1," ");
			itoa(refresh.yj,view_send,10);
			usart_send_str(USART1,view_send);
			usart_send_str(USART1," ");
			itoa(refresh.jb,view_send,10);
			usart_send_str(USART1,view_send);
			usart_send_str(USART1," ");
		}
/*******/
		
// 		usart_send_str(USART1," ");
// 		itoa(t1,view_send,10);
// 		usart_send_str(USART1,view_send);
		
// 		usart_send_str(USART1," ");
// 		itoa(t2,view_send,10);
// 		usart_send_str(USART1,view_send);
		
/***调试  计数***/
		memset(view_detial[send_i],0,106);	
		send_i++;
		if(send_i==5)
			send_i=0;
		i++;
		itoa(i,view_send,10);
		usart_send_str(USART1," ");
		usart_send_str(USART1,view_send);
/***  ***/

		memset(view_send,0,10);
		usart_send_enter(USART1);
		
	}
}
Exemple #4
0
static void *send_thread(void *data)
{
	struct rtmp_stream *stream = data;
	bool disconnected = false;

	while (os_sem_wait(stream->send_sem) == 0) {
		struct encoder_packet packet;

		if (os_event_try(stream->stop_event) != EAGAIN)
			break;
		if (!get_next_packet(stream, &packet))
			continue;
		if (send_packet(stream, &packet, false) < 0) {
			disconnected = true;
			break;
		}
	}

	if (!disconnected && !send_remaining_packets(stream))
		disconnected = true;

	if (disconnected) {
		blog(LOG_INFO, "Disconnected from %s", stream->path.array);
		free_packets(stream);
	}

	if (os_event_try(stream->stop_event) == EAGAIN) {
		pthread_detach(stream->send_thread);
		obs_output_signal_stop(stream->output, OBS_OUTPUT_DISCONNECTED);
	}

	stream->active = false;
	return NULL;
}
Exemple #5
0
void
set_thread_state(struct thread *thread, lispobj state)
{
    int i, waitcount = 0;
    sigset_t old;
    block_blockable_signals(&old);
    os_sem_wait(thread->state_sem, "set_thread_state");
    if (thread->state != state) {
        if ((STATE_STOPPED==state) ||
            (STATE_DEAD==state)) {
            waitcount = thread->state_not_running_waitcount;
            thread->state_not_running_waitcount = 0;
            for (i=0; i<waitcount; i++)
                os_sem_post(thread->state_not_running_sem, "set_thread_state (not running)");
        }
        if ((STATE_RUNNING==state) ||
            (STATE_DEAD==state)) {
            waitcount = thread->state_not_stopped_waitcount;
            thread->state_not_stopped_waitcount = 0;
            for (i=0; i<waitcount; i++)
                os_sem_post(thread->state_not_stopped_sem, "set_thread_state (not stopped)");
        }
        thread->state = state;
    }
    os_sem_post(thread->state_sem, "set_thread_state");
    thread_sigmask(SIG_SETMASK, &old, NULL);
}
static void *video_thread(void *param)
{
	struct video_output *video = param;

	os_set_thread_name("video-io: video thread");

	const char *video_thread_name =
		profile_store_name(obs_get_profiler_name_store(),
				"video_thread(%s)", video->info.name);

	while (os_sem_wait(video->update_semaphore) == 0) {
		if (video->stop)
			break;

		profile_start(video_thread_name);
		while (!video->stop && !video_output_cur_frame(video)) {
			video->total_frames++;
		}

		video->total_frames++;
		profile_end(video_thread_name);

		profile_reenable_thread();
	}

	return NULL;
}
Exemple #7
0
int log_puts(LOG_HANDLE ctx, int level, const char* msg, unsigned int msglen)
{
	if(msglen==0) msglen = (unsigned int)strlen(msg);
	if(ctx->stream.buf==NULL) return map[ctx->type].func_write(ctx, level, msg, msglen);

	for(;;) {
		os_mutex_lock(&ctx->stream.mtx);
		if(ctx->stream.len+sizeof(msglen)+msglen <= ctx->stream.max) break;
		ctx->stream.ouque_size++;
		os_mutex_unlock(&ctx->stream.mtx);
		os_sem_wait(&ctx->stream.ouque);
	}

	stream_write(ctx, (char*)&msglen, (unsigned int)sizeof(msglen));
	stream_write(ctx, msg, msglen);
	ctx->stream.inque_size++;

	if(ctx->stream.ouque_size>0) {
		ctx->stream.ouque_size--;
		os_sem_post(&ctx->stream.ouque);
	}

	os_sem_post(&ctx->stream.inque);
	os_mutex_unlock(&ctx->stream.mtx);

	get_level_string(level);

	return ERR_NOERROR;
}
Exemple #8
0
static void *send_thread(void *data)
{
	struct rtmp_stream *stream = data;

	os_set_thread_name("rtmp-stream: send_thread");

	while (os_sem_wait(stream->send_sem) == 0) {
		struct encoder_packet packet;

		if (stopping(stream) && stream->stop_ts == 0) {
			break;
		}

		if (!get_next_packet(stream, &packet))
			continue;

		if (stopping(stream)) {
			if (can_shutdown_stream(stream, &packet)) {
				obs_free_encoder_packet(&packet);
				break;
			}
		}

		if (!stream->sent_headers) {
			if (!send_headers(stream)) {
				os_atomic_set_bool(&stream->disconnected, true);
				break;
			}
		}

		if (send_packet(stream, &packet, false, packet.track_idx) < 0) {
			os_atomic_set_bool(&stream->disconnected, true);
			break;
		}
	}

	if (disconnected(stream)) {
		info("Disconnected from %s", stream->path.array);
	} else {
		info("User stopped the stream");
	}

	RTMP_Close(&stream->rtmp);

	if (!stopping(stream)) {
		pthread_detach(stream->send_thread);
		obs_output_signal_stop(stream->output, OBS_OUTPUT_DISCONNECTED);
	} else {
		obs_output_end_data_capture(stream->output);
	}

	free_packets(stream);
	os_event_reset(stream->stop_event);
	os_atomic_set_bool(&stream->active, false);
	stream->sent_headers = false;
	return NULL;
}
Exemple #9
0
/***假币报警***/
__task void single_jb(void)
{
	os_sem_init(jbsem,0);
	
	while(1)
	{
		os_sem_wait(jbsem,0xffff);
		give_single_state(0);
		os_dly_wait(30);
		give_single_state(1);
	}
}
Exemple #10
0
/* Only access thread state with blockables blocked. */
lispobj
thread_state(struct thread *thread)
{
    lispobj state;
    sigset_t old;
    block_blockable_signals(&old);
    os_sem_wait(thread->state_sem, "thread_state");
    state = thread->state;
    os_sem_post(thread->state_sem, "thread_state");
    thread_sigmask(SIG_SETMASK, &old, NULL);
    return state;
}
Exemple #11
0
__task void stop_block(void *void_ptr) {	
	while(1) {
		os_sem_wait(&next_block, 0xffff);
		
		watchdog_timer = os_time_get();
		
		x_offsets[count] = current_block.x_offset;
		if(count != 0){
			diff = x_offsets[count] - x_offsets[count - 1];
			// If the block completely missed the stack, game over
			if (abs(diff) >= current_block.width - 1 ){
				GLCD_DisplayString(1, 1, 1, "  GAME OVER ");

				os_sem_wait(&next_block, 0xffff);
				reset();
				continue;
			}
			// If the block extends to the right of the stack
			else if(diff < 0){
				destroy_left();
				
				x_offsets[count] -= diff;
				current_block.width += diff;
			}
			// If the block extends to the left of the stack
			else if (diff > 0){
				destroy_right();
				
				current_block.width -= diff;
			}
			// If the block is perfectly stacked, do nothing
		}
		current_block.y_offset -= HEIGHT;
		current_block.x_offset = INITIAL_X;
		current_block.color++;
		widths[count] = current_block.width;
		
		count++;
	}
}	
Exemple #12
0
static void wq_wait(wq_t *wq)
{
    int wait = 0;

    os_thread_mutex_lock(&wq->lock);
    if (wq->ev != 0)
        wq->ev = 0;
    else
        wait = 1;
    wq->wait = wait;

    os_thread_mutex_unlock(&wq->lock);

    if (wait == 1)
        os_sem_wait(&wq->sem);
}
Exemple #13
0
void semihost_disable(void) {
    // Called from:
    //   - main task when the the interface receives the POWERDOWN semihost call
    //   - cmsis-dap when a debugger opens the swd port
    //   - drag n drop when a binary will be flashed

    if (!semihostEnabled) return;
    if (semihostTask==0) return;

    os_evt_set(FLAGS_SH_STOP, semihostTask);

    // Wait for semihost task to stop
    os_sem_wait(semihostStoppedSem, NO_TIMEOUT);
    semihostEnabled = 0;
    return;
}
Exemple #14
0
int __exa_disk_zone_lock(device_t *dev, long first_sector, long size_in_sector,
                         bool lock)
{
  header_t *header = nbd_list_remove(&dev->disk_queue.root->free, NULL, LISTWAIT);
  EXA_ASSERT(header != NULL);

  header->type = NBD_HEADER_LOCK;
  header->lock.sector = first_sector;
  header->lock.sector_nb = size_in_sector;

  header->lock.op = lock ? NBD_REQ_TYPE_LOCK : NBD_REQ_TYPE_UNLOCK;

  nbd_list_post(&dev->disk_queue, header, -1);

  os_sem_wait(&dev->lock_sem_disk);

  return dev->locking_return;
}
Exemple #15
0
__task void set_difficulty(void *void_ptr){
	uint32_t ad_avg = 0;
  uint16_t ad_val = 0, ad_val_ = 0xFFFF;
	
	while (1) {                                /* Loop forever                  */
		os_sem_wait(&change_difficulty, 0xffff);
		
		ad_avg += AD_last << 8;                /* Add AD value to averaging     */
		ad_avg ++;
		if ((ad_avg & 0xFF) == 0x10) {         /* average over 16 values        */
			ad_val = (ad_avg >> 8) >> 4;         /* average devided by 16         */
			ad_avg = 0;
		}

    if (ad_val ^ ad_val_) {                  /* AD value changed              */
      ad_val_ = ad_val;
		}
    difficulty = ad_val;
	}
Exemple #16
0
/***上传测量数据任务   100ms上传一次***/
__task void upload_refresh_data(void)
{
	u16 data[4];
	
	os_sem_init(rfsem,0);
	memset(data,0,8);
	
	while(1)
	{
		os_sem_wait(rfsem,0xffff);
		
		data[0]=refresh.yy;
		data[1]=refresh.wj;
		data[2]=refresh.yj;
		data[3]=refresh.jb;
		usart_send_data(USART2,(u8 *)data,4);
		
		os_dly_wait(1000);	
		os_sem_init(rfsem,0);
	}
}
Exemple #17
0
 void RxThread()
 {
     while (1)
     {
         os_sem_wait(&rxSem);
         portENTER_CRITICAL();
         // we read the packet received to our assembly buffer
         bool result = readEP_NB(rxData, &rxSize);
         portEXIT_CRITICAL();
         if (!result)
         {
             diewith(0x80000CCC);
         }
         for (uint32_t i = 0; i < rxSize; i++)
         {
           /// @todo (balazs.racz) this needs to be replaced with something
           /// that works in the new select based model.
           //os_mq_send(rxQ, rxData + i);
         }
         rxSize = 0;
         // We reactivate the endpoint to receive next characters
         // readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK);
     }
 }
Exemple #18
0
static inline bool mp_media_thread(mp_media_t *m)
{
	os_set_thread_name("mp_media_thread");

	if (!init_avformat(m)) {
		return false;
	}
	if (!mp_media_reset(m)) {
		return false;
	}

	for (;;) {
		bool reset, kill, is_active;
		bool timeout = false;

		pthread_mutex_lock(&m->mutex);
		is_active = m->active;
		pthread_mutex_unlock(&m->mutex);

		if (!is_active) {
			if (os_sem_wait(m->sem) < 0)
				return false;
		} else {
			timeout = mp_media_sleepto(m);
		}

		pthread_mutex_lock(&m->mutex);

		reset = m->reset;
		kill = m->kill;
		m->reset = false;
		m->kill = false;

		pthread_mutex_unlock(&m->mutex);

		if (kill) {
			break;
		}
		if (reset) {
			mp_media_reset(m);
			continue;
		}

		/* frames are ready */
		if (is_active && !timeout) {
			if (m->has_video)
				mp_media_next_video(m, false);
			if (m->has_audio)
				mp_media_next_audio(m);

			if (!mp_media_prepare_frames(m))
				return false;
			if (mp_media_eof(m))
				continue;

			mp_media_calc_next_ns(m);
		}
	}

	return true;
}
Exemple #19
0
os_result
os_procCreate(
    const char *executable_file,
    const char *name,
    const char *arguments,
    os_procAttr *procAttr,
    os_procId *procId)
{
    int procTaskId;
    int sched_policy;
    os_result rv = os_resultSuccess;
    os_procContextData process_procContextData;
    os_int32 startRoutine = 0;
    os_int32 pOptions,privateSet;
    os_int32 len,i=0,n=0;
    char *converted = NULL;

    assert(executable_file != NULL);
    assert(name != NULL);
    assert(arguments != NULL);
    assert(procAttr != NULL);
    assert(procId != NULL);

    len = strlen(arguments);
    converted = (char*)os_malloc(len+1);
    for (; i < len ; i++)
    {
       if (arguments[i] != '\"')
       {
          converted[n] = arguments[i];
          n++;
       }
    }
    converted[n] = '\0';
    pOptions = 0;
    privateSet = 0;
    taskOptionsGet(taskIdSelf(),&pOptions);
    if ((pOptions & VX_PRIVATE_ENV) == 0)
    {
        envPrivateCreate(taskIdSelf(), 0);
        privateSet = 1;
    }
    putenv("SPLICE_NEW_PROCESS=no");

    if (procAttr->schedClass == OS_SCHED_REALTIME) {
        sched_policy = SCHED_FIFO;
    } else if (procAttr->schedClass == OS_SCHED_TIMESHARE) {
        return os_resultInvalid;
    } else if (procAttr->schedClass == OS_SCHED_DEFAULT) {
        sched_policy = SCHED_OTHER;
    } else {
        return os_resultInvalid;
    }

    if ((procAttr->schedPriority > VXWORKS_PRIORITY_MIN) ||
        (procAttr->schedPriority < VXWORKS_PRIORITY_MAX) ) {
        return os_resultInvalid;
    }


    {
      os_library binlib;
      os_libraryAttr attr;

      os_libraryAttrInit(&attr);
      /* Dynamic load of services is a special case, so try just static via
         os_libraryOpen */
      attr.staticLibOnly=1;
      binlib = os_libraryOpen( executable_file, &attr);
      /* FIXME existing use of os_int32 for pointer is CRAZY!! */
      if ( binlib != NULL )
      {
         startRoutine = (os_int32)os_libraryGetSymbol( binlib, executable_file );
      }

      if ( startRoutine == 0 && os_dynamicLibPlugin != NULL )
      {
         startRoutine = (os_uint32)os_dynamicLibPlugin->dlp_loadLib( executable_file );
      }

      if ( startRoutine == 0 )
      {
         OS_REPORT(OS_ERROR, "os_procCreate", 1,
                       "Unable to load %s (%s)",
                       executable_file, name);
     rv = os_resultInvalid;
      }
    }

    if (rv == os_resultSuccess)
    {
        process_procContextData = (os_procContextData )os_malloc((size_t)OS_SIZEOF(os_procContextData));
        if (process_procContextData == (os_procContextData) NULL) {
            OS_REPORT(OS_WARNING, "os_procCreate", 1,
                        "malloc failed with error %d (%s, %s)",
                        os_getErrno(), executable_file, name);
            rv = os_resultInvalid;
        }
        else
        {
#if defined ( _WRS_VXWORKS_MAJOR ) && ( _WRS_VXWORKS_MAJOR > 6 ) || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR > 8 )
        /* the blockParent semaphore is used to prevent this task exiting before the spawned task
           has completed copying its environ. */
        os_sem_t blockParent;
        os_sem_init( &blockParent, 0);
#endif
            os_procInit(process_procContextData, name, executable_file, converted);
            process_procContextData->procAttrPrio = procAttr->schedPriority;
            procTaskId = taskSpawn((char *)name, procAttr->schedPriority,
                                   VX_FP_TASK
#if ! defined ( _WRS_VXWORKS_MAJOR ) || _WRS_VXWORKS_MAJOR < 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9 )
/* VX_PRIVATE_ENV flag is no longer functional in vxworks 6.9 */
                   | VX_PRIVATE_ENV
#endif
#if defined ( VXWORKS_55 ) || defined ( VXWORKS_54 )
                                   | VX_STDIO | VX_DEALLOC_STACK
#endif
                                   ,
                                   VXWORKS_PROC_DEFAULT_STACK,
                                   (FUNCPTR)os_procWrapper,
                                   (int)process_procContextData, (int)process_procContextData->executable,
                                   (int)startRoutine, (int)process_procContextData->arguments, taskIdSelf(),
#if ! defined ( _WRS_VXWORKS_MAJOR ) || _WRS_VXWORKS_MAJOR < 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR < 9 )
                                   0,
#else
                                   &blockParent,
#endif
 0, 0, 0, 0);
#if defined ( _WRS_VXWORKS_MAJOR ) && ( _WRS_VXWORKS_MAJOR > 6 || ( _WRS_VXWORKS_MAJOR == 6 && _WRS_VXWORKS_MINOR > 8 ) )
            os_sem_wait(&blockParent);
            os_sem_destroy(&blockParent);
#endif
            if (procTaskId == ERROR)
            {
                os_free(process_procContextData);
                rv = os_resultInvalid;
            }
            else
            {
                *procId = *(os_procId *)&process_procContextData;
                rv = os_resultSuccess;
            }
        }
    }

    putenv("SPLICE_NEW_PROCESS=empty");
    if ( privateSet == 1)
    {
        envPrivateDestroy(taskIdSelf());
    }
    os_free(converted);
    return rv;
}
Exemple #20
0
/***读取IO状态  对IO特定状态计时 测量硬币直径***/
__task void io_keep_time(void)
{
	u8 bf=0,n=0;
	os_sem_init(iosem,0);

	while(1)
	{
 		os_sem_wait(iosem,0xffff);
/***光钎传感器  测直径***/
		while(1)
		{
			if(get_diasensor_state()==0)
			{
				TIM_Cmd(TIM2,ENABLE);
				TIM_Cmd(TIM4,DISABLE);
				value_count=0;
				break;
			}
			iotask_overtime();
			os_dly_wait(1);
		}
		while(1)
		{
			if(get_diasensor_state()==1)
			{
				TIM_Cmd(TIM2,DISABLE);
				n=view_detial[view_j][0];
				view_detial[view_j][n+2]=count;		//view_detial数据位后面第三位是光钎传感器测得的时间
				t2=count;
				count=0;
				break;
			}
			os_dly_wait(1);
		}
	/***  ***/		
			if(coin_kind[bf]!=0)
			{
				if(coin_kind[bf]==1&&deal_time(t2)==1)
					coin_kind[bf]=1;			//比较通过时间长度 得出币种
				else if(coin_kind[bf]==2&&deal_time(t2)>1)
				{
					coin_kind[bf]=deal_time(t2);
				}
				else
					coin_kind[bf]=0;
			}
			b_kind=coin_kind[bf];
			bf++;
			if(bf==5)
				bf=0;
			view_detial[view_j][n+3]=b_kind;
			view_j++;
			if(view_j==5)
				view_j=0;
			deal_coin(b_kind);
// 			b_kind=0;
			if(b_kind==0)
				os_sem_send(jbsem);
	// 		no_i=0;
	// 		os_sem_send(rfsem);		
			os_sem_send(resultsem);
	}
}
Exemple #21
0
void GUI_X_Lock(void)      { os_sem_wait(GUI_Semaphore, 0xFFFF); }