Merge branch 'feature/cpp'

This commit is contained in:
Jittapan Pluemsumran 2017-05-05 16:53:25 +07:00
commit 4a004ad4b8
No known key found for this signature in database
GPG Key ID: CE430096446F41D9
18 changed files with 897 additions and 568 deletions

View File

@ -1,7 +1,8 @@
language: c language: cpp
compiler: compiler:
- clang - clang
- gcc - gcc
dist: trusty
before_script: before_script:
- uname -a - uname -a
@ -24,6 +25,10 @@ before_script:
- mysql -u $DB_ROOT $DB_NAME < sql-files/mob_skill_db2_re.sql || aborterror "Unable to import renewal monster skill 2 table." - mysql -u $DB_ROOT $DB_NAME < sql-files/mob_skill_db2_re.sql || aborterror "Unable to import renewal monster skill 2 table."
- mysql -u $DB_ROOT $DB_NAME < sql-files/roulette_default_data.sql || aborterror "Unable to import roulette table." - mysql -u $DB_ROOT $DB_NAME < sql-files/roulette_default_data.sql || aborterror "Unable to import roulette table."
- mysql -u $DB_ROOT -e "GRANT ALL ON *.* TO '$DB_USER'@'$DB_HOST' IDENTIFIED BY '$DB_PASS';" - mysql -u $DB_ROOT -e "GRANT ALL ON *.* TO '$DB_USER'@'$DB_HOST' IDENTIFIED BY '$DB_PASS';"
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update -q
- sudo apt-get install gcc-4.8 -y
- sudo apt-get install g++-4.8 -y
script: script:
- ./configure $CONFIGURE_FLAGS - ./configure $CONFIGURE_FLAGS

1225
configure vendored

File diff suppressed because it is too large Load Diff

View File

@ -433,9 +433,9 @@ AC_ARG_WITH(
AC_PROG_MAKE_SET AC_PROG_MAKE_SET
AC_PROG_CC AC_PROG_CC
AC_PROG_CPP AC_PROG_CXX
AC_PATH_PROG(AR, ar) AC_PATH_PROG(AR, ar)
AC_LANG([C]) AC_LANG([C++])
CFLAGS="$CFLAGS -pipe -ffast-math -Wall" CFLAGS="$CFLAGS -pipe -ffast-math -Wall"
@ -700,12 +700,12 @@ AC_CHECK_COMPILER_WNOFLAG(unused-parameter, [int foo(int bar) { return 0; }])
AC_CHECK_COMPILER_WNOFLAG(maybe-uninitialized) AC_CHECK_COMPILER_WNOFLAG(maybe-uninitialized)
AC_CHECK_COMPILER_WNOFLAG(clobbered) AC_CHECK_COMPILER_WNOFLAG(clobbered)
AC_CHECK_COMPILER_WFLAG(empty-body) AC_CHECK_COMPILER_WFLAG(empty-body)
AC_CHECK_COMPILER_WFLAG(newline-eof) #AC_CHECK_COMPILER_WFLAG(newline-eof)
AC_CHECK_COMPILER_WFLAG(int-conversion) #AC_CHECK_COMPILER_WFLAG(int-conversion)
AC_CHECK_COMPILER_WFLAG(enum-conversion) #AC_CHECK_COMPILER_WFLAG(enum-conversion)
AC_CHECK_COMPILER_WFLAG(shorten-64-to-32) #AC_CHECK_COMPILER_WFLAG(shorten-64-to-32)
AC_CHECK_COMPILER_WFLAG(constant-conversion) #AC_CHECK_COMPILER_WFLAG(constant-conversion)
AC_CHECK_COMPILER_WFLAG(bool-conversion) #AC_CHECK_COMPILER_WFLAG(bool-conversion)
AC_CHECK_COMPILER_WNOFLAG(switch) AC_CHECK_COMPILER_WNOFLAG(switch)
AC_CHECK_COMPILER_WNOFLAG(missing-field-initializers) AC_CHECK_COMPILER_WNOFLAG(missing-field-initializers)

View File

@ -23,6 +23,8 @@ else
endif endif
ALL_DEPENDS=server ALL_DEPENDS=server
CXXFLAG =-std=c++11
@SET_MAKE@ @SET_MAKE@
##################################################################### #####################################################################
@ -63,10 +65,18 @@ obj/%.o: %.c $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H)
@echo " CC $<" @echo " CC $<"
@@CC@ @CFLAGS_AR@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $< @@CC@ @CFLAGS_AR@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
obj/%.o: %.cpp $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H)
@echo " CXX $<"
@@CXX@ $(CXXFLAG) @CFLAGS_AR@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
obj/mini%.o: %.c $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H) obj/mini%.o: %.c $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H)
@echo " CC $<" @echo " CC $<"
@@CC@ @CFLAGS_AR@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ -DMINICORE @CPPFLAGS@ -c $(OUTPUT_OPTION) $< @@CC@ @CFLAGS_AR@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ -DMINICORE @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
obj/mini%.o: %.cpp $(COMMON_H) $(MT19937AR_H) $(LIBCONFIG_H)
@echo " CXX $<"
@@CXX@ $(CXXFLAG) @CFLAGS_AR@ $(MT19937AR_INCLUDE) $(LIBCONFIG_INCLUDE) @MYSQL_CFLAGS@ -DMINICORE @CPPFLAGS@ -c $(OUTPUT_OPTION) $<
# missing object files # missing object files
$(MT19937AR_OBJ): $(MT19937AR_OBJ):
@$(MAKE) -C ../../3rdparty/mt19937ar @$(MAKE) -C ../../3rdparty/mt19937ar

