summaryrefslogtreecommitdiff
path: root/src/rt/rt_string.h
blob: f37b3683f3ee50b45e0d443cd77971bea4dd3500 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#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

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)))

static inline void atomic_set(atomic_t *v, int32_t val)
{
    v->counter = val;
}
#endif