示例#1
0
/**@brief Flash operation success callback handler.
 *
 * @details     This function updates read/write pointers.
 *              This function resets retry count.
 */
static __INLINE void on_operation_success(void)
{
    fs_cmd_t * const p_cmd = &m_cmd_queue.cmd[m_cmd_queue.rp];

    m_retry_count = 0;

    switch (p_cmd->op_code)
    {
        case FS_OP_STORE:
            // Update the offset on successful write.
            p_cmd->offset += FS_MAX_WRITE_SIZE_WORDS;
            break;

        case FS_OP_ERASE:
            // Update the offset to correspond to the page that has been erased.
            p_cmd->offset += FS_PAGE_SIZE_WORDS;
            break;
    }

    // If offset is equal to or larger than length, then the operation has finished.
    if (p_cmd->offset >= p_cmd->length_words)
    {
        cmd_consume(NRF_SUCCESS, p_cmd);
    }

    queue_process();
}
示例#2
0
/**@brief Function to handle system events from the SoftDevice.
 *
 * @details     This function should be dispatched system events if any of the modules used by
 *              the application rely on FStorage. Examples include @ref Peer Manager and
 *              @ref Flash Data Storage.
 *
 * @param[in]   sys_evt     System Event received.
 */
void fs_sys_event_handler(uint32_t sys_evt)
{
    fs_cmd_t const * const p_cmd = &m_cmd_queue.cmd[m_cmd_queue.rp];
    
    if (m_flags & FS_FLAG_PROCESSING)
    {
        /** A flash operation was initiated by this module.
         *  Handle its result. */
        switch (sys_evt)
        {
            case NRF_EVT_FLASH_OPERATION_SUCCESS:
                on_operation_success(p_cmd);
                break;

            case NRF_EVT_FLASH_OPERATION_ERROR:
                on_operation_failure(p_cmd);
                break;
        }
    }
    else if ((m_flags & FS_FLAG_FLASH_REQ_PENDING))
    {
        /** A flash operation was initiated outside this module.
         *  We have now receveid a callback which indicates it has
         *  finished. Clear the FS_FLAG_FLASH_REQ_PENDING flag. */
         m_flags &= ~FS_FLAG_FLASH_REQ_PENDING;
    }

    // Resume processing the queue, if necessary.
    queue_process();
}
示例#3
0
文件: ctdb_io.c 项目: AIdrifter/samba
static void queue_process_event(struct tevent_context *ev, struct tevent_immediate *im,
				void *private_data)
{
	struct ctdb_queue *queue = talloc_get_type(private_data, struct ctdb_queue);

	queue_process(queue);
}
示例#4
0
/**@brief Function to enqueue flash access command
 *
 * @param[in]   config      Registered configuration.
 * @param[in]   op_code     Operation code.
 * @param[in]   address     Destination of the data.
 * @param[in]   p_src       Source of data or NULL if n/a.
 * @param[in]   length      Length of the data, in 4 byte words.
 *
 * @retval NRF_SUCCESS      Success. Command enqueued.
 * @retval NRF_ERROR_NO_MEM Error. Queue is full.
 * @retval Any error returned by the SoftDevice flash API.
 */
static ret_code_t cmd_enqueue(fs_config_t      const * p_config,
                              uint8_t                  op_code,
                              uint32_t         const * p_addr,
                              uint32_t         const * p_src,
                              fs_length_t              length_words)
{
    fs_cmd_t * p_cmd;
    uint8_t    write_pos;

    if (m_cmd_queue.count == FS_CMD_QUEUE_SIZE - 1)
    {
        return NRF_ERROR_NO_MEM;
    }

    write_pos = (m_cmd_queue.rp + m_cmd_queue.count) % FS_CMD_QUEUE_SIZE;

    p_cmd = &m_cmd_queue.cmd[write_pos];

    p_cmd->p_config     = p_config;
    p_cmd->op_code      = op_code;
    p_cmd->p_src        = p_src;
    p_cmd->p_addr       = p_addr;
    p_cmd->length_words = length_words;

    m_cmd_queue.count++;

    return queue_process();
}
示例#5
0
void fs_sys_event_handler(uint32_t sys_evt)
{
    fs_op_t * const p_op = &m_queue.op[m_queue.rp];
    
    if (m_flags & FS_FLAG_PROCESSING)
    {
        // A flash operation was initiated by this module. Handle the result.
        switch (sys_evt)
        {
            case NRF_EVT_FLASH_OPERATION_SUCCESS:
                on_operation_success(p_op);
                break;

            case NRF_EVT_FLASH_OPERATION_ERROR:
                on_operation_failure(p_op);
                break;
        }
    }
    else if ((m_flags & FS_FLAG_FLASH_REQ_PENDING))
    {
        // A flash operation was initiated outside this module.
        // A callback which indicates that it has finished was received.
        m_flags &= ~FS_FLAG_FLASH_REQ_PENDING;

        // If there are any elements left in the queue, set FS_FLAG_PROCESSING.
        if (m_queue.count > 0)
        {
           m_flags |= FS_FLAG_PROCESSING;
        }
    }

    // Resume processing the queue, if necessary.
    queue_process();
}
示例#6
0
// Starts processing the queue if there are no pending flash operations, both inside and
// outside this module. Returns immediately otherwise.
static void queue_start(void)
{
    if (!(m_flags & FS_FLAG_PROCESSING) &&
        !(m_flags & FS_FLAG_FLASH_REQ_PENDING))
    {
        m_flags |= FS_FLAG_PROCESSING;
        queue_process();
    }
}
示例#7
0
/**@brief Flash operation failure callback handler.
 *
 * @details Function to keep track of retries and notify failures.
 */
