Skip to content

Instantly share code, notes, and snippets.

View psqli's full-sized avatar

Ricardo Biehl Pasquali psqli

  • Campo Bom, Brazil
  • 22:43 (UTC -03:00)
  • X @psqli
View GitHub Profile
@psqli
psqli / vmutex
Last active September 15, 2016 16:56
increment based mutex
/* We have two sides which can lock our vmutexes:
* 1st side uses acquire/release functions and it can only hold mutex when
* `counter` is zero. If counter is not zero `acquire` waits.
* 2nd side uses increment/decrement functions and when it holds mutex it
* increments `counter`. This side can't hold mutex while 1st side is already
* holding it.
*/
#include <pthread.h>
#include <stdlib.h>
@psqli
psqli / cfg_file_parser.c
Created May 4, 2017 17:48
simple configuration file parser
parse_line(char *line)
{
int i;
char *key;
char *value;
for (i = 0; line[i] != '\0'; i++) {
if (line[i] == ' ') {
/* jump spaces */
while (line[i] == ' ')