Stefan Schuermans

Stefan Schuermans commited on 2011-09-11 17:17:58
Showing 31 changed files, with 607 additions and 173 deletions.

... ...
@@ -1,3 +1,7 @@
1
+1.0.6 2010-12-30
2
+----------------
3
+adaptions to code and Makefile for Windows (MINGW32)
4
+
1 5
 1.0.5 2010-12-22
2 6
 ----------------
3 7
 adpations to Makefile for Mac OS X
... ...
@@ -1,5 +1,5 @@
1 1
 # FlexiPix library
2
-# !version: 1.0.5! !date: 2010-12-22!
2
+# !version: 1.0.6! !date: 2010-12-30!
3 3
 #
4 4
 # Copyright 2010 Stefan Schuermans <stefan schuermans info>
5 5
 #
... ...
@@ -16,83 +16,108 @@
16 16
 # You should have received a copy of the GNU Lesser General Public License
17 17
 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
 
19
-LIBTARGET=libflexipix
20
-VER=1
21
-VERMIN=0
22
-VERREV=5
23
-
24
-OS:=$(shell uname -s)
25
-ifeq ($(OS),Linux)
26
-  SED_I=sed -i
27
-  CC=gcc
28
-  AR=ar
29
-  SHLIBFLAGS=-shared -Wl,-soname,$(LIBTARGET).so.$(VER)
30
-  SHLIBEXT=so
31
-  RANLIB=ranlib
32
-  INSTALL=install
33
-  STOW_DIR=/usr/local/stow
34
-  DEF_PREFIX=/usr/local
35
-else
36
-  ifeq ($(OS),Darwin)
37
-    SED_I=sed -i ""
38
-    CC=gcc
39
-    AR=ar
40
-    SHLIBFLAGS=-dynamiclib
41
-    SHLIBEXT=dylib
42
-    RANLIB=ranlib
43
-    INSTALL=install
44
-    STOW_DIR=/usr/local/stow
45
-    DEF_PREFIX=/usr/local
46
-  else
47
-    $(error unsupported OS)
48
-  endif
49
-endif
19
+LIBTARGET := libflexipix
20
+VER_MAJ   := 1
21
+VER_MIN   := 0
22
+VER_REV   := 6
23
+
24
+SRCS    := $(wildcard src/*.c)
25
+EX_SRCS := $(wildcard examples/src/*.c)
50 26
 
51
-SRCS=$(wildcard src/*.c)
52
-EX_SRCS=$(wildcard examples/src/*.c)
53
-
54
-CFLAGS=-W -Wall -fPIC -O3
55
-DEFINES=-DFLP_VER_MAJ=$(VER) -DFLP_VER_MIN=$(VERMIN) -DFLP_VER_REV=$(VERREV)
56
-INCLUDES=-Iinclude
57
-LDFLAGS=-Llib
58
-LIBS=-lm -lpthread -lflexipix
59
-
60
-SRCS_BASE=$(patsubst %.c,%,$(SRCS))
61
-DEPS=$(addsuffix .d,$(SRCS_BASE))
62
-OBJS=$(addsuffix .o,$(SRCS_BASE))
63
-EX_SRCS_BASE=$(patsubst %.c,%,$(EX_SRCS))
64
-EX_DEPS=$(addsuffix .d,$(EX_SRCS_BASE))
65
-EX_OBJS=$(addsuffix .o,$(EX_SRCS_BASE))
66
-EX_TARGETS=$(EX_SRCS_BASE)
67
-
68
-LIBTGA = lib/$(LIBTARGET).a
69
-LIBTGSO = lib/$(LIBTARGET).$(SHLIBEXT).$(VER)
70
-LIBTGSOM = $(LIBTGSO).$(VERMIN)
71
-LIBTGSOR = $(LIBTGSOM).$(VERREV)
72
-
73
-VERSION = $(VER).$(VERMIN).$(VERREV)
27
+VERSION  := $(VER_MAJ).$(VER_MIN).$(VER_REV)
74 28
 DATE     := $(shell date +%Y-%m-%d)
75
-PACKNAME = $(LIBTARGET)-$(VERSION)_$(DATE)
76
-PACKDATA = ChangeLog COPYING COPYING.LESSER Makefile \
29
+PACKNAME := $(LIBTARGET)-$(VERSION)_$(DATE)
30
+PACKDATA := ChangeLog COPYING COPYING.LESSER Makefile \
77 31
             examples include README src
78 32
 
79
-ENV_PREFIX=$(shell echo $$PREFIX)
80
-STOW_PREFIX=$(STOW_DIR)/libflexipix-$(VERSION)
33
+CFLAGS     := -W -Wall -O3
34
+DEFINES    := -DFLP_VER_MAJ=$(VER_MAJ) -DFLP_VER_MIN=$(VER_MIN) \
35
+              -DFLP_VER_REV=$(VER_REV)
36
+INCLUDES   := -Iinclude
37
+SH_LDFLAGS :=
38
+SH_LIBS    :=
39
+EX_LDFLAGS := -Llib
40
+EX_LIBS    := -lm -lflexipix
41
+STOW_DIR   := /usr/local/stow
42
+DEF_PREFIX := /usr/local
43
+
44
+OS_RAW := $(shell uname -s)
45
+ifeq ($(OS_RAW),Linux)
46
+  OS         := linux
47
+  CC         := gcc
48
+  AR         := ar
49
+  RANLIB     := ranlib
50
+  LEXT       := so
51
+  LEXTSUF    := .$(VERSION)
52
+  BSUF       :=
53
+  INSTALL    := install
54
+  CFLAGS     += -fPIC
55
+  SH_LDFLAGS += -shared -Wl,-soname,$(LIBTARGET).so.$(VER_MAJ)
56
+  EX_LDFLAGS += -Wl,-rpath,\$$ORIGIN/../../lib
57
+  EX_LIBS    += -lpthread
58
+endif
59
+
60
+ifeq ($(OS_RAW),Darwin)
61
+  OS         := darwin
62
+  CC         := gcc
63
+  AR         := ar
64
+  RANLIB     := ranlib
65
+  LEXT       := dylib
66
+  LEXTSUF    :=
67
+  BSUF       :=
68
+  INSTALL    := install
69
+  CFLAGS     += -fPIC
70
+  SH_LDFLAGS += -dynamiclib
71
+  EX_LIBS    += -lpthread
72
+endif
73
+
74
+ifeq ($(patsubst MINGW32%,MINGW32,$(OS_RAW)),MINGW32)
75
+  OS         := mingw32
76
+  CC         := gcc
77
+  AR         := ar
78
+  RANLIB     := ranlib
79
+  LEXT       := dll
80
+  LEXTSUF    :=
81
+  BSUF       := .exe
82
+  INSTALL    := install
83
+  DEFINES    += -DWINDOWS
84
+  SH_LDFLAGS += -shared
85
+  SH_LIBS    += -lwsock32
86
+  EX_LIBS    += -lwsock32
87
+endif
88
+
89
+ifeq ($(OS),)
90
+  $(error unsupported operating system $(OS_RAW))
91
+endif
92
+
93
+SRCS_BASE    := $(patsubst %.c,%,$(SRCS))
94
+DEPS         := $(addsuffix .d,$(SRCS_BASE))
95
+OBJS         := $(addsuffix .o,$(SRCS_BASE))
96
+EX_SRCS_BASE := $(patsubst %.c,%,$(EX_SRCS))
97
+EX_DEPS      := $(addsuffix .d,$(EX_SRCS_BASE))
98
+EX_OBJS      := $(addsuffix .o,$(EX_SRCS_BASE))
99
+EX_TARGETS   := $(addsuffix $(BSUF),$(EX_SRCS_BASE))
100
+
101
+TARGET    := lib/$(LIBTARGET).a
102
+SH_TARGET := lib/$(LIBTARGET).$(LEXT)$(LEXTSUF)
103
+
104
+ENV_PREFIX := $(shell echo $$PREFIX)
105
+STOW_PREFIX := $(STOW_DIR)/libflexipix-$(VERSION)
81 106
 ifneq ($(ENV_PREFIX),)
82
-  PREFIX=$(ENV_PREFIX)
107
+  PREFIX := $(ENV_PREFIX)
83 108
 else
84 109
   ifeq ($(shell if [ -d $(STOW_DIR) ]; then echo stow; fi),stow)
85
-    PREFIX=$(STOW_PREFIX)
110
+    PREFIX := $(STOW_PREFIX)
86 111
   else
87
-    PREFIX=$(DEF_PREFIX)
112
+    PREFIX := $(DEF_PREFIX)
88 113
   endif
89 114
 endif
90 115
 
91
-.PHONY: all clean pack install uninstall
116
+.PHONY: all clean install uninstall ver pack
92 117
 .SECONDARY:
93 118
 .SUFFIXES:
94 119
 
95
-all: deps $(LIBTGA) $(LIBTGSO) $(EX_TARGETS)
120
+all: deps $(TARGET) $(SH_TARGET) $(EX_TARGETS)
96 121
 
97 122
 ifneq ($(MAKECMDGOALS),clean)
98 123
   include deps
... ...
@@ -103,40 +128,69 @@ deps: $(DEPS) $(EX_DEPS)
103 128
 
104 129
 %.d: %.c
105 130
 	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -M -o $@ $<
106
-	$(SED_I) 's!^$(basename $(notdir $<))!$(dir $<)&!' $@
131
+	sed 's!^$(basename $(notdir $<))!$(dir $<)&!' <$@ >$@.tmp
132
+	mv $@.tmp $@
107 133
 
108 134
 %.o: %.c
109 135
 	$(CC) $(CFLAGS) $(DEFINES) $(INCLUDES) -c -o $@ $<
110 136
 
111
-%: %.o $(LIBTGA) $(LIBTGSO)
112
-	$(CC) $(LDFLAGS) -o $@ $< $(LIBS)
137
+%$(BSUF): %.o $(LTA) $(LTSO)
138
+	$(CC) $(EX_LDFLAGS) -o $@ $< $(EX_LIBS)
113 139
 
114 140
 lib:
115 141
 	mkdir -p lib
116 142
 
117
-$(LIBTGA): $(OBJS) lib
143
+$(TARGET): $(OBJS) | lib
118 144
 	$(AR) cr $@ $(filter-out lib,$+)
119 145
 	$(RANLIB) $@
120 146
 
121
-$(LIBTGSOR): $(OBJS)
122
-	$(CC) $(SHLIBFLAGS) $(LDFLAGS) -o $@ $+
123
-
124
-$(LIBTGSOM): $(LIBTGSOR)
125
-	rm -f $@
126
-	ln -s $(notdir $<) $@
127
-
128
-$(LIBTGSO): $(LIBTGSOM)
129
-	rm -f $@
130
-	ln -s $(notdir $<) $@
147
+$(SH_TARGET): $(OBJS) | lib
148
+	$(CC) $(SH_LDFLAGS) -o $@ $+ $(SH_LIBS)
149
+ifeq ($(OS),linux)
150
+	cd $(dir $@); \
151
+	  ln -s $(notdir $@) \
152
+	        $(patsubst %.$(VER_REV),%,$(notdir $@))
153
+	cd $(dir $@); \
154
+	  ln -s $(patsubst %.$(VER_REV),%,$(notdir $@)) \
155
+	        $(patsubst %.$(VER_MIN).$(VER_REV),%,$(notdir $@))
156
+	cd $(dir $@); \
157
+	  ln -s $(patsubst %.$(VER_MIN).(VER_REV),%,$(notdir $@)) \
158
+	        $(patsubst %.$(VER_MAJ).$(VER_MIN).$(VER_REV),%,$(notdir $@))
159
+endif
131 160
 
132 161
 clean:
133 162
 	rm -rf deps $(DEPS) $(OBJS) lib \
134 163
 	       $(EX_DEPS) $(EX_OBJS) $(EX_TARGETS)
135 164
 
165
+install: all
166
+	$(INSTALL) -d $(PREFIX)/include/flexipix
167
+	$(INSTALL) -m 644 -t $(PREFIX)/include/flexipix $(wildcard include/flexipix/*.h)
168
+	$(INSTALL) -d $(PREFIX)/lib
169
+	$(INSTALL) -m 644 -t $(PREFIX)/lib $(TARGET) $(SH_TARGET)
170
+ifeq ($(OS),linux)
171
+	ln -s $(LIBTARGET).$(LEXT).$(VER_MAJ).$(VER_MIN).$(VER_REV) \
172
+	   $(PREFIX)/lib/$(LIBTARGET).$(LEXT).$(VER_MAJ).$(VER_MIN)
173
+	ln -s $(LIBTARGET).$(LEXT).$(VER_MAJ).$(VER_MIN) \
174
+	   $(PREFIX)/lib/$(LIBTARGET).$(LEXT).$(VER_MAJ)
175
+endif
176
+
177
+uninstall:
178
+	rm -f $(PREFIX)/lib/$(notdir $(SH_TARGET))
179
+	rm -f $(PREFIX)/lib/$(notdir $(TARGET))
180
+	rm -rf $(PREFIX)/include/flexipix
181
+
182
+ver:
183
+	$(MAKE) clean
184
+	for FILE in $$(find $(PACKDATA) -type f); \
185
+	do \
186
+	  <$$FILE sed 's/!version: [0-9.]*!/!version: $(VERSION)!/g' \
187
+	    | sed 's/!date: [0-9-]*!/!date: $(DATE)!/g' >$$FILE.tmp; \
188
+	  mv $$FILE.tmp $$FILE; \
189
+	done
190
+
136 191
 pack:
137 192
 	$(MAKE) clean
138
-	$(SED_I) 's/!version: [0-9.]*!/!version: $(VERSION)!/g' $$(find $(PACKDATA) -type f)
139
-	$(SED_I) 's/!date: [0-9-]*!/!date: $(DATE)!/g' $$(find $(PACKDATA) -type f)
193
+	$(MAKE) ver
140 194
 	$(MAKE)
141 195
 	$(MAKE) clean
142 196
 	mkdir -p pack/$(PACKNAME)
... ...
@@ -145,18 +199,3 @@ pack:
145 199
 	rm -rf pack/$(PACKNAME)
146 200
 	$(MAKE) clean
147 201
 
148
-install: all
149
-	$(INSTALL) -d $(PREFIX)/include/flexipix
150
-	$(INSTALL) -m 644 -t $(PREFIX)/include/flexipix $(wildcard include/flexipix/*.h)
151
-	$(INSTALL) -d $(PREFIX)/lib
152
-	$(INSTALL) -m 644 -t $(PREFIX)/lib $(LIBTGA) $(LIBTGSO)
153
-	ln -sf $(notdir $(LIBTGSO)) $(PREFIX)/lib/$(notdir $(LIBTGSOM))
154
-	ln -sf $(notdir $(LIBTGSOM)) $(PREFIX)/lib/$(notdir $(LIBTGSOR))
155
-
156
-uninstall:
157
-	rm -f $(PREFIX)/lib/$(notdir $(LIBTGA))
158
-	rm -f $(PREFIX)/lib/$(notdir $(LIBTGSOR))
159
-	rm -f $(PREFIX)/lib/$(notdir $(LIBTGSOM))
160
-	rm -f $(PREFIX)/lib/$(notdir $(LIBTGSO))
161
-	rm -rf $(PREFIX)/include/flexipix
162
-
... ...
@@ -1,5 +1,5 @@
1 1
 FlexiPix library
2
-!version: 1.0.5! !date: 2010-12-22!
2
+!version: 1.0.6! !date: 2010-12-30!
3 3
 
4 4
 FlexPix is a large scale display architecure that is driven using UDP/IP.
5 5
 It consists of single pixels that are connected to chains. A number of those
... ...
@@ -4,6 +4,10 @@
4 4
 
5 5
 #include <flexipix/flexipix.h>
6 6
 
7
+#ifdef WINDOWS
8
+#include <winsock.h>
9
+#endif
10
+
7 11
 /* just an example for some data */
8 12
 typedef struct userdata_s {
9 13
   int i;
... ...
@@ -57,6 +61,13 @@ int main(int argc, char *argv[])
57 61
   }
58 62
   config = argv[1];
59 63
 
64
+#ifdef WINDOWS
65
+  {
66
+    WSADATA data;
67
+    WSAStartup(MAKEWORD(1,1), &data);
68
+  }
69
+#endif
70
+
60 71
   /* create a display, take the configuration from a file,
61 72
      deliver messages to the callback function msg(),
62 73
      the last parameter is passed as first parameter to msg()
... ...
@@ -87,6 +98,11 @@ int main(int argc, char *argv[])
87 98
   printf("done\n");
88 99
 
89 100
   flp_display_free(p_display);
101
+
102
+#ifdef WINDOWS
103
+  WSACleanup();
104
+#endif
105
+
90 106
   return 0;
91 107
 }
92 108
 
... ...
@@ -4,6 +4,10 @@
4 4
 
5 5
 #include <flexipix/flexipix.h>
6 6
 
7
+#ifdef WINDOWS
8
+#include <winsock.h>
9
+#endif
10
+
7 11
 /* just an example for some data */
8 12
 typedef struct userdata_s {
9 13
   int i;
... ...
@@ -58,6 +62,13 @@ int main(int argc, char *argv[])
58 62
   }
59 63
   config = argv[1];
60 64
 
65
+#ifdef WINDOWS
66
+  {
67
+    WSADATA data;
68
+    WSAStartup(MAKEWORD(1,1), &data);
69
+  }
70
+#endif
71
+
61 72
   /* create a displayer that manages a display in the background
62 73
      and takes care that data is sent periodically to the distributors
63 74
      to prevent that the pixels turn off after a timeout,
... ...
@@ -125,6 +136,11 @@ int main(int argc, char *argv[])
125 136
 
126 137
   free(p_image);
127 138
   flp_displayer_free(p_displayer);
139
+
140
+#ifdef WINDOWS
141
+  WSACleanup();
142
+#endif
143
+
128 144
   return 0;
129 145
 }
130 146
 
... ...
@@ -4,6 +4,10 @@
4 4
 
5 5
 #include <flexipix/flexipix.h>
6 6
 
7
+#ifdef WINDOWS
8
+#include <winsock.h>
9
+#endif
10
+
7 11
 /* just an example for some data */
8 12
 typedef struct userdata_s {
9 13
   int i;
... ...
@@ -57,6 +61,13 @@ int main(int argc, char *argv[])
57 61
   }
58 62
   config = argv[1];
59 63
 
64
+#ifdef WINDOWS
65
+  {
66
+    WSADATA data;
67
+    WSAStartup(MAKEWORD(1,1), &data);
68
+  }
69
+#endif
70
+
60 71
   /* create a display, take the configuration from a file,
61 72
      deliver messages to the callback function msg(),
62 73
      the last parameter is passed as first parameter to msg()
... ...
@@ -97,6 +108,11 @@ int main(int argc, char *argv[])
97 108
 
98 109
   free(p_image);
99 110
   flp_display_free(p_display);
111
+
112
+#ifdef WINDOWS
113
+  WSACleanup();
114
+#endif
115
+
100 116
   return 0;
101 117
 }
102 118
 
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -21,13 +21,15 @@
21 21
 #ifndef FLP_DISPLAYER_H
22 22
 #define FLP_DISPLAYER_H
23 23
 
24
+#include <intern/thread.h>
25
+
24 26
 /**
25 27
  * \brief output thread of displayer object
26 28
  *
27 29
  * \param[in] vp_displayer pointer to displayer object
28 30
  * \return unused, always NULL
29 31
  */
30
-void * flp_displayer_thread(void *vp_displayer);
32
+FLP_THREAD_FUNC(flp_displayer_thread);
31 33
 
32 34
 #endif /* #ifndef FLP_DISPLAYER_H */
33 35
 
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -0,0 +1,37 @@
1
+/*
2
+ * FlexiPix library
3
+ * !version: 1.0.6! !date: 2010-12-30!
4
+ *
5
+ * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, version 3 of the License.
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+#ifndef FLP_MISSING_H
22
+#define FLP_MISSING_H
23
+
24
+#include <string.h>
25
+
26
+#ifdef WINDOWS
27
+extern inline char * strerror_r(int errnum, char *buf, size_t buflen)
28
+{
29
+  strncpy(buf, strerror(errnum), buflen);
30
+  if (buflen >= 1)
31
+    buf[buflen - 1] = 0;
32
+  return buf;
33
+}
34
+#endif
35
+
36
+#endif /* #ifndef FLP_MISSING_H */
37
+
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -22,15 +22,72 @@
22 22
 #define FLP_NET_H
23 23
 
24 24
 #ifdef WINDOWS
25
+#  include <stdint.h>
25 26
 #  include <winsock2.h>
26 27
 #else
27
-#define closesocket close
28 28
 #  include <arpa/inet.h>
29
+#  include <errno.h>
29 30
 #  include <netdb.h>
30 31
 #  include <netinet/in.h>
32
+#  include <string.h>
31 33
 #  include <sys/socket.h>
32 34
 #  include <unistd.h>
33 35
 #endif
34 36
 
37
+/** type of socket descriptor */
38
+#ifdef WINDOWS
39
+typedef SOCKET flp_sock_t;
40
+#else
41
+typedef int flp_sock_t;
42
+#endif
43
+
44
+#ifdef WINDOWS
45
+/** IP address type missing on Windows */
46
+typedef uint32_t in_addr_t;
47
+#endif
48
+
49
+#ifdef WINDOWS
50
+/** port type missing on Windows */
51
+typedef uint16_t in_port_t;
52
+#endif
53
+
54
+#ifndef WINDOWS
55
+/** closesocket() only exists for Windows,other OSes just use close() */
56
+extern inline int closesocket(int fd)
57
+{
58
+  return close(fd);
59
+}
60
+#endif
61
+
62
+/**
63
+ * \brief check a socket descriptor
64
+ * \param[in] sock socket descriptor to check
65
+ * \return 1 if valid, 0 if not valid
66
+ */
67
+extern inline int flp_sock_is_valid(flp_sock_t sock)
68
+{
69
+#ifdef WINDOWS
70
+  return sock != INVALID_SOCKET;
71
+#else
72
+  return sock >= 0;
73
+#endif
74
+}
75
+
76
+/**
77
+ * \brief get error of last socket call as text
78
+ * \param[in] buf pointer to buffer to place text into
79
+ * \param[in] buflen size of buffer
80
+ */
81
+extern inline void flp_sock_get_last_error(char *buf, size_t buflen)
82
+{
83
+#ifdef WINDOWS
84
+  int err = WSAGetLastError();
85
+  FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
86
+                NULL, err, 0, buf, buflen, NULL);
87
+#else
88
+  strerror_r(errno, buf, buflen);
89
+#endif
90
+}
91
+
35 92
 #endif /* #ifndef FLP_NET_H */