View File

@ -2,6 +2,7 @@
// For more information, see LICENCE in the main folder // For more information, see LICENCE in the main folder
#include "mmo.h" #include "mmo.h"
#include "cbasetypes.h"
#include "showmsg.h" #include "showmsg.h"
#include "malloc.h" #include "malloc.h"
#include "core.h" #include "core.h"
@ -164,14 +165,14 @@ const char* get_svn_revision(void) {
// - ignores database file structure // - ignores database file structure
// - assumes the data in NODES.dav_cache column ends with "!svn/ver/<revision>/<path>)" // - assumes the data in NODES.dav_cache column ends with "!svn/ver/<revision>/<path>)"
// - since it's a cache column, the data might not even exist // - since it's a cache column, the data might not even exist
if( (fp = fopen(".svn"PATHSEP_STR"wc.db", "rb")) != NULL || (fp = fopen(".."PATHSEP_STR".svn"PATHSEP_STR"wc.db", "rb")) != NULL ) if( (fp = fopen(".svn" PATHSEP_STR "wc.db", "rb")) != NULL || (fp = fopen(".." PATHSEP_STR ".svn" PATHSEP_STR "wc.db", "rb")) != NULL )
{ {
#ifndef SVNNODEPATH #ifndef SVNNODEPATH
//not sure how to handle branches, so i'll leave this overridable define until a better solution comes up //not sure how to handle branches, so i'll leave this overridable define until a better solution comes up
#define SVNNODEPATH trunk #define SVNNODEPATH trunk
#endif #endif
const char* prefix = "!svn/ver/"; const char* prefix = "!svn/ver/";
const char* postfix = "/"EXPAND_AND_QUOTE(SVNNODEPATH)")"; // there should exist only 1 entry like this const char* postfix = "/" EXPAND_AND_QUOTE(SVNNODEPATH) ")"; // there should exist only 1 entry like this
size_t prefix_len = strlen(prefix); size_t prefix_len = strlen(prefix);
size_t postfix_len = strlen(postfix); size_t postfix_len = strlen(postfix);
size_t i,j,len; size_t i,j,len;
@ -257,7 +258,7 @@ const char *get_git_hash (void) {
if( GitHash[0] != '\0' ) if( GitHash[0] != '\0' )
return GitHash; return GitHash;
if( (fp = fopen(".git/"GIT_ORIGIN, "r")) != NULL ) { if( (fp = fopen(".git/" GIT_ORIGIN, "r")) != NULL ) {
char line[64]; char line[64];
char *rev = (char*)malloc(sizeof(char) * 50); char *rev = (char*)malloc(sizeof(char) * 50);
@ -286,21 +287,21 @@ static void display_title(void) {
const char* git = get_git_hash(); const char* git = get_git_hash();
ShowMessage("\n"); ShowMessage("\n");
ShowMessage(""CL_PASS" "CL_BOLD" "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BOLD " " CL_PASS"" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_BT_WHITE" rAthena Development Team presents "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BT_WHITE " rAthena Development Team presents " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_BOLD" ___ __ __ "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BOLD " ___ __ __ " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_BOLD" _____/ | / /_/ /_ ___ ____ ____ _ "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BOLD " _____/ | / /_/ /_ ___ ____ ____ _ " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_BOLD" / ___/ /| |/ __/ __ \\/ _ \\/ __ \\/ __ `/ "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BOLD " / ___/ /| |/ __/ __ \\/ _ \\/ __ \\/ __ `/ " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_BOLD" / / / ___ / /_/ / / / __/ / / / /_/ / "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BOLD " / / / ___ / /_/ / / / __/ / / / /_/ / " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_BOLD" /_/ /_/ |_\\__/_/ /_/\\___/_/ /_/\\__,_/ "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BOLD " /_/ /_/ |_\\__/_/ /_/\\___/_/ /_/\\__,_/ " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_BOLD" "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BOLD " " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_GREEN" http://rathena.org/board/ "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_GREEN " http://rathena.org/board/ " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
ShowMessage(""CL_PASS" "CL_BOLD" "CL_PASS""CL_CLL""CL_NORMAL"\n"); ShowMessage("" CL_PASS " " CL_BOLD " " CL_PASS "" CL_CLL "" CL_NORMAL "\n");
if( svn[0] != UNKNOWN_VERSION ) if( svn[0] != UNKNOWN_VERSION )
ShowInfo("SVN Revision: '"CL_WHITE"%s"CL_RESET"'\n", svn); ShowInfo("SVN Revision: '" CL_WHITE "%s" CL_RESET "'\n", svn);
else if( git[0] != UNKNOWN_VERSION ) else if( git[0] != UNKNOWN_VERSION )
ShowInfo("Git Hash: '"CL_WHITE"%s"CL_RESET"'\n", git); ShowInfo("Git Hash: '" CL_WHITE "%s" CL_RESET "'\n", git);
} }
// Warning if executed as superuser (root) // Warning if executed as superuser (root)

View File

@ -4,6 +4,10 @@
#ifndef _CORE_H_ #ifndef _CORE_H_
#define _CORE_H_ #define _CORE_H_
#ifdef __cplusplus
extern "C" {
#endif
/* so that developers with --enable-debug can raise signals from any section of the code they'd like */ /* so that developers with --enable-debug can raise signals from any section of the code they'd like */
#ifdef DEBUG #ifdef DEBUG
#include <signal.h> #include <signal.h>
@ -53,4 +57,8 @@ enum E_CORE_ST
/// If NULL, runflag is set to CORE_ST_STOP instead. /// If NULL, runflag is set to CORE_ST_STOP instead.
extern void (*shutdown_callback)(void); extern void (*shutdown_callback)(void);
#ifdef __cplusplus
}
#endif
#endif /* _CORE_H_ */ #endif /* _CORE_H_ */

View File

@ -42,6 +42,10 @@
#ifndef _DB_H_ #ifndef _DB_H_
#define _DB_H_ #define _DB_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "cbasetypes.h" #include "cbasetypes.h"
#include <stdarg.h> #include <stdarg.h>
@ -1655,6 +1659,8 @@ void linkdb_foreach (struct linkdb_node** head, LinkDBFunc func, ...);
/// @return negative if v1 is top, positive if v2 is top, 0 if equal /// @return negative if v1 is top, positive if v2 is top, 0 if equal
#define BHEAP_MAXTOPCMP(v1,v2) ( v1 == v2 ? 0 : v1 > v2 ? -1 : 1 ) #define BHEAP_MAXTOPCMP(v1,v2) ( v1 == v2 ? 0 : v1 > v2 ? -1 : 1 )
#ifdef __cplusplus
}
#endif
#endif /* _DB_H_ */ #endif /* _DB_H_ */

View File

@ -40,6 +40,10 @@
#ifndef _ERS_H_ #ifndef _ERS_H_
#define _ERS_H_ #define _ERS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "cbasetypes.h" #include "cbasetypes.h"
/*****************************************************************************\ /*****************************************************************************\
@ -175,4 +179,8 @@ void ers_report(void);
void ers_final(void); void ers_final(void);
#endif /* DISABLE_ERS / not DISABLE_ERS */ #endif /* DISABLE_ERS / not DISABLE_ERS */
#ifdef __cplusplus
}
#endif
#endif /* _ERS_H_ */ #endif /* _ERS_H_ */

View File

@ -4,6 +4,9 @@
#ifndef _MALLOC_H_ #ifndef _MALLOC_H_
#define _MALLOC_H_ #define _MALLOC_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "cbasetypes.h" #include "cbasetypes.h"
#define ALC_MARK __FILE__, __LINE__, __func__ #define ALC_MARK __FILE__, __LINE__, __func__
@ -89,4 +92,8 @@ size_t malloc_usage (void);
void malloc_init (void); void malloc_init (void);
void malloc_final (void); void malloc_final (void);
#ifdef __cplusplus
}
#endif
#endif /* _MALLOC_H_ */ #endif /* _MALLOC_H_ */

View File

@ -51,7 +51,7 @@ struct ra_align(16) node{
// The Pointer to this struct is the base address of the segment itself. // The Pointer to this struct is the base address of the segment itself.
struct pool_segment{ struct pool_segment{
mempool pool; // pool, this segment belongs to pMempool pool; // pool, this segment belongs to
struct pool_segment *next; struct pool_segment *next;
int64 num_nodes_total; int64 num_nodes_total;
int64 num_bytes; int64 num_bytes;
@ -96,17 +96,17 @@ struct mempool{
/// ///
// Implementation: // Implementation:
// //
static void segment_allocate_add(mempool p, uint64 count); static void segment_allocate_add(pMempool p, uint64 count);
static SPIN_LOCK l_mempoolListLock; static SPIN_LOCK l_mempoolListLock;
static mempool l_mempoolList = NULL; static pMempool l_mempoolList = NULL;
static rAthread l_async_thread = NULL; static prAthread l_async_thread = NULL;
static ramutex l_async_lock = NULL; static ramutex l_async_lock = NULL;
static racond l_async_cond = NULL; static racond l_async_cond = NULL;
static volatile int32 l_async_terminate = 0; static volatile int32 l_async_terminate = 0;
static void *mempool_async_allocator(void *x){ static void *mempool_async_allocator(void *x){
mempool p; pMempool p;
while(1){ while(1){
@ -167,7 +167,7 @@ void mempool_init(){
void mempool_final(){ void mempool_final(){
mempool p, pn; pMempool p, pn;
if( rand()%2 + 1 ) if( rand()%2 + 1 )
return; return;
@ -205,7 +205,7 @@ void mempool_final(){
}//end: mempool_final() }//end: mempool_final()
static void segment_allocate_add(mempool p, uint64 count){ static void segment_allocate_add(pMempool p, uint64 count){
// Required Memory: // Required Memory:
// sz( segment ) // sz( segment )
@ -303,7 +303,7 @@ static void segment_allocate_add(mempool p, uint64 count){
}//end: segment_allocate_add() }//end: segment_allocate_add()
mempool mempool_create(const char *name, pMempool mempool_create(const char *name,
uint64 elem_size, uint64 elem_size,
uint64 initial_count, uint64 initial_count,
uint64 realloc_count, uint64 realloc_count,
@ -311,8 +311,8 @@ mempool mempool_create(const char *name,
memPoolOnNodeDeallocationProc onNodeDealloc){ memPoolOnNodeDeallocationProc onNodeDealloc){
//.. //..
uint64 realloc_thresh; uint64 realloc_thresh;
mempool pool; pMempool pool;
pool = (mempool)aCalloc( 1, sizeof(struct mempool) ); pool = (pMempool)aCalloc( 1, sizeof(struct mempool) );
if(pool == NULL){ if(pool == NULL){
ShowFatalError("mempool_create: Failed to allocate %u bytes memory.\n", sizeof(struct mempool) ); ShowFatalError("mempool_create: Failed to allocate %u bytes memory.\n", sizeof(struct mempool) );
@ -369,10 +369,10 @@ mempool mempool_create(const char *name,
}//end: mempool_create() }//end: mempool_create()
void mempool_destroy(mempool p){ void mempool_destroy(pMempool p){
struct pool_segment *seg, *segnext; struct pool_segment *seg, *segnext;
struct node *niter; struct node *niter;
mempool piter, pprev; pMempool piter, pprev;
char *ptr; char *ptr;
int64 i; int64 i;
@ -472,7 +472,7 @@ void mempool_destroy(mempool p){
}//end: mempool_destroy() }//end: mempool_destroy()
void *mempool_node_get(mempool p){ void *mempool_node_get(pMempool p){
struct node *node; struct node *node;
int64 num_used; int64 num_used;
@ -511,7 +511,7 @@ void *mempool_node_get(mempool p){
}//end: mempool_node_get() }//end: mempool_node_get()
void mempool_node_put(mempool p, void *data){ void mempool_node_put(pMempool p, void *data){
struct node *node; struct node *node;
node = DATA_TO_NODE(data); node = DATA_TO_NODE(data);
@ -544,7 +544,7 @@ void mempool_node_put(mempool p, void *data){
}//end: mempool_node_put() }//end: mempool_node_put()
mempool_stats mempool_get_stats(mempool pool){ mempool_stats mempool_get_stats(pMempool pool){
mempool_stats stats; mempool_stats stats;
// initialize all with zeros // initialize all with zeros

View File

@ -1,9 +1,13 @@
#ifndef _rA_MEMPOOL_H_ #ifndef _rA_MEMPOOL_H_
#define _rA_MEMPOOL_H_ #define _rA_MEMPOOL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "cbasetypes.h" #include "cbasetypes.h"
typedef struct mempool *mempool; typedef struct mempool *pMempool;
typedef void (*memPoolOnNodeAllocationProc)(void *ptr); typedef void (*memPoolOnNodeAllocationProc)(void *ptr);
typedef void (*memPoolOnNodeDeallocationProc)(void *ptr); typedef void (*memPoolOnNodeDeallocationProc)(void *ptr);
@ -45,7 +49,7 @@ void mempool_final();
* *
* @return not NULL * @return not NULL
*/ */
mempool mempool_create(const char *name, pMempool mempool_create(const char *name,
uint64 elem_size, uint64 elem_size,
uint64 initial_count, uint64 initial_count,
uint64 realloc_count, uint64 realloc_count,
@ -63,7 +67,7 @@ mempool mempool_create(const char *name,
* Everything gets deallocated, regardless if everything was freed properly! * Everything gets deallocated, regardless if everything was freed properly!
* So you have to ensure that all references are cleared properly! * So you have to ensure that all references are cleared properly!
*/ */
void mempool_destroy(mempool pool); void mempool_destroy(pMempool pool);
/** /**
@ -73,7 +77,7 @@ void mempool_destroy(mempool pool);
* *
* @return Address of empty Node * @return Address of empty Node
*/ */
void *mempool_node_get(mempool pool); void *mempool_node_get(pMempool pool);
/** /**
@ -82,7 +86,7 @@ void *mempool_node_get(mempool pool);
* @param pool - the pool to put the node, to * @param pool - the pool to put the node, to
* @param node - the node to return * @param node - the node to return
*/ */
void mempool_node_put(mempool pool, void *node); void mempool_node_put(pMempool pool, void *node);
/** /**
@ -94,7 +98,10 @@ void mempool_node_put(mempool pool, void *node);
* *
* @return stats struct * @return stats struct
*/ */
mempool_stats mempool_get_stats(mempool pool); mempool_stats mempool_get_stats(pMempool pool);
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -4,6 +4,10 @@
#ifndef _SHOWMSG_H_ #ifndef _SHOWMSG_H_
#define _SHOWMSG_H_ #define _SHOWMSG_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "../../3rdparty/libconfig/libconfig.h" #include "../../3rdparty/libconfig/libconfig.h"
// for help with the console colors look here: // for help with the console colors look here:
@ -97,4 +101,8 @@ extern void ShowError(const char *, ...);
extern void ShowFatalError(const char *, ...); extern void ShowFatalError(const char *, ...);
extern void ShowConfigWarning(config_setting_t *config, const char *string, ...); extern void ShowConfigWarning(config_setting_t *config, const char *string, ...);
#ifdef __cplusplus
}
#endif
#endif /* _SHOWMSG_H_ */ #endif /* _SHOWMSG_H_ */

View File

@ -17,6 +17,10 @@
#include <time.h> #include <time.h>
#ifdef __cplusplus
extern "C" {
#endif
#define FIFOSIZE_SERVERLINK 256*1024 #define FIFOSIZE_SERVERLINK 256*1024
// socket I/O macros // socket I/O macros
@ -182,4 +186,8 @@ void send_shortlist_add_fd(int fd);
void send_shortlist_do_sends(); void send_shortlist_do_sends();
#endif #endif
#ifdef __cplusplus
}
#endif
#endif /* _SOCKET_H_ */ #endif /* _SOCKET_H_ */

View File

@ -4,6 +4,10 @@
#ifndef _COMMON_SQL_H_ #ifndef _COMMON_SQL_H_
#define _COMMON_SQL_H_ #define _COMMON_SQL_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "cbasetypes.h" #include "cbasetypes.h"
#include <stdarg.h>// va_list #include <stdarg.h>// va_list
@ -341,5 +345,8 @@ void SqlStmt_Free(SqlStmt* self);
void Sql_Init(void); void Sql_Init(void);
#ifdef __cplusplus
}
#endif
#endif /* _COMMON_SQL_H_ */ #endif /* _COMMON_SQL_H_ */

View File

@ -4,12 +4,22 @@
#ifndef _STRLIB_H_ #ifndef _STRLIB_H_
#define _STRLIB_H_ #define _STRLIB_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "cbasetypes.h" #include "cbasetypes.h"
#include <stdarg.h> #include <stdarg.h>
#if !defined(__USE_GNU)
#define __USE_GNU // required to enable strnlen on some platforms #define __USE_GNU // required to enable strnlen on some platforms
#define __USED_GNU
#endif
#include <string.h> #include <string.h>
#if defined(__USED_GNU)
#undef __USE_GNU #undef __USE_GNU
#undef __USED_GNU
#endif
char* jstrescape (char* pt); char* jstrescape (char* pt);
char* jstrescapecpy (char* pt, const char* spt); char* jstrescapecpy (char* pt, const char* spt);
@ -152,4 +162,8 @@ void StringBuf_Clear(StringBuf* self);
void StringBuf_Destroy(StringBuf* self); void StringBuf_Destroy(StringBuf* self);
void StringBuf_Free(StringBuf* self); void StringBuf_Free(StringBuf* self);
#ifdef __cplusplus
}
#endif
#endif /* _STRLIB_H_ */ #endif /* _STRLIB_H_ */

View File

@ -96,7 +96,7 @@ void rathread_final(){
// gets called whenever a thread terminated .. // gets called whenever a thread terminated ..
static void rat_thread_terminated( rAthread handle ){ static void rat_thread_terminated( prAthread handle ){
int id_backup = handle->myID; int id_backup = handle->myID;
@ -117,7 +117,7 @@ static void *_raThreadMainRedirector( void *p ){
// Update myID @ TLS to right id. // Update myID @ TLS to right id.
#ifdef HAS_TLS #ifdef HAS_TLS
g_rathread_ID = ((rAthread)p)->myID; g_rathread_ID = ((prAthread)p)->myID;
#endif #endif
#ifndef WIN32 #ifndef WIN32
@ -135,13 +135,13 @@ static void *_raThreadMainRedirector( void *p ){
#endif #endif
ret = ((rAthread)p)->proc( ((rAthread)p)->param ) ; ret = ((prAthread)p)->proc( ((prAthread)p)->param ) ;
#ifdef WIN32 #ifdef WIN32
CloseHandle( ((rAthread)p)->hThread ); CloseHandle( ((prAthread)p)->hThread );
#endif #endif
rat_thread_terminated( (rAthread)p ); rat_thread_terminated( (prAthread)p );
#ifdef WIN32 #ifdef WIN32
return (DWORD)ret; return (DWORD)ret;
#else #else
@ -156,18 +156,18 @@ static void *_raThreadMainRedirector( void *p ){
/// ///
/// API Level /// API Level
/// ///
rAthread rathread_create( rAthreadProc entryPoint, void *param ){ prAthread rathread_create( rAthreadProc entryPoint, void *param ){
return rathread_createEx( entryPoint, param, (1<<23) /*8MB*/, RAT_PRIO_NORMAL ); return rathread_createEx( entryPoint, param, (1<<23) /*8MB*/, RAT_PRIO_NORMAL );
}//end: rathread_create() }//end: rathread_create()
rAthread rathread_createEx( rAthreadProc entryPoint, void *param, size_t szStack, RATHREAD_PRIO prio ){ prAthread rathread_createEx( rAthreadProc entryPoint, void *param, size_t szStack, RATHREAD_PRIO prio ){
#ifndef WIN32 #ifndef WIN32
pthread_attr_t attr; pthread_attr_t attr;
#endif #endif
size_t tmp; size_t tmp;
unsigned int i; unsigned int i;
rAthread handle = NULL; prAthread handle = NULL;
// given stacksize aligned to systems pagesize? // given stacksize aligned to systems pagesize?
@ -214,7 +214,7 @@ rAthread rathread_createEx( rAthreadProc entryPoint, void *param, size_t szSta
}//end: rathread_createEx }//end: rathread_createEx
void rathread_destroy ( rAthread handle ){ void rathread_destroy ( prAthread handle ){
#ifdef WIN32 #ifdef WIN32
if( TerminateThread(handle->hThread, 0) != FALSE){ if( TerminateThread(handle->hThread, 0) != FALSE){
CloseHandle(handle->hThread); CloseHandle(handle->hThread);
@ -233,9 +233,9 @@ void rathread_destroy ( rAthread handle ){
#endif #endif
}//end: rathread_destroy() }//end: rathread_destroy()
rAthread rathread_self( ){ prAthread rathread_self( ){
#ifdef HAS_TLS #ifdef HAS_TLS
rAthread handle = &l_threads[g_rathread_ID]; prAthread handle = &l_threads[g_rathread_ID];
if(handle->proc != NULL) // entry point set, so its used! if(handle->proc != NULL) // entry point set, so its used!
return handle; return handle;
@ -279,7 +279,7 @@ int rathread_get_tid(){
}//end: rathread_get_tid() }//end: rathread_get_tid()
bool rathread_wait( rAthread handle, void* *out_exitCode ){ bool rathread_wait( prAthread handle, void* *out_exitCode ){
// Hint: // Hint:
// no thread data cleanup routine call here! // no thread data cleanup routine call here!
@ -297,13 +297,13 @@ bool rathread_wait( rAthread handle, void* *out_exitCode ){
}//end: rathread_wait() }//end: rathread_wait()
void rathread_prio_set( rAthread handle, RATHREAD_PRIO prio ){ void rathread_prio_set( prAthread handle, RATHREAD_PRIO prio ){
handle->prio = RAT_PRIO_NORMAL; handle->prio = RAT_PRIO_NORMAL;
//@TODO //@TODO
}//end: rathread_prio_set() }//end: rathread_prio_set()
RATHREAD_PRIO rathread_prio_get( rAthread handle){ RATHREAD_PRIO rathread_prio_get( prAthread handle){
return handle->prio; return handle->prio;
}//end: rathread_prio_get() }//end: rathread_prio_get()

View File

@ -5,9 +5,13 @@
#ifndef _rA_THREAD_H_ #ifndef _rA_THREAD_H_
#define _rA_THREAD_H_ #define _rA_THREAD_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "cbasetypes.h" #include "cbasetypes.h"
typedef struct rAthread *rAthread; typedef struct rAthread *prAthread;
typedef void* (*rAthreadProc)(void*); typedef void* (*rAthreadProc)(void*);
typedef enum RATHREAD_PRIO { typedef enum RATHREAD_PRIO {
@ -25,7 +29,7 @@ typedef enum RATHREAD_PRIO {
* *
* @return not NULL if success * @return not NULL if success
*/ */
rAthread rathread_create( rAthreadProc entryPoint, void *param ); prAthread rathread_create( rAthreadProc entryPoint, void *param );
/** /**
@ -38,7 +42,7 @@ rAthread rathread_create( rAthreadProc entryPoint, void *param );
* *
* @return not NULL if success * @return not NULL if success
*/ */
rAthread rathread_createEx( rAthreadProc entryPoint, void *param, size_t szStack, RATHREAD_PRIO prio ); prAthread rathread_createEx( rAthreadProc entryPoint, void *param, size_t szStack, RATHREAD_PRIO prio );
/** /**
@ -48,7 +52,7 @@ rAthread rathread_createEx( rAthreadProc entryPoint, void *param, size_t szSta
* *
* @param handle - thread to destroy. * @param handle - thread to destroy.
*/ */
void rathread_destroy ( rAthread handle ); void rathread_destroy ( prAthread handle );
/** /**
@ -59,7 +63,7 @@ void rathread_destroy ( rAthread handle );
* *
* @return not NULL if success * @return not NULL if success
*/ */
rAthread rathread_self( ); prAthread rathread_self( );
/** /**
@ -81,7 +85,7 @@ int rathread_get_tid();
* *
* @return true - if the given thread has been terminated. * @return true - if the given thread has been terminated.
*/ */
bool rathread_wait( rAthread handle, void* *out_exitCode ); bool rathread_wait( prAthread handle, void* *out_exitCode );
/** /**
@ -90,7 +94,7 @@ bool rathread_wait( rAthread handle, void* *out_exitCode );
* @param handle - thread to set prio for * @param handle - thread to set prio for
* @param rio - the priority (RAT_PRIO_LOW ... ) * @param rio - the priority (RAT_PRIO_LOW ... )
*/ */
void rathread_prio_set( rAthread handle, RATHREAD_PRIO prio ); void rathread_prio_set( prAthread handle, RATHREAD_PRIO prio );
/** /**
@ -98,7 +102,7 @@ void rathread_prio_set( rAthread handle, RATHREAD_PRIO prio );
* *
* @param handle - the thread to get the prio for. * @param handle - the thread to get the prio for.
*/ */
RATHREAD_PRIO rathread_prio_get( rAthread handle); RATHREAD_PRIO rathread_prio_get( prAthread handle);
/** /**
@ -115,5 +119,8 @@ void rathread_yield();
void rathread_init(); void rathread_init();
void rathread_final(); void rathread_final();
#ifdef __cplusplus
}
#endif
#endif #endif

View File

@ -4,6 +4,10 @@
#ifndef _TIMER_H_ #ifndef _TIMER_H_
#define _TIMER_H_ #define _TIMER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "cbasetypes.h" #include "cbasetypes.h"
#include <time.h> #include <time.h>
@ -60,4 +64,8 @@ int do_timer(unsigned int tick);
void timer_init(void); void timer_init(void);
void timer_final(void); void timer_final(void);
#ifdef __cplusplus
}
#endif
#endif /* _TIMER_H_ */ #endif /* _TIMER_H_ */