示例#1
0
void vfs_mngr_fs_remount(void)
{
    sync_lock();

    // Only start a remount if in the connected state and not in a transition
    if (!changing_state() && (VFS_MNGR_STATE_CONNECTED == vfs_state)) {
        vfs_state_next = VFS_MNGR_STATE_RECONNECTING;
    }

    sync_unlock();
}
示例#2
0
// Rebuild the virtual filesystem.  This must only be called
// when mass storage is inactive.
void vfs_user_enable(bool enable)
{
    sync_lock();
    if (enable) {
        if (VFS_USER_STATE_DISCONNECTED == vfs_state_next) {
            vfs_state_remaining_ms = connect_delay_ms;
            vfs_state_next = VFS_USER_STATE_CONNECTED;
        }
    } else {
        vfs_state_remaining_ms = disconnect_delay_ms;
        vfs_state_next = VFS_USER_STATE_DISCONNECTED;
    }
    sync_unlock();
}
示例#3
0
void vfs_mngr_fs_enable(bool enable)
{
    sync_lock();

    if (enable) {
        if (VFS_MNGR_STATE_DISCONNECTED == vfs_state_next) {
            vfs_state_next = VFS_MNGR_STATE_CONNECTED;
        }
    } else {
        vfs_state_next = VFS_MNGR_STATE_DISCONNECTED;
    }

    sync_unlock();
}
示例#4
0
文件: vector.c 项目: ifzz/libcdf
void * vector_get(vector_t *vector,int index)
{
	uint32_t get_pos     = index;
	uint8_t *vector_head = vector->vector_head;
	uint32_t step        = vector->step;
	void * ret           = NULL;
	
	dbg_str(DBG_CONTAINER_DETAIL,"get_pos=%d",get_pos);

	sync_lock(&vector->vector_lock,NULL);
	ret = (vector_head + get_pos * step);
	sync_unlock(&vector->vector_lock);

	return ret;
}
示例#5
0
文件: vector.c 项目: ifzz/libcdf
int vector_pop_back(vector_t *vector)
{
	uint32_t pop_pos  = vector->end.vector_pos;
	
	dbg_str(DBG_CONTAINER_DETAIL,"pop back");

	sync_lock(&vector->vector_lock,NULL);
	if(!vector_pos_equal(&vector->begin,&vector->end)){
		vector_pos_init(&vector->end,--pop_pos,vector);
	} else{
		dbg_str(DBG_CONTAINER_WARNNING,"vector is NULL");
	}
	sync_unlock(&vector->vector_lock);

	return 0;
}
示例#6
0
/* Called at shutdown to tidy the lockspace */
void destroy_lvhash()
{
	struct dm_hash_node *v;
	struct lv_info *lvi;
	char *resource;
	int status;

	pthread_mutex_lock(&lv_hash_lock);

	dm_hash_iterate(v, lv_hash) {
		lvi = dm_hash_get_data(lv_hash, v);
		resource = dm_hash_get_key(lv_hash, v);

		if ((status = sync_unlock(resource, lvi->lock_id)))
			DEBUGLOG("unlock_all. unlock failed(%d): %s\n",
				 status,  strerror(errno));
		free(lvi);
	}
示例#7
0
文件: vector.c 项目: ifzz/libcdf
int vector_set(vector_t *vector,int index,void *data)
{
	uint32_t set_pos  = index;
	uint32_t end_pos  = vector->end.vector_pos;
	void *vector_head = vector->vector_head;
	uint32_t step     = vector->step;
	int ret  = 0;
	
	dbg_str(DBG_CONTAINER_DETAIL,"set_pos=%d",set_pos);

	sync_lock(&vector->vector_lock,NULL);
	memcpy(vector_head + set_pos * step,data,step);
	if(set_pos > end_pos){
		vector_pos_init(&vector->end,set_pos,vector);
	}
	sync_unlock(&vector->vector_lock);

	return ret;
}
示例#8
0
文件: vector.c 项目: ifzz/libcdf
int vector_insert(vector_t *vector, vector_pos_t *it, void *data)
{

	uint32_t insert_pos = it->vector_pos;
	uint32_t end_pos    = vector->end.vector_pos;
	uint32_t count      = end_pos - insert_pos;
	void *vector_head   = vector->vector_head;
	uint32_t step       = vector->step;
	vector_pos_t to;
	
	vector_pos_init(&to,insert_pos + 1,vector);
	dbg_str(DBG_CONTAINER_DETAIL,"insert_pos=%d,to_pos=%d",insert_pos,to.vector_pos);

	sync_lock(&vector->vector_lock,NULL);
	vector_copy(vector,&to,it,count);
	memcpy(vector_head + insert_pos * step,data,step);
	vector_pos_init(&vector->end,end_pos + 1,vector);
	sync_unlock(&vector->vector_lock);

	return 0;
}
示例#9
0
文件: vector.c 项目: ifzz/libcdf
int vector_delete(vector_t *vector, vector_pos_t *it)
{
	uint32_t delete_pos  = it->vector_pos;
	uint32_t end_pos = vector->end.vector_pos;
	uint32_t count = end_pos - delete_pos;
	vector_pos_t from;

	vector_pos_init(&from,delete_pos + 1,vector);

	sync_lock(&vector->vector_lock,0);
	if(vector_pos_equal(it,&vector->end)){
		dbg_str(DBG_CONTAINER_WARNNING,"can't del end pos");
	}else if(vector_pos_equal(it,&vector->begin)&&vector_pos_equal(&from,&vector->end)){
		dbg_str(DBG_CONTAINER_WARNNING,"vector is NULL");
	}else{
		vector_copy(vector,it,&from,count);
		vector_pos_init(&vector->end,end_pos - 1,vector);
	}
	sync_unlock(&vector->vector_lock);

	return 0;
}
示例#10
0
void mempool_attach_list(struct list_head *new_head,struct list_head *hl_head)
{
	cds_mempool_head_list_t *head_list;

	head_list = container_of(hl_head,cds_mempool_head_list_t,list_head);

	sync_lock(&head_list->head_lock,NULL);
	/*
	 *pthread_rwlock_wrlock(&head_list->head_lock);
	 */
	list_add(new_head,hl_head);
	head_list->count++;
	sync_unlock(&head_list->head_lock);
	/*
	 *pthread_rwlock_unlock(&head_list->head_lock);
	 */

	/*
	 *dbg_str(DBG_ALLOC_DETAIL,"add head:%p hl_head:%p",new_head,hl_head);
	 *dbg_str(DBG_ALLOC_DETAIL,"new heads next:%p, prev:%p",new_head->next,new_head->prev);
	 *dbg_str(DBG_ALLOC_DETAIL,"add mempool list,list count =%d",head_list->count);
	 */
}
示例#11
0
文件: debug_log.c 项目: ifzz/libcdf
int log_print_print_str_vl(debugger_t *debugger,size_t level,const char *fmt,va_list vl)
{
#define MAX_LOG_PRINT_BUFFER_LEN 1024*4
	char buffer_str[MAX_LOG_PRINT_BUFFER_LEN];
	size_t ret = 0,offset = 0;
	debug_log_prive_t *log_priv = &debugger->priv.log;

	level = 0;
	/*
	 *pthread_mutex_t *lock = &log_priv->log_file_lock;
	 *pthread_mutex_lock(lock);
	 */
	sync_lock(&log_priv->log_file_lock,NULL);
	memset(buffer_str,'\0',MAX_LOG_PRINT_BUFFER_LEN);
	offset = vsnprintf(buffer_str,MAX_LOG_PRINT_BUFFER_LEN,fmt,vl);
	ret = log_print_write_log(log_priv->fp,buffer_str);
	sync_unlock(&log_priv->log_file_lock);
	/*
	 *pthread_mutex_unlock(&log_priv->log_file_lock);
	 */

	return ret;
#undef MAX_LOG_PRINT_BUFFER_LEN 
}
示例#12
0
static int control_unlock(struct gfs2_sbd *sdp)
{
	struct lm_lockstruct *ls = &sdp->sd_lockstruct;
	return sync_unlock(sdp, &ls->ls_control_lksb, "control_lock");
}
示例#13
0
static int mounted_unlock(struct gfs2_sbd *sdp)
{
	struct lm_lockstruct *ls = &sdp->sd_lockstruct;
	return sync_unlock(sdp, &ls->ls_mounted_lksb, "mounted_lock");
}
示例#14
0
void vfs_user_periodic(uint32_t elapsed_ms)
{
    vfs_user_state_t vfs_state_local;
    vfs_user_state_t vfs_state_local_prev;
    sync_assert_usb_thread();
    sync_lock();

    // Return immediately if the desired state has been reached
    if (!changing_state()) {
        sync_unlock();
        return;
    }

    // Wait until the required amount of time has passed
    // before changing state
    if (vfs_state_remaining_ms > 0) {
        vfs_state_remaining_ms -= MIN(elapsed_ms, vfs_state_remaining_ms);
        sync_unlock();
        return;
    }

    vfs_user_printf("vfs_user_periodic()\r\n");

    // Transistion to new state
    vfs_state_local_prev = vfs_state;
    vfs_state = vfs_state_next;
    switch (vfs_state) {
        case VFS_USER_STATE_RECONNECTING:
            // Transition back to the connected state
            vfs_state_next = VFS_USER_STATE_CONNECTED;
            vfs_state_remaining_ms = reconnect_delay_ms;
            break;
        default:
            // No state change logic required in other states
            break;
    }
    vfs_state_local = vfs_state;
    sync_unlock();

    // Processing when leaving a state
    vfs_user_printf("    state %i->%i\r\n", vfs_state_local_prev, vfs_state_local);
    switch (vfs_state_local_prev) {
        case VFS_USER_STATE_DISCONNECTED:
            // No action needed
            break;
        case VFS_USER_STATE_RECONNECTING:
            // No action needed
            break;
        case VFS_USER_STATE_CONNECTED:
            if (file_transfer_state.stream_open) {
                error_t status;
                file_transfer_state.stream_open = false;
                status = stream_close();
                if (ERROR_SUCCESS == fail_reason) {
                    fail_reason = status;
                }
                vfs_user_printf("    stream_close ret %i\r\n", status);
            }
            // Reset if programming was successful  //TODO - move to flash layer
            if (daplink_is_bootloader() && (ERROR_SUCCESS == fail_reason)) {
                NVIC_SystemReset();
            }
            // If hold in bootloader has been set then reset after usb is disconnected
            if (daplink_is_interface() && config_ram_get_hold_in_bl()) {
                NVIC_SystemReset();
            }
            // Resume the target if configured to do so //TODO - move to flash layer
            if (config_get_auto_rst()) {
                target_set_state(RESET_RUN);
            }
            break;
    }

    // Processing when entering a state
    switch (vfs_state_local) {
        case VFS_USER_STATE_DISCONNECTED:
            USBD_MSC_MediaReady = 0;
            break;
        case VFS_USER_STATE_RECONNECTING:
            USBD_MSC_MediaReady = 0;
            break;
        case VFS_USER_STATE_CONNECTED:
            build_filesystem();
            USBD_MSC_MediaReady = 1;
            break;
    }
    return;
}
示例#15
0
void vfs_mngr_periodic(uint32_t elapsed_ms)
{
    bool change_state;
    vfs_mngr_state_t vfs_state_local;
    vfs_mngr_state_t vfs_state_local_prev;
    sync_assert_usb_thread();
    sync_lock();

    // Return immediately if the desired state has been reached
    if (!changing_state()) {
        sync_unlock();
        return;
    }

    change_state = ready_for_state_change();

    if (time_usb_idle < MAX_EVENT_TIME_MS) {
        time_usb_idle += elapsed_ms;
    }

    sync_unlock();

    if (!change_state) {
        return;
    }

    vfs_mngr_printf("vfs_mngr_periodic()\r\n");
    vfs_mngr_printf("   time_usb_idle=%i\r\n", time_usb_idle);
    vfs_mngr_printf("   transfer_state=%i\r\n", file_transfer_state.transfer_state);
    // Transistion to new state
    vfs_state_local_prev = vfs_state;
    vfs_state = vfs_state_next;

    switch (vfs_state) {
        case VFS_MNGR_STATE_RECONNECTING:
            // Transition back to the connected state
            vfs_state_next = VFS_MNGR_STATE_CONNECTED;
            break;

        default:
            // No state change logic required in other states
            break;
    }

    vfs_state_local = vfs_state;
    time_usb_idle = 0;
    sync_unlock();
    // Processing when leaving a state
    vfs_mngr_printf("    state %i->%i\r\n", vfs_state_local_prev, vfs_state_local);

    switch (vfs_state_local_prev) {
        case VFS_MNGR_STATE_DISCONNECTED:
            // No action needed
            break;

        case VFS_MNGR_STATE_RECONNECTING:
            // No action needed
            break;

        case VFS_MNGR_STATE_CONNECTED:

            // Close ongoing transfer if there is one
            if (file_transfer_state.transfer_state != TRASNFER_FINISHED) {
                vfs_mngr_printf("    transfer timeout\r\n");
                file_transfer_state.transfer_timeout = true;
                transfer_update_state(ERROR_SUCCESS);
            }

            util_assert(TRASNFER_FINISHED == file_transfer_state.transfer_state);
            vfs_user_disconnecting();
            break;
    }

    // Processing when entering a state
    switch (vfs_state_local) {
        case VFS_MNGR_STATE_DISCONNECTED:
            USBD_MSC_MediaReady = 0;
            break;

        case VFS_MNGR_STATE_RECONNECTING:
            USBD_MSC_MediaReady = 0;
            break;

        case VFS_MNGR_STATE_CONNECTED:
            build_filesystem();
            USBD_MSC_MediaReady = 1;
            break;
    }

    return;
}
示例#16
0
void timer_unlock (void)
{
	sync_unlock (&core_timer);
}