Skip to content

majianzheng/simple-cpp-middleware

Folders and files

NameName
Last commit message
Last commit date

Latest commit

344e2af · Jun 11, 2021

History

1 Commit
Jun 11, 2021
Jun 11, 2021
Jun 11, 2021
Jun 11, 2021
Jun 11, 2021
Jun 11, 2021

Repository files navigation

simple c++ middleware

As it's name, it's a light simple middleware library for c++ developers without any third library, and only for Linux and MacOS based raw OS kernal clang API and asm.

  • Memory pool
  • Lock based AQS
  • Blocking queue
  • Thread pool
  • High performance share memory management(todo).

Backgroud

When we want to develop a small system, properly need depend on some third big library even if we only use a litle part of it.

Building and test

Clean the old target. Use make clean command:

[root@localhost simple-cpp-middleware]# make clean
cleaned up.

How to build it. Execute Makefile make command to build the library as:

[root@localhost simple-cpp-middleware]# make
start build...
build success!

Test it use the make test command like:

[root@localhost simple-cpp-middleware]# make test
start build the test source code...
build test code success! start execute test...
test proccess is ready, start test>>>
...
...
test result output
...
...
test is over, press [Enter] to finish.

test finished!

And also you can use group command once like make clean all test.

[root@localhost simple-cpp-middleware]# make clean all test
cleaned up.
start build...
build success!
start build the test source code...
build test code success! start execute test...
test proccess is ready, start test>>>
...
...
test result output
...
...
test is over, press [Enter] to finish.

test finished!

API document

Memory pool include the memory_pool.h

file: demo.c

#include "memory_pool.h"

int main(int argc, char const *argv[]) {
    //At first alloc 10M space from system to init memory pool
    mem_init(1024 * 1024 * 10);

    //Malloc some memory from memory pool
    void * buffer = mem_malloc(1024);

    //Use the memory do something
    const char* data = "some data...";
    memcpy(buffer, data, strlen(data));

    //At last release the memory
    mem_free(buffer);

    return 0;
}

Lock and thread usage

#include "ReentrantLock.h"
#include "Thread.h"

int main(int argc, char const *argv[]) {
    //At first init a Lock instance.
    ReentrantLock lock;

    //Ant start a thread

    return 0;
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published