summaryrefslogtreecommitdiff
path: root/src/rt
diff options
context:
space:
mode:
Diffstat (limited to 'src/rt')
-rw-r--r--src/rt/rt.mk42
-rw-r--r--src/rt/rt_common.h19
-rw-r--r--src/rt/rt_file.c32
-rw-r--r--src/rt/rt_file.h7
-rw-r--r--src/rt/rt_stdlib.c29
-rw-r--r--src/rt/rt_stdlib.h15
-rw-r--r--src/rt/rt_string.c35
-rw-r--r--src/rt/rt_string.h74
-rw-r--r--src/rt/rt_sync.h20
-rw-r--r--src/rt/rt_time.c58
-rw-r--r--src/rt/rt_time.h12
-rw-r--r--src/rt/rt_tmr.c212
-rw-r--r--src/rt/rt_tmr.h25
13 files changed, 0 insertions, 580 deletions
diff --git a/src/rt/rt.mk b/src/rt/rt.mk
deleted file mode 100644
index 36480c8..0000000
--- a/src/rt/rt.mk
+++ /dev/null
@@ -1,42 +0,0 @@
-
-
-# standard component Makefile header
-sp := $(sp).x
-dirstack_$(sp) := $(d)
-d := $(dir)
-
-# component specification
-
-OBJS_$(d) :=\
- $(OBJ_DIR)/rt_file.o\
- $(OBJ_DIR)/rt_stdlib.o\
- $(OBJ_DIR)/rt_string.o\
- $(OBJ_DIR)/rt_tmr.o\
- $(OBJ_DIR)/rt_time.o
-
-CFLAGS_LOCAL += -I$(d)
-$(OBJS_$(d)): CFLAGS_LOCAL := -std=gnu99 -W -Wall -Wunused-parameter -g -O3 \
- -I$(d)\
-
-
-# standard component Makefile rules
-
-DEPS_$(d) := $(OBJS_$(d):.o=.d)
-
-#LIBS_LIST := $(LIBS_LIST) $(LIBRARY)
-LIBS_LIST := $(LIBS_LIST)
-
-CLEAN_LIST := $(CLEAN_LIST) $(OBJS_$(d)) $(DEPS_$(d))
-
--include $(DEPS_$(d))
-
-#$(LIBRARY): $(OBJS)
-# $(MYARCHIVE)
-
-$(OBJ_DIR)/%.o: $(d)/%.c
- $(COMPILE)
-
-# standard component Makefile footer
-
-d := $(dirstack_$(sp))
-sp := $(basename $(sp))
diff --git a/src/rt/rt_common.h b/src/rt/rt_common.h
deleted file mode 100644
index 058c43e..0000000
--- a/src/rt/rt_common.h
+++ /dev/null
@@ -1,19 +0,0 @@
-#ifndef __RT_COMMON_H__
-#define __RT_COMMON_H__
-
-#include <assert.h>
-#define EVAL_TM_STYLE "%Y-%m-%d"
-
-/** Alway treated the expr as true */
-#ifndef likely
-#define likely(expr) __builtin_expect(!!(expr), 1)
-#endif
-
-/** Alway treated the expr as false */
-#ifndef unlikely
-#define unlikely(expr) __builtin_expect(!!(expr), 0)
-#endif
-
-#define __rt_always_inline__ __attribute__((always_inline)) inline
-
-#endif
diff --git a/src/rt/rt_file.c b/src/rt/rt_file.c
deleted file mode 100644
index 1b3746e..0000000
--- a/src/rt/rt_file.c
+++ /dev/null
@@ -1,32 +0,0 @@
-#include <stdio.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <dirent.h>
-
-#include "rt_common.h"
-
-int rt_file_exsit(const char *realpath_file)
-{
- return (!access(realpath_file, F_OK));
-}
-
-int rt_dir_exsit (const char *realpath)
-{
- DIR *dir = NULL;
- int exsit = 0;
-
- if (unlikely (!realpath))
- goto finish;
-
- dir = opendir(realpath);
- if (!dir) goto finish;
-
- exsit = 1;
- closedir(dir);
-finish:
- return exsit;
-}
-
diff --git a/src/rt/rt_file.h b/src/rt/rt_file.h
deleted file mode 100644
index 66563ac..0000000
--- a/src/rt/rt_file.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef __RT_FILE_H__
-#define __RT_FILE_H__
-
-extern int rt_file_exsit(const char *);
-extern int rt_dir_exsit (const char *realpath);
-
-#endif
diff --git a/src/rt/rt_stdlib.c b/src/rt/rt_stdlib.c
deleted file mode 100644
index a4d6b58..0000000
--- a/src/rt/rt_stdlib.c
+++ /dev/null
@@ -1,29 +0,0 @@
-
-#include <stdlib.h>
-#include <string.h>
-#include "rt_common.h"
-#include "rt_stdlib.h"
-
-void *kmalloc(int s,
- int flags,
- int __attribute__((__unused__)) node)
-{
- void *p;
-
- if(likely((p = malloc(s)) != NULL)){
- if(flags & MPF_CLR)
- memset(p, 0, s);
- }
-
- return p;
-}
-
-void kfree(void *p)
-{
- if(likely(p != NULL)){
- free(p);
- }
-
- p = NULL;
-}
-
diff --git a/src/rt/rt_stdlib.h b/src/rt/rt_stdlib.h
deleted file mode 100644
index a8cc1ec..0000000
--- a/src/rt/rt_stdlib.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef __RT_STDLIB_H__
-#define __RT_STDLIB_H__
-
-#include <stdlib.h>
-
-/** memory flags */
-#define MPF_CLR (1 << 0) /** Clear it after allocated */
-
-extern void kfree(void *p);
-
-void *kmalloc(int s, int flags, int __attribute__((__unused__)) node);
-
-
-#endif
-
diff --git a/src/rt/rt_string.c b/src/rt/rt_string.c
deleted file mode 100644
index bb2ef4c..0000000
--- a/src/rt/rt_string.c
+++ /dev/null
@@ -1,35 +0,0 @@
-#include <stdint.h>
-#include <string.h>
-#include "rt_string.h"
-
-const char *
-try_val_to_str_idx(const unsigned int val, const struct value_string *vs, int *idx)
-{
- int i = 0;
- if (idx == NULL){
- goto finish;
- }
-
- if(vs) {
- while (vs[i].strptr) {
- if (vs[i].value == val) {
- *idx = i;
- return(vs[i].strptr);
- }
- i++;
- }
- }
-
-finish:
- *idx = -1;
- return NULL;
-}
-
-const char*
-val_to_str(const unsigned int val, const struct value_string *vs)
-{
- int ignore_me;
-
- return try_val_to_str_idx(val, vs, &ignore_me);
-}
-
diff --git a/src/rt/rt_string.h b/src/rt/rt_string.h
deleted file mode 100644
index c183db5..0000000
--- a/src/rt/rt_string.h
+++ /dev/null
@@ -1,74 +0,0 @@
-#ifndef __UTIL_STRING_H__
-#define __UTIL_STRING_H__
-
-#include <string.h>
-#include <stdio.h>
-#include <stdint.h>
-
-#ifndef STRLEN
-#define STRLEN(STR) ((int)strlen((const char *)STR))
-#endif
-
-#ifndef ISALNUM
-#define ISALNUM(S) (isalnum((const char)S))
-#endif
-
-#ifndef STRCMP
-#define STRCMP(S,D) (strcmp((const char *)S, (const char *)D))
-#endif
-
-#ifndef STRSTR
-#define STRSTR(D,S) (strstr((const char *)D,(const char *)S))
-#endif
-
-#ifndef STRNCMP
-#define STRNCMP(S,D,L) (strncmp((const char *)S, (const char *)D, L))
-#endif
-
-#ifndef STRCAT
-#define STRCAT(D,S) (strcat((char *)D, (const char *)S))
-#endif
-
-#ifndef FOREVER
-#define FOREVER for(;;)
-#endif
-
-#ifndef MIN
-#define MIN(a, b) (((a) < (b)) ? (a) : (b))
-#endif
-
-typedef struct atomic {
- volatile int counter;
-} atomic_t;
-
-struct value_string {
- unsigned int value;
- const char *strptr;
-};
-
-extern const char*
-val_to_str(const unsigned int val, const struct value_string *vs);
-
-typedef struct{
-#define ATOMIC64_SIZE sizeof(long long)
- int64_t counter;
-}atomic64_t;
-
-#define ATOMIC_INIT(i) { (i) }
-
-#define atomic_read(v) (*(volatile int *)&(v)->counter)
-#define atomic64_read(v) (*(volatile int64_t *)&(v)->counter)
-
-#define atomic_add(x, y) (__sync_add_and_fetch((&(((atomic_t *)x)->counter)), (y)))
-#define atomic64_add(x, y) (__sync_add_and_fetch((&(((atomic64_t *)x)->counter)), (y)))
-#define atomic64_sub(x, y) (__sync_sub_and_fetch((&(((atomic64_t *)x)->counter)), (y)))
-
-#define atomic64_inc(x) (atomic64_add((x), 1))
-#define atomic64_dec(x) (atomic64_sub((x), 1))
-
-static inline void atomic64_set(atomic64_t *v, int64_t val)
-{
- v->counter = val;
-}
-
-#endif
diff --git a/src/rt/rt_sync.h b/src/rt/rt_sync.h
deleted file mode 100644
index b8fc272..0000000
--- a/src/rt/rt_sync.h
+++ /dev/null
@@ -1,20 +0,0 @@
-#ifndef __SYSTEM_SYNC_H__
-#define __SYSTEM_SYNC_H__
-
-#include <pthread.h>
-
-#define rt_pthread_attr pthread_attr_t
-#define rt_pthread pthread_t
-#define rt_mutex pthread_mutex_t
-#define rt_mutex_attr pthread_mutexattr_t
-#define rt_mutex_init(mut, mutattr ) pthread_mutex_init(mut, mutattr)
-#define rt_mutex_lock(mut) pthread_mutex_lock(mut)
-#define rt_mutex_trylock(mut) pthread_mutex_trylock(mut)
-#define rt_mutex_unlock(mut) pthread_mutex_unlock(mut)
-#define rt_mutex_destroy(mut) pthread_mutex_destroy(mut)
-
-#define INIT_MUTEX(name)\
- rt_mutex name = PTHREAD_MUTEX_INITIALIZER;
-
-#endif
-
diff --git a/src/rt/rt_time.c b/src/rt/rt_time.c
deleted file mode 100644
index feef593..0000000
--- a/src/rt/rt_time.c
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
-* rt_time.c
-* Created by fengweihao
-* 30 May, 2018
-* Func: Time Component
-*/
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/time.h>
-#include <time.h>
-#include <assert.h>
-#include <errno.h>
-
-#include "rt_time.h"
-
-struct tm *rt_localtime(time_t timep, struct tm *result)
-{
- return localtime_r(&timep, result);
-}
-
-uint64_t rt_time_s(void)
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (tv.tv_sec + tv.tv_usec/1000/1000); /** CST timestamp */
-};
-
-uint64_t rt_time_ms(void)
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (tv.tv_sec * 1000 + tv.tv_usec/1000);
-}
-
-uint64_t rt_time_ns()
-{
- struct timeval tv;
- gettimeofday(&tv, NULL);
- return (tv.tv_sec * 1000 * 1000 + tv.tv_usec);
-}
-
-int rt_tms2str(uint64_t ts, const char *tm_form, char *date, size_t len)
-{
- struct tm *tm = NULL;
-
- assert(date);
- /** Convert ts to localtime with local time-zone */
- tm = localtime((time_t *)&ts);
- return (int)strftime(date, len - 1, tm_form, tm);
-}
-
-int rt_curr_tms2str(const char *tm_form, char *date, size_t len)
-{
- return rt_tms2str(time(NULL), tm_form, date, len);
-}
-
diff --git a/src/rt/rt_time.h b/src/rt/rt_time.h
deleted file mode 100644
index ea3ec1c..0000000
--- a/src/rt/rt_time.h
+++ /dev/null
@@ -1,12 +0,0 @@
-#ifndef __RT_TM_H__
-#define __RT_TM_H__
-
-struct tm *rt_localtime(time_t timep, struct tm *result);
-int rt_tms2str(uint64_t ts, const char *tm_form, char *date, size_t len);
-int rt_curr_tms2str(const char *tm_form, char *date, size_t len);
-
-u_int64_t rt_time_s(void);
-u_int64_t rt_time_ms(void);
-u_int64_t rt_time_ns();
-
-#endif
diff --git a/src/rt/rt_tmr.c b/src/rt/rt_tmr.c
deleted file mode 100644
index e47a5e2..0000000
--- a/src/rt/rt_tmr.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/*************************************************************************
- > File Name: rt_tmr.c
- > Author:
- > Mail:
- > Created Time: 2018年09月19日 星期三 15时57分58秒
- ************************************************************************/
-
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <unistd.h>
-#include <assert.h>
-#include <sys/time.h>
-#include <stdint.h>
-#include <signal.h>
-
-#include "rt_stdlib.h"
-#include "rt_sync.h"
-#include "rt_string.h"
-#include "rt_common.h"
-
-static int init;
-
-enum {
- ALLOWED,
- FORBIDDEN
-};
-
-struct tmr_task{
- rt_pthread pid;
-
- rt_pthread_attr *attr;
-
- void * (*routine)(void *);
-};
-
-struct timer_t{
-
-#define TMR_INVALID -1
-
- int module;
-
- /** unique id */
- uint32_t uid;
-
- /** Make sure that allocate desc member with malloc like function. */
- char *desc;
-
- /** in ms */
- int64_t interval;
-
- int64_t curr_ticks;
-
- enum {TMR_PERIODIC, TMR_ASHOT} type;
-
- enum {TMR_STOPPED, TMR_STARTED} status;
-
- void (*routine)(uint32_t uid, int argc, char **argv);
-
- int argc;
-
- char **argv;
-
- int recycle;
-};
-
-struct timer_t *_this;
-
-static volatile atomic64_t g_sys_cur_ticks = ATOMIC_INIT(0);
-
-struct timer_t *
-tmr_set(uint32_t uid,
- void (*proc)(struct timer_t *t))
-{
- uid = uid;
-
- if(likely(proc))
- proc(_this);
-
- return _this;
-}
-
-static void tmr_enable(struct timer_t *t)
-{
- t->status = TMR_STARTED;
-}
-
-static void tmr_disable(struct timer_t *t)
-{
- t->status = TMR_STOPPED;
-}
-
-void tmr_start(uint32_t uid)
-{
- tmr_set(uid, tmr_enable);
-}
-
-void tmr_stop(uint32_t uid)
-{
- tmr_set(uid, tmr_disable);
-}
-
-static void tmr_handler()
-{
- int64_t old_ticks = 0;
-
- old_ticks = atomic64_add(&g_sys_cur_ticks, 1);
- if (likely(_this->status == TMR_STARTED)){
- if (likely(old_ticks >= _this->curr_ticks)) {
- _this->routine(_this->uid, _this->argc, _this->argv);
- if (likely(TMR_ASHOT == _this->type))
- _this->status= TMR_STOPPED;
- else
- _this->curr_ticks = old_ticks + _this->interval;
- }
- }
-}
-
-static void realtimer_init()
-{
- static struct itimerval tmr;
-
- signal(SIGALRM, (void *) tmr_handler);
- tmr.it_interval.tv_sec = 1;
- tmr.it_interval.tv_usec = 0;
- tmr.it_value.tv_sec = 1;
- tmr.it_value.tv_usec = 0;
- setitimer(ITIMER_REAL, &tmr, NULL);
-
-}
-
-static void
-tmr_default_routine(uint32_t uid, int __attribute__((__unused__))argc,
- char __attribute__((__unused__))**argv)
-{
- static int count[2] = {0};
-
- count[uid%2] ++;
- printf ("default timer [%u, %d] routine has occured\n", uid, count[uid%2]);
-}
-
-static __rt_always_inline__ void *
-tmr_alloc()
-{
- struct timer_t *t;
-
- t = kmalloc(sizeof(struct timer_t), MPF_CLR, -1);
- if(likely(t)){
- t->uid = TMR_INVALID;
- t->routine = tmr_default_routine;
- t->interval = 3; //tmr_internal_trans(3);
- t->recycle = ALLOWED;
- t->type = TMR_ASHOT;
- t->status = TMR_STOPPED;
- }
- return t;
-}
-
-static void *
-tmr_daemon(void __attribute__((__unused__))*pv_par )
-{
- FOREVER{
- sleep(86400);
- }
- return NULL;
-}
-
-uint32_t tmr_create(int module,
- const char *desc,
- void (*routine)(uint32_t, int, char **), int argc, char **argv, int sec)
-{
- uint32_t uid = -1;
-
- if(unlikely(!desc)){
- goto finish;
- }
-
- _this = (struct timer_t *)tmr_alloc();
- if(unlikely(!_this)){
- goto finish;
- }
-
- _this->module = module;
- _this->desc = strdup(desc);
- _this->curr_ticks = 0;
- _this->interval = sec;
- _this->routine = routine ? routine : tmr_default_routine;
- _this->type = TMR_PERIODIC;
- _this->uid = uid = 1;
- _this->recycle = ALLOWED;
- _this->status = TMR_STOPPED;
- _this->argc = argc;
- _this->argv = argv;
-
- if(likely(init == 0)){
- struct tmr_task *task = (struct tmr_task*)kmalloc(sizeof(struct tmr_task), MPF_CLR, -1);
- if (likely(task)){
- if (pthread_create(&task->pid, task->attr, tmr_daemon, NULL)){
- goto finish;
- }
- if (pthread_detach(task->pid)){
- goto finish;
- }
- }
- init = 1;
- realtimer_init();
- }
-
-finish:
- return uid;
-}
-
diff --git a/src/rt/rt_tmr.h b/src/rt/rt_tmr.h
deleted file mode 100644
index 3368f79..0000000
--- a/src/rt/rt_tmr.h
+++ /dev/null
@@ -1,25 +0,0 @@
-/*************************************************************************
- > File Name: rt_tmr.h
- > Author:
- > Mail:
- > Created Time: 2018年09月19日 星期三 15时58分04秒
- ************************************************************************/
-
-#ifndef _RT_TMR_H
-#define _RT_TMR_H
-
-#define RT_TMR_ADVANCED
-
-extern void tmr_start(uint32_t uid);
-extern void tmr_stop(uint32_t uid);
-
-/**
-* routine: must be a reentrant function.
-* An unknown error ocurrs if a thread-safe function called as a routione.
-*/
-extern uint32_t tmr_create(int module,
- const char *desc,
- void (*routine)(uint32_t, int, char **), int argc, char **argv, int sec);
-
-#endif
-