forked from vieter-v/libvieter
Compare commits
No commits in common. "5b2ce6acaa6cb9cc559eb9618be1eabda2e12356" and "ab418e57b3d3ae989e7196056487b7f6634a677b" have entirely different histories.
5b2ce6acaa
...
ab418e57b3
11
Makefile
11
Makefile
|
|
@ -8,8 +8,6 @@ SRC_DIR ?= src
|
||||||
TEST_DIR ?= test
|
TEST_DIR ?= test
|
||||||
INC_DIRS ?= include
|
INC_DIRS ?= include
|
||||||
|
|
||||||
LIB := $(BUILD_DIR)/$(LIB_FILENAME)
|
|
||||||
|
|
||||||
SRCS != find '$(SRC_DIR)' -iname '*.c'
|
SRCS != find '$(SRC_DIR)' -iname '*.c'
|
||||||
SRCS_H != find $(INC_DIRS) -iname '*.h'
|
SRCS_H != find $(INC_DIRS) -iname '*.h'
|
||||||
SRCS_TEST != find '$(TEST_DIR)' -iname '*.c'
|
SRCS_TEST != find '$(TEST_DIR)' -iname '*.c'
|
||||||
|
|
@ -42,7 +40,7 @@ all: vieter
|
||||||
objs: $(OBJS)
|
objs: $(OBJS)
|
||||||
|
|
||||||
.PHONY: vieter
|
.PHONY: vieter
|
||||||
vieter: $(LIB)
|
vieter: $(BUILD_DIR)/$(LIB_FILENAME)
|
||||||
$(BUILD_DIR)/$(LIB_FILENAME): $(OBJS)
|
$(BUILD_DIR)/$(LIB_FILENAME): $(OBJS)
|
||||||
ar -rcs $@ $(OBJS)
|
ar -rcs $@ $(OBJS)
|
||||||
|
|
||||||
|
|
@ -71,11 +69,10 @@ build-test: $(BINS_TEST)
|
||||||
|
|
||||||
# For simplicity, we link every object file to each of the test files. This
|
# For simplicity, we link every object file to each of the test files. This
|
||||||
# might be changed later if this starts to become too slow.
|
# might be changed later if this starts to become too slow.
|
||||||
$(BINS_TEST): %: %.c.o $(LIB)
|
$(BINS_TEST): %: %.c.o $(OBJS)
|
||||||
$(CC) \
|
$(CC) $^ -o $@
|
||||||
$^ -o $@
|
|
||||||
|
|
||||||
# Along with the include directory, each test includes $(TEST_DIR) (which
|
# Allow with the include directory, each test includes $(TEST_DIR) (which
|
||||||
# contains the acutest.h header file), and the src directory of the module it's
|
# contains the acutest.h header file), and the src directory of the module it's
|
||||||
# testing. This allows tests to access internal methods, which aren't publicly
|
# testing. This allows tests to access internal methods, which aren't publicly
|
||||||
# exposed.
|
# exposed.
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ be implemented in C (or just parts I want to implement in C because it's fun).
|
||||||
The goal of this library is to be as self-contained as possible; data
|
The goal of this library is to be as self-contained as possible; data
|
||||||
structures should be implemented manually if possible.
|
structures should be implemented manually if possible.
|
||||||
|
|
||||||
See the [source code](src) for the list of modules.
|
See the [source code](/src) for the list of modules.
|
||||||
|
|
||||||
## Development
|
## Development
|
||||||
|
|
||||||
|
|
@ -43,7 +43,7 @@ only used in a .c file, the import should be placed in the .c file instead.
|
||||||
|
|
||||||
This library uses [Acutest](https://github.com/mity/acutest) for its tests.
|
This library uses [Acutest](https://github.com/mity/acutest) for its tests.
|
||||||
Tests should be placed in the `test` subdirectory, further divided into
|
Tests should be placed in the `test` subdirectory, further divided into
|
||||||
directories that correspond to those in `src`. Test files should begin with
|
directories that correspond those in `src`. Test files should begin with
|
||||||
`test_`, and their format should follow the expected format for Acutest.
|
`test_`, and their format should follow the expected format for Acutest.
|
||||||
|
|
||||||
Each `test_` is compiled separately into a binary, linked with libvieter. A
|
Each `test_` is compiled separately into a binary, linked with libvieter. A
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ typedef struct vieter_cron_simple_time {
|
||||||
/*
|
/*
|
||||||
* Allocate and initialize a new empty cron expression.
|
* Allocate and initialize a new empty cron expression.
|
||||||
*/
|
*/
|
||||||
vieter_cron_expression *vieter_cron_expr_init();
|
vieter_cron_expression *ce_init();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Deallocate a cron expression.
|
* Deallocate a cron expression.
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ typedef enum vieter_heap_error {
|
||||||
} vieter_heap_error;
|
} vieter_heap_error;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate and initialize an empty heap.
|
* Allocate and initalize an empty heap.
|
||||||
*/
|
*/
|
||||||
vieter_heap *vieter_heap_init();
|
vieter_heap *vieter_heap_init();
|
||||||
|
|
||||||
|
|
@ -41,22 +41,4 @@ vieter_heap_error vieter_heap_pop(void **out, vieter_heap *heap);
|
||||||
*/
|
*/
|
||||||
vieter_heap_error vieter_heap_peek(void **out, vieter_heap *heap);
|
vieter_heap_error vieter_heap_peek(void **out, vieter_heap *heap);
|
||||||
|
|
||||||
/*
|
|
||||||
* Acquire a read lock on the heap. Return value is the result of
|
|
||||||
* pthread_rwlock_rdlock.
|
|
||||||
*/
|
|
||||||
int vieter_heap_rlock(vieter_heap *heap);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Acquire a write lock on the heap. Return value is the result of
|
|
||||||
* pthread_rwlock_wrlock.
|
|
||||||
*/
|
|
||||||
int vieter_heap_wlock(vieter_heap *heap);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Unlock the lock after having acquired it. Return value is the result of
|
|
||||||
* pthread_rwlock_unlock.
|
|
||||||
*/
|
|
||||||
int vieter_heap_unlock(vieter_heap *heap);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -2,13 +2,7 @@
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
vieter_heap *vieter_heap_init() {
|
vieter_heap *vieter_heap_init() { return calloc(1, sizeof(vieter_heap)); }
|
||||||
vieter_heap *heap = calloc(1, sizeof(vieter_heap));
|
|
||||||
|
|
||||||
pthread_rwlock_init(&heap->lock, NULL);
|
|
||||||
|
|
||||||
return heap;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint64_t vieter_heap_size(vieter_heap *heap) {
|
uint64_t vieter_heap_size(vieter_heap *heap) {
|
||||||
uint64_t size = 0;
|
uint64_t size = 0;
|
||||||
|
|
@ -82,15 +76,3 @@ vieter_heap_error vieter_heap_peek(void **out, vieter_heap *heap) {
|
||||||
|
|
||||||
return vieter_heap_ok;
|
return vieter_heap_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
int vieter_heap_rlock(vieter_heap *heap) {
|
|
||||||
return pthread_rwlock_rdlock(&heap->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
int vieter_heap_wlock(vieter_heap *heap) {
|
|
||||||
return pthread_rwlock_wrlock(&heap->lock);
|
|
||||||
}
|
|
||||||
|
|
||||||
int vieter_heap_unlock(vieter_heap *heap) {
|
|
||||||
return pthread_rwlock_unlock(&heap->lock);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,6 @@
|
||||||
#include "vieter_heap.h"
|
#include "vieter_heap.h"
|
||||||
#include "vieter_heap_tree.h"
|
#include "vieter_heap_tree.h"
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
struct vieter_heap {
|
struct vieter_heap {
|
||||||
vieter_heap_node *tree;
|
vieter_heap_node *tree;
|
||||||
pthread_rwlock_t lock;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ typedef struct vieter_heap_node {
|
||||||
} vieter_heap_node;
|
} vieter_heap_node;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate and initialize a heap node object.
|
* Allocate an initialize a heap node object.
|
||||||
*/
|
*/
|
||||||
vieter_heap_node *vieter_heap_node_init();
|
vieter_heap_node *vieter_heap_node_init();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue