Ejemplo n.º 1
0
Archivo: block.c Proyecto: hxhlb/GridOS
/**
	@brief 线程自我主动阻塞

	@note
		如果当前线程异常,那么会返回失败,否则永远不会。
*/
bool fss_grab_buffer(void)
{
    bool ret = true;

    /* We are the one to wait the result */
    ke_atomic_inc(&cache_desc()->recaller->desired);

    /* Trigger recaller */
    ke_event_set(cache_desc()->recaller->start_recall);

    /* 等待完成,如果太多人都在等待,并且回收了很多的DBD,那么大家就会疯抢DBD,应该有个优先级控制 */
    //TODO:增加优先级控制,避免疯抢!
    if (ke_event_wait(cache_desc()->recaller->end_recall, KE_SYNC_WAIT_INFINITE) != KE_WAIT_OK)
        ret = false;

    return ret;
}
Ejemplo n.º 2
0
/**
	@brief Thread synchronizing operation
 
	@return kt_sync_wait_result
*/
static int thread_sync_ops(struct sysreq_thread_sync *req)
{
	int i;
	int ops = req->ops;

	switch(ops)
	{
		/* 等待同步对象 */
		case SYSREQ_THREAD_SYNC_WAIT_OBJS:
		{
			int count = req->detail.wait_objs.count;
			struct kt_sync_base *sync_objs[Y_SYNC_MAX_OBJS_COUNT];
			y_handle sync_handles[Y_SYNC_MAX_OBJS_COUNT];
			kt_sync_wait_result ret = KE_WAIT_ERROR;
			
			if (count > Y_SYNC_MAX_OBJS_COUNT)
				goto wait_end;
			
			for (i = 0; i < count; i++)
			{
				sync_handles[i] =(ke_handle)req->detail.wait_objs.sync_objects[i];
				sync_objs[i] = ke_handle_translate(sync_handles[i]);
				if (!sync_objs[i])
					goto unwind_translate;
			}
			ret = kt_wait_objects(kt_current(), count, sync_objs,
							req->detail.wait_objs.wait_all,
							req->detail.wait_objs.timeout, NULL);

unwind_translate:
			for (i = 0; i < count; i++)
			{
				if (sync_objs[i])
					ke_handle_put(sync_handles[i], sync_objs[i]);
			}
wait_end:
			return ret;
		}
		case SYSREQ_THREAD_SYNC_WAIT_MS:
		{
			TODO("");
			break;	
		}

		case SYSREQ_THREAD_SYNC_EVENT:
		{
			ke_handle hevent;
			struct ke_event *event;
			
			switch (req->detail.event.ops)
			{
				case 's':
				{
					/* 唤醒线程,返回唤醒数量 */
					int count;
					
					hevent = req->detail.event.event;
					if (!(event = ke_handle_translate(hevent)))
						goto invalid_handle;
					count = ke_event_set(event);
					ke_handle_put(hevent, event);
					
					return count;
				}
				case 'c':
				{
					/* Create event, return handle */
					if (!(event = ke_event_object_create(req->detail.event.is_manual, req->detail.event.is_set)))
						goto invalid_handle;
					if (KE_INVALID_HANDLE == (hevent = ke_handle_create(event)))
					{
						km_vfree(event);
						goto invalid_handle;
					}
				
					return hevent;
				}
				case 'd':
				{
					/* delete the event, cause everybody wakeup */
#if 0
					hevent = req->detail.event.event;
					if (!(event = ke_handle_translate(hevent)))
						goto invalid_handle;
					ke_handle_and_object_destory(hevent, event);
#else
					TODO("事件对象用户模型还缺少cl_object的封装,无法销毁对象");
#endif
					return 0;
				}
			}
			break;
		}
	}
	
invalid_handle:
	return KE_INVALID_HANDLE;
}
Ejemplo n.º 3
0
/**
 ****************************************************************************************
 * @brief Handles the 1 second tick (call back).
 *****************************************************************************************
 */
static void app_display_sec_tick_cbck(void)
{
    ke_event_set(KE_EVENT_RTC_1S_TICK);
}