36 93
 
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -0,0 +1,256 @@
1
+/*
2
+ * FlexiPix library
3
+ * !version: 1.0.6! !date: 2010-12-30!
4
+ *
5
+ * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6
+ *
7
+ * This program is free software: you can redistribute it and/or modify
8
+ * it under the terms of the GNU General Public License as published by
9
+ * the Free Software Foundation, version 3 of the License.
10
+ *
11
+ *
12
+ * This program is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
+ * GNU General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public License
18
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
19
+ */
20
+
21
+#ifndef FLP_THREAD_H
22
+#define FLP_THREAD_H
23
+
24
+#ifdef WINDOWS
25
+#  include <windows.h>
26
+#else
27
+#  include <errno.h>
28
+#  include <pthread.h>
29
+#  include <sys/time.h>
30
+#  include <stdlib.h>
31
+#endif
32
+
33
+/** signature to define or declare thread function */
34
+#ifdef WINDOWS
35
+#  define FLP_THREAD_FUNC(func) DWORD (__stdcall func)(LPVOID vp_displayer)
36
+#else
37
+#  define FLP_THREAD_FUNC(func) void * (func)(void *vp_displayer)
38
+#endif
39
+
40
+/** return a void pointer from a thread function */
41
+#ifdef WINDOWS
42
+#  define FLP_THREAD_RETURN(vp) return (DWORD)(vp);
43
+#else
44
+#  define FLP_THREAD_RETURN(vp) return (vp);
45
+#endif
46
+
47
+/** type for a thread ID */
48
+#ifdef WINDOWS
49
+typedef HANDLE flp_thread_id_t;
50
+#else
51
+typedef pthread_t flp_thread_id_t;
52
+#endif
53
+
54
+/** type for a mutex */
55
+#ifdef WINDOWS
56
+typedef HANDLE flp_thread_mutex_t;
57
+#else
58
+typedef pthread_mutex_t flp_thread_mutex_t;
59
+#endif
60
+
61
+/** type for a condition */
62
+#ifdef WINDOWS
63
+typedef HANDLE flp_thread_cond_t;
64
+#else
65
+typedef pthread_cond_t flp_thread_cond_t;
66
+#endif
67
+
68
+/**
69
+ * \brief create a thread
70
+ * \param[out] *p_tid thread ID
71
+ * \param[in] func thread function
72
+ * \param[in] p_data user data pointer
73
+ * \return 1 if successful, 0 on error
74
+ */
75
+extern inline int flp_thread_create(flp_thread_id_t *p_tid,
76
+                                    FLP_THREAD_FUNC(*func),
77
+                                    void * p_data)
78
+{
79
+#ifdef WINDOWS
80
+  HANDLE h = CreateThread(NULL, 0, func, (LPVOID)p_data, 0, NULL);
81
+  if (h != NULL)
82
+    *p_tid = h;
83
+  return h != NULL;
84
+#else
85
+  return pthread_create(p_tid, NULL, func, p_data) == 0;
86
+#endif
87
+}
88
+
89
+/**
90
+ * \brief join a thread
91
+ * \param[in] tid thread ID
92
+ */
93
+extern inline void flp_thread_join(flp_thread_id_t tid)
94
+{
95
+#ifdef WINDOWS
96
+  WaitForSingleObject(tid, INFINITE);
97
+  CloseHandle(tid);
98
+#else
99
+  pthread_join(tid, NULL);
100
+#endif
101
+}
102
+
103
+/**
104
+ * \brief initialize mutex
105
+ * \param[in] *p_mtx mutex variable
106
+ * \return 1 if successful, 0 on error
107
+ */
108
+extern inline int flp_thread_mutex_init(flp_thread_mutex_t *p_mtx)
109
+{
110
+#ifdef WINDOWS
111
+  HANDLE h = CreateMutex(NULL, FALSE, NULL);
112
+  if (h != NULL)
113
+    *p_mtx = h;
114
+  return h != NULL;
115
+#else
116
+  return pthread_mutex_init(p_mtx, NULL) == 0;
117
+#endif
118
+}
119
+
120
+/**
121
+ * \brief destroy mutex
122
+ * \param[in] *p_mtx mutex variable
123
+ */
124
+extern inline void flp_thread_mutex_destroy(flp_thread_mutex_t *p_mtx)
125
+{
126
+#ifdef WINDOWS
127
+  CloseHandle(*p_mtx);
128
+#else
129
+  pthread_mutex_destroy(p_mtx);
130
+#endif
131
+}
132
+
133
+/**
134
+ * \brief lock mutex
135
+ * \param[in] *p_mtx mutex variable
136
+ */
137
+extern inline void flp_thread_mutex_lock(flp_thread_mutex_t *p_mtx)
138
+{
139
+#ifdef WINDOWS
140
+  WaitForSingleObject(*p_mtx, INFINITE);
141
+#else
142
+  pthread_mutex_lock(p_mtx);
143
+#endif
144
+}
145
+
146
+/**
147
+ * \brief unlock mutex
148
+ * \param[in] *p_mtx mutex variable
149
+ */
150
+extern inline void flp_thread_mutex_unlock(flp_thread_mutex_t *p_mtx)
151
+{
152
+#ifdef WINDOWS
153
+  ReleaseMutex(*p_mtx);
154
+#else
155
+  pthread_mutex_unlock(p_mtx);
156
+#endif
157
+}
158
+
159
+/**
160
+ * \brief initialize condition
161
+ * \param[in] *p_cond conition variable
162
+ * \return 1 if successful, 0 on error
163
+ */
164
+extern inline int flp_thread_cond_init(flp_thread_cond_t *p_cond)
165
+{
166
+#ifdef WINDOWS
167
+  HANDLE h = CreateEvent(NULL, FALSE, FALSE, NULL);
168
+  if (h != NULL)
169
+    *p_cond = h;
170
+  return h != NULL;
171
+#else
172
+  return pthread_cond_init(p_cond, NULL) == 0;
173
+#endif
174
+}
175
+
176
+/**
177
+ * \brief destroy condition
178
+ * \param[in] *p_cond condition variable
179
+ */
180
+extern inline void flp_thread_cond_destroy(flp_thread_cond_t *p_cond)
181
+{
182
+#ifdef WINDOWS
183
+  CloseHandle(*p_cond);
184
+#else
185
+  pthread_cond_destroy(p_cond);
186
+#endif
187
+}
188
+
189
+/**
190
+ * \brief signal condition
191
+ * \param[in] *p_cond condition variable
192
+ */
193
+extern inline void flp_thread_cond_signal(flp_thread_cond_t *p_cond)
194
+{
195
+#ifdef WINDOWS
196
+  SetEvent(*p_cond);
197
+#else
198
+  pthread_cond_signal(p_cond);
199
+#endif
200
+}
201
+
202
+/**
203
+ * \brief wait for condition
204
+ * \param[in] *p_cond condition variable
205
+ * \param[in] *p_mtx mutex variable to unlock while waiting
206
+ */
207
+extern inline void flp_thread_cond_wait(flp_thread_cond_t *p_cond,
208
+                                        flp_thread_mutex_t *p_mtx)
209
+{
210
+#ifdef WINDOWS
211
+  /* the unlock/wait-begin and wait-end/lock are atomic for pthread,
212
+     but this is not needed for libflexipix... */
213
+  ReleaseMutex(*p_mtx); /* unlock mutex */
214
+  WaitForSingleObject(*p_cond, INFINITE); /* wait for condition */
215
+  WaitForSingleObject(*p_mtx, INFINITE); /* lock mutex again */
216
+#else
217
+  pthread_cond_wait(p_cond, p_mtx);
218
+#endif
219
+}
220
+
221
+/**
222
+ * \brief wait for condition with timeout
223
+ * \param[in] *p_cond condition variable
224
+ * \param[in] *p_mtx mutex variable to unlock while waiting
225
+ * \param[in] *p_now current time
226
+ * \param[in] millisecs number of milliseconds to wait at most
227
+ * \return 0 for condition singnaled, 1 for timeout
228
+ */
229
+extern inline int flp_thread_cond_timedwait(flp_thread_cond_t *p_cond,
230
+                                            flp_thread_mutex_t *p_mtx,
231
+                                            struct timeval *p_now,
232
+                                            unsigned int millisecs)
233
+{
234
+#ifdef WINDOWS
235
+  int ret;
236
+  /* the unlock/wait-begin and wait-end/lock are atomic for pthread,
237
+     but this is not needed for libflexipix... */
238
+  ReleaseMutex(*p_mtx); /* unlock mutex */
239
+  ret = WaitForSingleObject(*p_cond, millisecs); /* wait for condition */
240
+  WaitForSingleObject(*p_mtx, INFINITE); /* lock mutex again */
241
+  return ret == WAIT_TIMEOUT;
242
+  (void)p_now;
243
+#else
244
+  struct timespec until;
245
+  until.tv_sec = p_now->tv_sec + millisecs / 1000;
246
+  until.tv_nsec = p_now->tv_usec * 1000 + (millisecs % 1000) * 1000000;
247
+  if (until.tv_nsec > 1000000000) {
248
+    until.tv_nsec -= 1000000000;
249
+    until.tv_sec++;
250
+  }
251
+  return pthread_cond_timedwait(p_cond, p_mtx, &until) == ETIMEDOUT;
252
+#endif
253
+}
254
+
255
+#endif /* #ifndef FLP_THREAD_H */
256
+
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -21,11 +21,10 @@
21 21
 #ifndef FLP_TYPES_H
