Permalink
Browse files

Merge branch 'master' of git://github.com/lexszero/jitsynth

  • Loading branch information...
2 parents 8d4e047 + b854a73 commit f7026da956aa9236b797a0af14bb26b82a39f6f5 @qrick committed Nov 23, 2011
Showing with 84 additions and 105 deletions.
  1. +1 −15 Makefile
  2. +2 −1 function.c
  3. +75 −86 generic_list.h
  4. +2 −1 player.h
  5. +2 −1 track.h
  6. +2 −1 xface.h
View
@@ -1,6 +1,5 @@
TARGET = synth
SRC = synth.c player.c function.o track.c util.c xface.c
-GENSRC = funclist.h tracklist.h plist.h keylist.h
CFLAGS += -O0 -ggdb -Wall -Wextra -std=c99 -MD -MP -MF .dep/$(@F).d
LDFLAGS += -lm -ljit -lxcb -lX11 -lX11-xcb
@@ -11,7 +10,7 @@ function_test: function_test.c function.o util.o
CC = gcc
COBJ = $(SRC:.c=.o)
-$(COBJ): %.o : %.c $(GENSRC)
+$(COBJ): %.o : %.c
$(CC) -c $(CFLAGS) $< -o $@
.SECONDARY: $(TARGET)
@@ -20,19 +19,6 @@ $(TARGET): $(COBJ)
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
-funclist.h: generic_list.h
- sed "s/NAME/funclist/g; s/TYPE/function_t/g" generic_list.h > funclist.h
-
-tracklist.h: generic_list.h
- sed "s/NAME/tracklist/g; s/TYPE/track_t/g" generic_list.h > tracklist.h
-
-plist.h: generic_list.h
- sed "s/NAME/plist/g; s/TYPE/playing_t/g" generic_list.h > plist.h
-
-keylist.h: generic_list.h
- sed "s/NAME/keylist/g; s/TYPE/keydown_t/g" generic_list.h > keylist.h
-
-
.PHONY: clean
clean:
View
@@ -1,7 +1,8 @@
#include "common.h"
#include "function.h"
-#include "funclist.h"
+#include "generic_list.h"
+LIST(funclist, function_t);
funclist_t *funclist;
jit_context_t jit_context;
View
@@ -1,99 +1,88 @@
#ifndef ADT_LIST
#define ADT_LIST
-#define list_new(type) type##_new();
+#define list_new(type) type##_new()
#define list_add_head(type, name, data) type##_add_head(name, data)
#define list_add_tail(type, name, data) type##_add_tail(name, data)
#define list_delete(type, name, item) type##_delete(name, item)
#define list_foreach(name, item) for (item = name->head; item; item = item->next)
#define list_foreach_safe(name, item, nextitem, func) for (item = name->head; item; item = nextitem) { nextitem = item->next; func; }
#define list_free(type, name) type##_free(name)
-#endif
#define _unused __attribute__((unused))
-
-typedef struct NAMEitem_t {
- TYPE data;
- struct NAMEitem_t *next, *prev;
-} NAMEitem_t;
-
-typedef struct NAME_t {
- pthread_mutex_t mutex;
- NAMEitem_t *head, *tail;
-} NAME_t;
-
-static _unused NAME_t * NAME_new() {
- NAME_t *t = calloc(1, sizeof(NAME_t));
- return t;
-}
-
-static _unused NAMEitem_t * NAME_add_head(NAME_t *t, TYPE data) {
- assert(t);
-
- mutex_lock(*t);
- NAMEitem_t *item = calloc(1, sizeof(NAMEitem_t));
- item->data = data;
-
- if (t->head) {
- item->next = t->head;
- t->head->prev = item;
- }
- t->head = item;
-
- if (! t->tail)
- t->tail = item;
-
- mutex_unlock(*t);
- LOGF("add head=%p", t->head);
- return item;
+#define LIST(NAME, TYPE) \
+typedef struct NAME##item_t { \
+ TYPE data; \
+ struct NAME##item_t *next, *prev; \
+} NAME##item_t; \
+\
+typedef struct NAME##_t { \
+ pthread_mutex_t mutex; \
+ NAME##item_t *head, *tail; \
+} NAME##_t; \
+\
+static _unused NAME##_t * NAME##_new() { \
+ NAME##_t *t = calloc(1, sizeof(NAME##_t)); \
+ return t; \
+} \
+\
+static _unused NAME##item_t * NAME##_add_head(NAME##_t *t, TYPE data) { \
+ assert(t); \
+ mutex_lock(*t); \
+ NAME##item_t *item = calloc(1, sizeof(NAME##item_t)); \
+ item->data = data; \
+ if (t->head) { \
+ item->next = t->head; \
+ t->head->prev = item; \
+ } \
+ t->head = item; \
+ if (! t->tail) \
+ t->tail = item; \
+ mutex_unlock(*t); \
+ LOGF("add head=%p", t->head); \
+ return item; \
+} \
+\
+static _unused NAME##item_t * NAME##_add_tail(NAME##_t *t, TYPE data) { \
+ assert(t); \
+ mutex_lock(*t); \
+ NAME##item_t *item = calloc(1, sizeof(NAME##item_t)); \
+ item->data = data; \
+ if (t->tail) { \
+ item->prev = t->tail; \
+ t->tail->next = item; \
+ } \
+ t->tail = item; \
+ if (! t->head) \
+ t->head = item; \
+ mutex_unlock(*t); \
+ LOGF("add tail=%p", t->head); \
+ return item; \
+} \
+\
+static _unused void NAME##_delete(NAME##_t *t, NAME##item_t *item) { \
+ assert(t); \
+ assert(item); \
+ mutex_lock(*t); \
+ if (t->head == item) \
+ t->head = item->next; \
+ if (t->tail == item) \
+ t->tail = item->prev; \
+ if (item->next) \
+ item->next->prev = item->prev; \
+ if (item->prev)\
+ item->prev->next = item->next; \
+ free(item); \
+ mutex_unlock(*t); \
+ LOGF("deleted"); \
+} \
+\
+static _unused void NAME##_free(NAME##_t *t) { \
+ NAME##item_t *cur; \
+ mutex_lock(*t); \
+ for (cur = t->head; cur; cur = cur->next, free(cur)); \
+ mutex_unlock(*t); \
+ free(t); \
}
-static _unused NAMEitem_t * NAME_add_tail(NAME_t *t, TYPE data) {
- assert(t);
-
- mutex_lock(*t);
- NAMEitem_t *item = calloc(1, sizeof(NAMEitem_t));
- item->data = data;
-
- if (t->tail) {
- item->prev = t->tail;
- t->tail->next = item;
- }
- t->tail = item;
-
- if (! t->head)
- t->head = item;
-
- mutex_unlock(*t);
- LOGF("add tail=%p", t->head);
- return item;
-}
-
-static _unused void NAME_delete(NAME_t *t, NAMEitem_t *item) {
- assert(t);
- assert(item);
-
- mutex_lock(*t);
- if (t->head == item)
- t->head = item->next;
- if (t->tail == item)
- t->tail = item->prev;
- if (item->next)
- item->next->prev = item->prev;
- if (item->prev)
- item->prev->next = item->next;
- free(item);
-
- mutex_unlock(*t);
- LOGF("deleted");
-}
-
-static _unused void NAME_free(NAME_t *t) {
- NAMEitem_t *cur;
- mutex_lock(*t);
- for (cur = t->head; cur; cur = cur->next, free(cur));
- mutex_unlock(*t);
- free(t);
-}
-
-#undef _unused
+#endif
View
@@ -60,7 +60,8 @@ typedef struct {
char **sample_fn;
} track_param_sampler_t;
-#include "plist.h"
+#include "generic_list.h"
+LIST(plist, playing_t);
struct track_t {
pthread_mutex_t mutex;
View
@@ -4,7 +4,8 @@
#include "common.h"
#include "player.h"
-#include "tracklist.h"
+#include "generic_list.h"
+LIST(tracklist, track_t);
extern tracklist_t *tracklist;
extern void tracker_init();
View
@@ -15,7 +15,8 @@ typedef struct {
} data;
} keydown_t;
-#include "keylist.h"
+#include "generic_list.h"
+LIST(keylist, keydown_t);
keylist_t *keylist;
extern pthread_t xface_thread;

0 comments on commit f7026da

Please sign in to comment.