1. Paweł Wieczorek
  2. libpwuthread

Commits

Paweł Wieczorek  committed 1fa50dd

* inicjacja struktury projektu

  • Participants
  • Parent commits 54f5ad4
  • Branches default

Comments (0)

Files changed (12)

File Makefile

View file
+CC= gcc
+CFLAGS= -Wall -g -fPIC -Iinclude
+LD= ${CC} -shared
+LDFLAGS= 
+LIBNAME=libpwuthread.so
+LIBVER=1
+LIBRARY=${LIBNAME}.${LIBVER}
+SRCS= ${LIB_SRC} ${SUPPORT_SRC}
+LIB_SRC=\
+    lib/main.c\
+
+EXAMPLE_SRC=\
+    examples/ex01.c\
+    examples/ex02.c\
+    
+OBJS= ${SRCS:%.c=%.o}
+EXAMPLES= ${EXAMPLE_SRC:%.c=%}
+.SUFFIXES: .o .c.o .c
+
+all: ${LIBNAME} examples
+
+${LIBRARY}: ${OBJS}
+	${LD} ${LDFLAGS} -o ${LIBRARY} ${OBJS}
+
+${LIBNAME}: ${LIBRARY}
+	ln -sf ${LIBRARY} ${LIBNAME}
+
+examples: ${EXAMPLES}
+
+.c.o:
+	${CC} -c ${CFLAGS} -o $@ $<
+
+.c:
+	${CC} -L. -Wl,-rpath,. ${CFLAGS} -o $@ $< -lpwuthread
+
+clean:
+	rm -f ${LIBNAME} ${LIBRARY} ${OBJS} ${EXAMPLES}
+

File examples/ex01.c

View file
+#include <stdio.h>
+#include <pwuthread.h>
+
+void *
+tmain(void *arg)
+{
+    printf("Working\n");
+    return arg;
+}
+
+int
+main()
+{
+    pwuthread_t t;
+    pwuthread_create(&t, NULL, tmain, NULL);
+    pwuthread_join(t, NULL);
+    pwuthread_detach(t);
+    return 0;
+}

File examples/ex02.c

View file
+#include <stdio.h>
+#include <pwuthread.h>
+
+int i;
+
+void *
+tmain0(void *arg)
+{
+    for (i = 0; i < 10; i++) {
+        pwuthread_yield();
+    }
+    return arg;
+}
+
+void *
+tmain1(void *arg)
+{
+    int j;
+    for (j = 0; j < 5; j++) {
+        i++;
+        pwuthread_yield();
+    }
+    return arg;
+}
+
+int
+main()
+{
+    pwuthread_t t0,t1;
+    pwuthread_setschedtype(PWUTHREAD_SCHED_COOPERATIVE, NULL);
+    pwuthread_create(&t0, NULL, tmain0, NULL);
+    pwuthread_create(&t1, NULL, tmain1, NULL);
+    pwuthread_join(&t0);
+    pwuthread_join(&t1);
+    return 0;
+}
+

File include/pwuthread.h

View file
+#ifndef PWUTHREAD_H
+#define PWUTHREAD_H
+
+#include "pwuthread/types.h"
+#include "pwuthread/mainapi.h"
+
+#endif
+

File include/pwuthread/ctx.h

View file
+#ifndef PWUTHREAD_CTX_H
+#define PWUTHREAD_CTX_H
+
+void pwuthread_ctx_create(pwuthread_ctx_t *ctx, pwuthread_main_f *func);
+void pwuthread_ctx_setstack(pwuthread_ctx_t *ctx, void *addr, size_t l);
+void pwuthread_ctx_switch(pwuthread_ctx_t *ctx0, pwuthread_ctx_t *ctx1);
+
+#endif

File include/pwuthread/exun.h

View file
+#ifndef PWUTHREAD_EXUN_H
+#define PWUTHREAD_EXUN_H
+
+#endif
+

File include/pwuthread/mainapi.h

View file
+#ifndef PWUTHREAD_MAINAPI_H
+#define PWUTHREAD_MAINAPI_H
+
+enum PWUTHREAD_CANCEL_STATE {
+    PWUTHREAD_CANCEL_ENABLE,
+    PWUTHREAD_CANCEL_DISABLE
+};
+
+enum PWUTHREAD_CANCEL_TYPE {
+    PWUTHREAD_CANCEL_DEFERED,
+    PWUTHREAD_CANCEL_ASYNCHRONOUS
+};
+
+enum PWUTHREAD_SCHED_TYPE {
+    PWUTHREAD_SCHED_PREEMPTIVE,
+    PWUTHREAD_SCHED_COOPERATIVE
+};
+
+int pwuthread_create(pwuthread_t *t, pwuthread_attr_t *a,
+        pwuthread_main_f *func, void  *arg);
+int pwuthread_detach(pwuthread_t t);
+
+int pwuthread_setcancelstate(int state, int *oldstate);
+int pwuthread_setcanceltype(int type, int *oldtype);
+int pwuthread_setschedtype(int schedtype);
+int pwuthread_join(pwuthread_t t, void **);
+int pwuthread_cancel(pwuthread_t t);
+int pwuthread_exit(pwuthread_t t, void *);
+void pwuthread_testcancel(void);
+void pwuthread_yield(void);
+
+int pwuthread_attr_init(pwuthread_attr_t *a);
+int pwuthread_attr_get(pwuthread_t t, pwuthread_attr_t *a);
+int pwuthread_attr_destroy(pwuthread_attr_t *a);
+int pwuthread_attr_setstack(pwuthread_attr_t *a, void *, size_t );
+int pwuthread_attr_getstack(pwuthread_attr_t *a, void **, size_t *);
+
+int pwuthread_key_create(pwuthread_key_t *k);
+int pwuthread_key_destroy(pwuthread_key_t k);
+int pwuthread_setspecific(pwuthread_key_t k, const void *);
+void *pwuthread_getspecific(pwuthread_key_t k);
+
+#endif
+

File include/pwuthread/private.h

View file
+#ifndef PWUTHREAD_PRIVATE_H
+#define PWUTHREAD_PRIVATE_H
+
+#include "types.h"
+#include "mainapi.h"
+#include "ctx.h"
+
+void pwuthread_log(const char *fmt, ...);
+int pwuthread_init(void);
+
+#endif

File include/pwuthread/support.h

View file
+#ifndef PWUTHREAD_SUPPORT_H
+#define PWUTHREAD_SUPPORT_H
+
+#endif
+
+

File include/pwuthread/types.h

View file
+#ifndef PWUTHREAD_TYPES_H
+#define PWUTHREAD_TYPES_H
+
+#include <sys/types.h>
+
+struct pwuthread;
+struct pwuthread_attr;
+struct pwuthread_exun;
+struct pwuthread_exun_attr;
+struct pwuthread_ctx;
+
+typedef struct pwuthread *pwuthread_t;
+typedef struct pwuthread_attr *pwuthread_attr_t;
+typedef struct pwuthread_exun *pwuthread_exun_t;
+typedef struct pwuthread_exun_attr *pwuthread_exun_attr_t;
+typedef struct pwuthread_ctx *pwuthread_ctx_t;
+typedef int pwuthread_key_t;
+
+typedef void *pwuthread_main_f(void *);
+
+#endif

File include/pwuthread/util.h

View file
+#ifndef PWUTHREAD_UTIL_H
+#define PWUTHREAD_UTIL_H
+
+
+#endif

File lib/main.c

View file
+#include "pwuthread/private.h"
+
+int
+pwuthread_init(void)
+{
+    return 0;
+}
+
+