22 22
 #define FLP_TYPES_H
23 23
 
24
-#include <pthread.h>
25
-
26 24
 #include <flexipix/types.h>
27 25
 #include <intern/constants.h>
28 26
 #include <intern/net.h>
27
+#include <intern/thread.h>
29 28
 
30 29
 /** mapping information
31 30
  *
... ...
@@ -73,7 +72,7 @@ struct flp_display_s {
73 72
   unsigned int distri_cnt;            /**< total number of distris */
74 73
   unsigned int output_cnt;            /**< total number of outputs */
75 74
   unsigned long pixel_cnt;            /**< total number of pixels */
76
-  int sock;                           /**< socket to send UDP packets */
75
+  flp_sock_t sock;                    /**< socket to send UDP packets */
77 76
 };
78 77
 
79 78
 /** a displayer
... ...
@@ -82,9 +81,9 @@ struct flp_display_s {
82 81
  */
83 82
 struct flp_displayer_s {
84 83
   flp_display_t *p_display; /**< display managed by this displayer */
85
-  pthread_mutex_t mtx;      /**< mutex to lock msg_buf of distris */
86
-  pthread_cond_t cond;      /**< condition to wake up thread on new frame */
87
-  pthread_t tid;            /**< id of output thread */
84
+  flp_thread_mutex_t mtx;   /**< mutex to lock msg_buf of distris */
85
+  flp_thread_cond_t cond;   /**< condition to wake up thread on new frame */
86
+  flp_thread_id_t tid;      /**< id of output thread */
88 87
   volatile int active;      /**< if to output to distris */
89 88
   volatile int send;        /**< set to force immediate sending to distris */
90 89
   volatile int end;         /**< set to signal end to thread */
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -29,6 +29,7 @@
29 29
 #include <intern/constants.h>
30 30
 #include <intern/config.h>
31 31
 #include <intern/mapping.h>
32
+#include <intern/missing.h>
32 33
 #include <intern/net.h>
33 34
 #include <intern/parse.h>
34 35
 #include <intern/strtod_noloc.h>
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -79,11 +79,11 @@ flp_display_t *flp_display_create(const char *sz_config_file,
79 79
 
80 80
   /* create socket */
81 81
   p_display->sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
82
-  if (p_display->sock < 0) {
82
+  if (!flp_sock_is_valid(p_display->sock)) {
83 83
     flp_display_free(p_display);
84 84
     if (p_msg_func) {
85 85
       char errmsg[256];
86
-      strerror_r(errno, errmsg, sizeof(errmsg));
86
+      flp_sock_get_last_error(errmsg, sizeof(errmsg));
87 87
       p_msg_func(p_msg_ctx, flp_msg_type_err,
88 88
                  "could not create UDP socket: %s\n", errmsg);
89 89
     }
... ...
@@ -96,7 +96,7 @@ flp_display_t *flp_display_create(const char *sz_config_file,
96 96
     flp_display_free(p_display);
97 97
     if (p_msg_func) {
98 98
       char errmsg[256];
99
-      strerror_r(errno, errmsg, sizeof(errmsg));
99
+      flp_sock_get_last_error(errmsg, sizeof(errmsg));
100 100
       p_msg_func(p_msg_ctx, flp_msg_type_err,
101 101
                  "could not bind UDP socket to \"%s:%u\": %s\n",
102 102
                  inet_ntoa(p_display->bind_addr.sin_addr),
... ...
@@ -134,7 +134,7 @@ void flp_display_free(flp_display_t *p_display)
134 134
     }
135 135
 
136 136
     /* close network connection */
137
-    if (p_display->sock >= 0)
137
+    if (flp_sock_is_valid(p_display->sock))
138 138
       closesocket(p_display->sock);
139 139
 
140 140
     /* free display structutre */
... ...
@@ -260,8 +260,8 @@ void flp_display_send(flp_display_t *p_display)
260 260
         htonl(FLP_DEST_IP_BASE + p_distri->distri * FLP_DEST_IP_STEP);
261 261
 
262 262
       /* send message as UDP packet */
263
-      sendto(p_display->sock, p_distri->p_msg_buf, p_distri->msg_len, 0,
264
-             (struct sockaddr *)&dest_addr, sizeof (dest_addr));
263
+      sendto(p_display->sock, (char *)p_distri->p_msg_buf, p_distri->msg_len,
264
+             0, (struct sockaddr *)&dest_addr, sizeof (dest_addr));
265 265
 
266 266
     } /* if (p_distri) */
267 267
   } /* for (distri ...) */
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -18,7 +18,6 @@
18 18
  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
  */
20 20
 
21
-#include <pthread.h>
22 21
 #include <sys/time.h>
23 22
 #include <stdlib.h>
24 23
 
... ...
@@ -27,6 +26,7 @@
27 26
 #include <flexipix/msg.h>
28 27
 #include <flexipix/types.h>
29 28
 #include <intern/displayer.h>
29
+#include <intern/thread.h>
30 30
 #include <intern/types.h>
31 31
 
32 32
 /**
... ...
@@ -81,7 +81,7 @@ flp_displayer_t *flp_displayer_create(const char *sz_config_file,
81 81
   /* set up output thread */
82 82
 
83 83
   /* initialize mutex */
84
-  if (pthread_mutex_init(&p_displayer->mtx, NULL)) {
84
+  if (!flp_thread_mutex_init(&p_displayer->mtx)) {
85 85
     flp_display_free(p_displayer->p_display);
86 86
     free(p_displayer);
87 87
     if (p_msg_func)
... ...
@@ -91,8 +91,8 @@ flp_displayer_t *flp_displayer_create(const char *sz_config_file,
91 91
   }
92 92
 
93 93
   /* initialize condition */
94
-  if (pthread_cond_init(&p_displayer->cond, NULL)) {
95
-    pthread_mutex_destroy(&p_displayer->mtx);
94
+  if (!flp_thread_cond_init(&p_displayer->cond)) {
95
+    flp_thread_mutex_destroy(&p_displayer->mtx);
96 96
     flp_display_free(p_displayer->p_display);
97 97
     free(p_displayer);
98 98
     if (p_msg_func)
... ...
@@ -102,10 +102,10 @@ flp_displayer_t *flp_displayer_create(const char *sz_config_file,
102 102
   }
103 103
 
104 104
   /* create thread */
105
-  if (pthread_create(&p_displayer->tid, NULL,
106
-                     flp_displayer_thread, (void *)p_displayer)) {
107
-    pthread_cond_destroy(&p_displayer->cond);
108
-    pthread_mutex_destroy(&p_displayer->mtx);
105
+  if (!flp_thread_create(&p_displayer->tid, flp_displayer_thread,
106
+                        (void *)p_displayer)) {
107
+    flp_thread_cond_destroy(&p_displayer->cond);
108
+    flp_thread_mutex_destroy(&p_displayer->mtx);
109 109
     flp_display_free(p_displayer->p_display);
110 110
     free(p_displayer);
111 111
     if (p_msg_func)
... ...
@@ -126,10 +126,10 @@ void flp_displayer_free(flp_displayer_t *p_displayer)
126 126
 {
127 127
   /* tear down thread */
128 128
   p_displayer->end = 1;
129
-  pthread_cond_signal(&p_displayer->cond);
130
-  pthread_join(p_displayer->tid, NULL);
131
-  pthread_cond_destroy(&p_displayer->cond);
132
-  pthread_mutex_destroy(&p_displayer->mtx);
129
+  flp_thread_cond_signal(&p_displayer->cond);
130
+  flp_thread_join(p_displayer->tid);
131
+  flp_thread_cond_destroy(&p_displayer->cond);
132
+  flp_thread_mutex_destroy(&p_displayer->mtx);
133 133
 
134 134
   /* free managed display */
135 135
   flp_display_free(p_displayer->p_display);
... ...
@@ -148,9 +148,9 @@ void flp_displayer_free(flp_displayer_t *p_displayer)
148 148
 void flp_displayer_get_size(flp_displayer_t *p_displayer,
149 149
                             unsigned int *p_width, unsigned int *p_height)
150 150
 {
151
-  pthread_mutex_lock(&p_displayer->mtx);
151
+  flp_thread_mutex_lock(&p_displayer->mtx);
152 152
   flp_display_get_size(p_displayer->p_display, p_width, p_height);
153
-  pthread_mutex_unlock(&p_displayer->mtx);
153
+  flp_thread_mutex_unlock(&p_displayer->mtx);
154 154
 }
155 155
 
156 156
 /**
... ...
@@ -166,7 +166,7 @@ void flp_displayer_get_size(flp_displayer_t *p_displayer,
166 166
 void flp_displayer_activate(flp_displayer_t *p_displayer)
167 167
 {
168 168
   p_displayer->active = 1;
169
-  pthread_cond_signal(&p_displayer->cond);
169
+  flp_thread_cond_signal(&p_displayer->cond);
170 170
 }
171 171
 
172 172
 /**
... ...
@@ -192,9 +192,9 @@ void flp_displayer_deactivate(flp_displayer_t *p_displayer)
192 192
  */
193 193
 void flp_displayer_data_clear(flp_displayer_t *p_displayer)
194 194
 {
195
-  pthread_mutex_lock(&p_displayer->mtx);
195
+  flp_thread_mutex_lock(&p_displayer->mtx);
196 196
   flp_display_data_clear(p_displayer->p_display);
197
-  pthread_mutex_unlock(&p_displayer->mtx);
197
+  flp_thread_mutex_unlock(&p_displayer->mtx);
198 198
 }
199 199
 
200 200
 /**
... ...
@@ -217,10 +217,10 @@ void flp_displayer_data(flp_displayer_t *p_displayer, flp_u8_t *p_data,
217 217
                         unsigned int x, unsigned int y,
218 218
                         unsigned int width, unsigned int height)
219 219
 {
220
-  pthread_mutex_lock(&p_displayer->mtx);
220
+  flp_thread_mutex_lock(&p_displayer->mtx);
221 221
   flp_display_data(p_displayer->p_display, p_data, stride_x, stride_y,
222 222
                    x, y, width, height);
223
-  pthread_mutex_unlock(&p_displayer->mtx);
223
+  flp_thread_mutex_unlock(&p_displayer->mtx);
224 224
 }
225 225
 
226 226
 /**
... ...
@@ -233,27 +233,23 @@ void flp_displayer_data(flp_displayer_t *p_displayer, flp_u8_t *p_data,
233 233
 void flp_displayer_send(flp_displayer_t *p_displayer)
234 234
 {
235 235
   p_displayer->send = 1;
236
-  pthread_cond_signal(&p_displayer->cond);
236
+  flp_thread_cond_signal(&p_displayer->cond);
237 237
 }
238 238
 
239
-#define FLP_MMFI_MS_S (FLP_MCUF_MAX_FRAME_INTERVAL_MS / 1000)
240
-#define FLP_MMFI_MS_US ((FLP_MCUF_MAX_FRAME_INTERVAL_MS % 1000) * 1000)
241
-#define FLP_MMFI_MS_NS ((FLP_MCUF_MAX_FRAME_INTERVAL_MS % 1000) * 1000000)
242
-
243 239
 /**
244 240
  * \brief output thread of displayer object
245 241
  *
246 242
  * \param[in] vp_displayer pointer to displayer object
247 243
  * \return unused, always NULL
248 244
  */
249
-void * flp_displayer_thread(void *vp_displayer)
245
+FLP_THREAD_FUNC(flp_displayer_thread)
250 246
 {
251 247
   flp_displayer_t *p_displayer = (flp_displayer_t *)vp_displayer;
252 248
   struct timeval last, now, delta;
253
-  struct timespec until;
254 249
   int timed_send;
250
+  int interval_ms = FLP_MCUF_MAX_FRAME_INTERVAL_MS;
255 251
 
256
-  pthread_mutex_lock(&p_displayer->mtx);
252
+  flp_thread_mutex_lock(&p_displayer->mtx);
257 253
 
258 254
   gettimeofday(&last, NULL); /* initialize last to some valid time */
259 255
 
... ...
@@ -273,9 +269,9 @@ void * flp_displayer_thread(void *vp_displayer)
273 269
         ++delta.tv_sec;
274 270
       }
275 271
       /* check if late enough for timed send */
276
-      timed_send = delta.tv_sec > FLP_MMFI_MS_S
277
-                 || (delta.tv_sec == FLP_MMFI_MS_S
278
-                     && delta.tv_usec >= FLP_MMFI_MS_US);
272
+      timed_send = delta.tv_sec > interval_ms / 1000
273
+                 || (delta.tv_sec == interval_ms / 1000
274
+                     && delta.tv_usec >= (interval_ms % 1000) * 1000);
279 275
 
280 276
       /* send if send requested or late enough */
281 277
       if (p_displayer->send || timed_send) {
... ...
@@ -285,13 +281,8 @@ void * flp_displayer_thread(void *vp_displayer)
285 281
       }
286 282
 
287 283
       /* sleep until next frame has to be sent */
288
-      until.tv_sec = last.tv_sec + FLP_MMFI_MS_S;
289
-      until.tv_nsec = last.tv_usec * 1000 + FLP_MMFI_MS_NS;
290
-      if (until.tv_nsec > 1000000000) {
291
-        until.tv_nsec -= 1000000000;
292
-        until.tv_sec++;
293
-      }
294
-      pthread_cond_timedwait(&p_displayer->cond, &p_displayer->mtx, &until);
284
+      flp_thread_cond_timedwait(&p_displayer->cond, &p_displayer->mtx,
285
+                                &last, interval_ms);
295 286
 
296 287
     } /* if (p_displayer->active) */
297 288
 
... ...
@@ -299,14 +290,14 @@ void * flp_displayer_thread(void *vp_displayer)
299 290
     else {
300 291
 
301 292
       /* sleep */
302
-      pthread_cond_wait(&p_displayer->cond, &p_displayer->mtx);
293
+      flp_thread_cond_wait(&p_displayer->cond, &p_displayer->mtx);
303 294
 
304 295
     } /* if (p_displayer->active) ... else */
305 296
 
306 297
   } /* while(!p_displayer->end) */
307 298
 
308
-  pthread_mutex_unlock(&p_displayer->mtx);
299
+  flp_thread_mutex_unlock(&p_displayer->mtx);
309 300
 
310
-  return NULL;
301
+  FLP_THREAD_RETURN(NULL);
311 302
 }
312 303
 
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * FlexiPix library
3
- * !version: 1.0.5! !date: 2010-12-22!
3
+ * !version: 1.0.6! !date: 2010-12-30!
4 4
  *
5 5
  * Copyright 2010 Stefan Schuermans <stefan schuermans info>
6 6
  *
7 7