-
Notifications
You must be signed in to change notification settings - Fork 29
MLPL
A library of commonly used functions.
- Some functions available on Linux are typically C-style such as sem_wait(), sprintf() etc. By Wrapping them with C++'s features we can make code simple. For example, explicit initialization or free can be automated by a constructor and a destructor.
-
AtomicValue: Atomic operation
-
get(), set(), add(), sub(), etc.
-
internally uses gcc's builtin functions such as __sync_fetch_and_add().
-
We can use instances as if they are native type by operator's overload.
AtomicValue<int> a, b;
a = 1;
b = a;
-
-
EventSemaphore
- A semaphore using EventFd (A feature of Linux)
- We can wait for a semaphore with GLibEvent Loop based on poll().
-
Logger
-
MLPL_X() (X: DBG, INFO, WARN, ERR, CRIT, BUG) writes a message both to stderr and syslog.
MLPL_INFO ("My name: %s, Age: %d\n", name, age);
-
-
MutexLock
- lock(), unlock(), and timedlock().
-
ParsableString
- We can parse a string from the top with specifying a separator.
-
ReadWriteLock
- readLock(), writeLock(), and unlock()
-
Reaper
-
An auto pointer helper.
-
deletes an object or a buffer at the end of the block.
-
works even when an exception is thrown.
MutexLock lock;
Reaper unlocker(&lock, MutexLock::unlock);char *buf = malloc(100);
Reaper<char *> reaper(buf, free);
-
-
SmartTime: holds time (sec and nanosec)
- Constructor(INIT_CURR_TIME)
- Constructor(const timespec &ts)
- Comparators: <, >, <=, >=, ==
- Add/Sub: +=, -=
-
StringUtils
- sprintf()