Skip to content

Commit

Permalink
整理文件结构
Browse files Browse the repository at this point in the history
  • Loading branch information
Vincent authored and Vincent committed Jun 12, 2014
2 parents 7a6c475 + 69aad92 commit 88ec645
Show file tree
Hide file tree
Showing 4,565 changed files with 1,975,750 additions and 0 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified FSNet/.DS_Store
Binary file not shown.
22 changes: 22 additions & 0 deletions FSNet/fs_define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// fs_define.h
// fsnet
//
// Created by Vincent on 14-5-20.
// Copyright (c) 2014年 Vincent. All rights reserved.
//

#ifndef FSNet_fs_define_h
#define FSNet_fs_define_h


#define BYTE unsigned char
#define fs_bool BYTE
#define fs_true 1
#define fs_false 0
#define fs_id int
#define fs_script_id unsigned long
#define fs_pack_type int16_t


#endif
86 changes: 86 additions & 0 deletions FSNet/fs_loop_queue.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
//
// fs_loop_queue.c
// fsnet
//
// Created by Vincent on 14-5-22.
// Copyright (c) 2014年 Vincent. All rights reserved.
//

#include <stdio.h>
#include "fs_loop_queue.h"
#include "fs_malloc.h"


struct fs_loop_queue{

void** que;
size_t head;
size_t tail;
size_t max_len;

unsigned long script_id;
};


#define _pos_add(x, n, max) x = (x + n) % max

struct fs_loop_queue*
fs_create_loop_queue(size_t len){
struct fs_loop_queue* queue = (struct fs_loop_queue*)fs_malloc(sizeof(*queue));
fs_zero(queue, sizeof(*queue));
queue->max_len = len;
queue->que = fs_malloc( sizeof( void* ) * len );
fs_zero(queue->que, sizeof( void* ) * len);
return queue;
}

fs_bool
fs_loop_queue_push( struct fs_loop_queue* que, void* item){

if(fs_loop_queue_full(que)){
return fs_false;
}

que->que[que->head] = item;
_pos_add(que->head, 1, que->max_len);


return fs_true;
}

void*
fs_loop_queue_pop( struct fs_loop_queue* que ){

if(fs_loop_queue_empty(que)){
return NULL;
}


void* item = que->que[que->tail];
que->que[que->tail] = NULL;
_pos_add(que->tail, 1, que->max_len);

return item;

}

fs_bool
fs_loop_queue_full( struct fs_loop_queue* que ){

return ((que->head + 1) % que->max_len) == que->tail;
}

fs_bool
fs_loop_queue_empty( struct fs_loop_queue* que ){

return que->head == que->tail;
}


void
fs_loop_queue_free( struct fs_loop_queue* que){

fs_free(que->que);
fs_free(que);

}
27 changes: 27 additions & 0 deletions FSNet/fs_loop_queue.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// fs_loop_queue.h
// fsnet
//
// Created by Vincent on 14-5-22.
// Copyright (c) 2014年 Vincent. All rights reserved.
//

#ifndef fsnet_fs_loop_queue_h
#define fsnet_fs_loop_queue_h

#include "fs_define.h"

struct fs_loop_queue;


struct fs_loop_queue* fs_create_loop_queue(size_t len);

fs_bool fs_loop_queue_push(struct fs_loop_queue*, void* item);
void* fs_loop_queue_pop(struct fs_loop_queue*);

fs_bool fs_loop_queue_full(struct fs_loop_queue*);
fs_bool fs_loop_queue_empty(struct fs_loop_queue*);

void fs_loop_queue_free( struct fs_loop_queue* );

#endif
47 changes: 47 additions & 0 deletions FSNet/fs_malloc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// fs_malloc.c
// fsnet
//
// Created by Vincent on 14-5-20.
// Copyright (c) 2014年 Vincent. All rights reserved.
//

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "fs_define.h"
#include <jemalloc.h>

void*
fs_malloc(size_t len){
// return ruby_xmalloc(len);
return je_malloc(len);
// return malloc(len);
}


void
fs_free(void* ptr){
// ruby_xfree(ptr);
je_free(ptr);
// free(ptr);
}

void*
fs_realloc(void* ptr, size_t len) {
// return ruby_xrealloc(ptr, len);
return je_realloc(ptr, len);
// return realloc(ptr, len);
}


void
fs_zero(void* data, size_t len){
memset(data, 0, len);
}

void fs_assert(fs_bool cond){
if(!cond){
abort();
}
}
21 changes: 21 additions & 0 deletions FSNet/fs_malloc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// fs_malloc.h
// fsnet
//
// Created by Vincent on 14-5-20.
// Copyright (c) 2014年 Vincent. All rights reserved.
//

#ifndef FSNet_fs_malloc_h
#define FSNet_fs_malloc_h

#include "fs_define.h"

void* fs_malloc(size_t);
void fs_free(void*);
void* fs_realloc(void*, size_t);
void fs_zero(void*, size_t);

void fs_assert(fs_bool cond);

#endif
Loading

0 comments on commit 88ec645

Please sign in to comment.