forked from frodosens/fsnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
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.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.