static __INLINE void on_operation_failure(uint32_t sys_evt)
{
    const fs_cmd_t * p_cmd;
    
    if (++m_retry_count > FS_CMD_MAX_RETRIES)
    {
        p_cmd = &m_cmd_queue.cmd[m_cmd_queue.rp];
        cmd_consume(NRF_ERROR_TIMEOUT, p_cmd);
    }

    queue_process();
}
示例#8
0
/**@brief Starts processing the queue if there are no pending flash operations
 *        for which we are awaiting a callback.
 */
static ret_code_t queue_process_start(void)
{
    ret_code_t ret = NRF_SUCCESS;

    /** If the queue is not being processed and there are no events pending,
     *  then start processing. */
    if (!(m_flags & FS_FLAG_PROCESSING) &&
        !(m_flags & FS_FLAG_FLASH_REQ_PENDING))
    {
        m_flags |= FS_FLAG_PROCESSING;

        ret = queue_process();        
    }

    // If already processing the queue, return immediately.
    return ret;
}
示例#9
0
文件: main.c 项目: byte-mug/cumes
int main(int argc,const char* const* argv){
	int c;
	const char* message = NULL;
	while ( (c = getopt(argc,(char*const*)argv, "p:")) != -1) {
		switch(c) {
			/* -p $MSGID : preprocess message $MSGID */
			caseof('p',message = optarg)
		}
	}
	if(message) {
		queue_init();
		queue_process(message);
		return 0;
	}

	clock_init(argv[0]);
	clock_loop();
	return 1;
}
示例#10
0
文件: ctdb_io.c 项目: AIdrifter/samba
/*
  called when an incoming connection is readable
  This function MUST be safe for reentry via the queue callback!
*/
static void queue_io_read(struct ctdb_queue *queue)
{
	int num_ready = 0;
	ssize_t nread;
	uint8_t *data;
	int navail;

	/* check how much data is available on the socket for immediately
	   guaranteed nonblocking access.
	   as long as we are careful never to try to read more than this
	   we know all reads will be successful and will neither block
	   nor fail with a "data not available right now" error
	*/
	if (ioctl(queue->fd, FIONREAD, &num_ready) != 0) {
		return;
	}
	if (num_ready == 0) {
		/* the descriptor has been closed */
		goto failed;
	}

	if (queue->buffer.data == NULL) {
		/* starting fresh, allocate buf to read data */
		queue->buffer.data = talloc_size(queue, QUEUE_BUFFER_SIZE);
		if (queue->buffer.data == NULL) {
			DEBUG(DEBUG_ERR, ("read error alloc failed for %u\n", num_ready));
			goto failed;
		}
		queue->buffer.size = QUEUE_BUFFER_SIZE;
	} else if (queue->buffer.extend > 0) {
		/* extending buffer */
		data = talloc_realloc_size(queue, queue->buffer.data, queue->buffer.extend);
		if (data == NULL) {
			DEBUG(DEBUG_ERR, ("read error realloc failed for %u\n", queue->buffer.extend));
			goto failed;
		}
		queue->buffer.data = data;
		queue->buffer.size = queue->buffer.extend;
		queue->buffer.extend = 0;
	}

	navail = queue->buffer.size - queue->buffer.length;
	if (num_ready > navail) {
		num_ready = navail;
	}

	if (num_ready > 0) {
		nread = read(queue->fd, queue->buffer.data + queue->buffer.length, num_ready);
		if (nread <= 0) {
			DEBUG(DEBUG_ERR, ("read error nread=%d\n", (int)nread));
			goto failed;
		}
		queue->buffer.length += nread;
	}

	queue_process(queue);
	return;

failed:
	queue->callback(NULL, 0, queue->private_data);
}
示例#11
0
int main(int argc, char *argv[]) {

	/*unsigned int m = -1;

	 printf("%ud\n", m);*/

	if (argc < 2) {
		printf("Usage: ./cpusched in.txt out.txt SCHEDULE_ALGORITHM [quantum]");
		exit(1);
	}

	//get the algorithm indicator
	SCHEDULER method;
	if (strcmp("FCFS", argv[3]) == 0)
		method = FCFS;
	else if (strcmp("RR", argv[3]) == 0)
		method = RR;
	else if (strcmp("SJF", argv[3]) == 0)
		method = SJF;
	else {
		printf("THE ALGORITHM DOESN'T EXISTS\n");
		exit(1);
	}

	//default by 5
	int quantum = 5;
	if (argc == 5)
		quantum = atoi(argv[4]);

	queue_init();

	//open the input text file
	FILE *f_in;
	if ((f_in = fopen(argv[1], "r+")) == NULL) {
		printf("THE INPUT FILE DOESN'T EXISTS");
	}

	int pid, atime, burst;

	while (fscanf(f_in, "%d\t%d\t%d", &pid, &atime, &burst) != -1) {
		printf("%d:%d:%d\n", pid, atime, burst);

		priority_queue *queue = malloc(sizeof(priority_queue));
		process p;
		p.pid = pid;
		p.arrival_time = atime;
		p.cpu_burst = burst;
		p.process_status = PENDING;
		p.consume_time = 0;
		p.last_exec_tick = 0;
		p.done_print = 0;
		p.exec_times = 0;

		queue->current_process = p;
		queue->next_ptr = NULL;

		queue_insert(queue, method);
	}

	printf("out of the castle\n");

	if ((f_out = fopen(argv[2], "w+")) == NULL) {
		printf("THE OUTPUT FILE CREATED FAILED!\n");
	}

	queue_process(method, quantum);

	if (method == FCFS)
		queue_print(f_out);

	fclose(f_in);
	fclose(f_out);

	return 0;
}