See Here
See change log
Lib Name | Description |
---|---|
flist | Lockfree FIFO single-linked list in one-producer one-consumer scenario |
fdlist | Double-linked list |
fhash | Hash table |
flock | A wraper, which is safer and easier to use pthread condition |
flog | A High Performance Logging Library |
fmbuf | A light-weight ring-buffer |
fconf | A simple configuration file library |
ftime | Easy to create system timer |
fthread_pool | Simple thread pool, which is easy to use |
fnet | Wrap the system APIs, easy to use the networking api |
fev | Event framework, including buffer, networking, timer service... |
fcache | A simple cache with LRU |
fco | C coroutine. Notes: Legacy library, use it carefully |
C Unit test framework. Notes: Migrated to fcunit | |
Thread-Cache memory pool. Notes: Migrated to skull-malloc | |
Pcap file conversion library. Notes: Migrated to fpcap |
See Wiki
git clone [email protected]:finaldie/final_libs.git flibs
cd flibs
git submodule update --init --recursive
make
make check
make valgrind-check
make bench
make bench-run
- Change the compiler, such as using clang:
make CC=clang
- Build shared library instead of static library:
make SHARED=true
- Build debug version without any optimization parameters
make debug=true
- Build
32
bit libraries under64
bit platform
make BIT=32
- Build in parallel
make -j4 # Adjust the number '4' according to the real cpu cores to speed up
the compile time
- Skip building legacy library
Currently,
fco
is defined as a legacy library, maybe it won't working well or lose support in some archs, use a specify macro to skip building it.
make FLIB_CFLAGS=-DFLIB_SKIP_LEGACY
- Custom CFLAGS and LDFLAGS
Sometimes, we want to define some different macros/compilation flags to control
compiling/linking results, in flibs, instead of standard
CFLAGS
andLDFLAGS
, we can useFLIB_CFLAGS
andFLIB_LDFLAGS
- Build 64bit static-link libraries
make -j4 && make -j4 check
- Build 64bit dynamic-link libraries
make SHARED=true -j4 && make SHARED=true check
- Install flibs to system
After compilation, just call
install
target, to install flibs into system:
make install
notes: By default, the flibs will be installed in /usr/local/:
- Headers in:
/usr/local/include
- Libraries in:
/usr/local/lib
If we want to change the location, maybe to/usr/
, just run:
make prefix=/usr/ install
After installing flibs into system, basically we need few steps to use it:
- Include the headers from the source file
- Link the statis/dynamic library from the Makefile
Let's see an example Source file and Makefile, e.g. fhash:
// main.c
#include <stdlib.h>
#include <stdio.h>
#include <flibs/fhash.h>
int main(int argc, char** argv)
{
// 1. Create string hash table
fhash* tbl = fhash_str_create(0, FHASH_MASK_AUTO_REHASH);
// 2. Set a key-value into table
const char* key = "hello";
fhash_str_set(tbl, key, "world");
// 3. Get the value from table
const char* value = fhash_str_get(tbl, key);
printf("Key: %s, value: %s\n", key, value);
// 4. Destroy the hash table
fhash_str_delete(tbl);
return 0;
}
# Makefile
all:
gcc -Wall -g -O2 -o demo main.c -lflibs
Then Build and Run it:
final@ubuntu1404: ~/code/github/flibs/demo>make
gcc -Wall -g -O2 -o demo main.c -lflibs
final@ubuntu1404: ~/code/github/flibs/demo>./demo
Key: hello, value: world
Have fun :)