forked from atheme/libmowgli-2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coroutine: some initial bits of this module, incomplete
- Loading branch information
Showing
6 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
include ../../../extra.mk | ||
|
||
STATIC_PIC_LIB_NOINST = ${LIBMOWGLI_SHARED_COROUTINE} | ||
STATIC_LIB_NOINST = ${LIBMOWGLI_STATIC_COROUTINE} | ||
|
||
SRCS = coroutine.c | ||
|
||
INCLUDES := ${SRCS:.c=.h} | ||
|
||
include ../../../buildsys.mk | ||
|
||
includesubdir = $(PACKAGE_NAME)/coroutine | ||
|
||
CPPFLAGS += -I. -I.. -I../../.. -DMOWGLI_CORE | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* libmowgli: A collection of useful routines for programming. | ||
* coroutine.c: coroutines/fibers implementation | ||
* | ||
* Copyright (c) 2012 William Pitcock <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include "mowgli.h" | ||
#include "coroutine_private.h" | ||
|
||
static mowgli_stack_dir_t mowgli_coroutine_get_stack_dir_leaf_ptr(void *callstack_p) | ||
{ | ||
mowgli_stack_dir_t dir; | ||
void *childstack_p = &callstack_p; | ||
|
||
dir = (childstack_p > callstack_p ? MOWGLI_STACK_GROWS_UP : MOWGLI_STACK_GROWS_DOWN); | ||
|
||
return dir; | ||
} | ||
|
||
mowgli_stack_dir_t mowgli_coroutine_get_stack_dir(void) | ||
{ | ||
int dummy1 = 0; | ||
void *dummy2 = &dummy1; | ||
|
||
return mowgli_coroutine_get_stack_dir_leaf_ptr(dummy2); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* libmowgli: A collection of useful routines for programming. | ||
* coroutine.h: coroutines/fibers implementation | ||
* | ||
* Copyright (c) 2012 William Pitcock <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and/or distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | ||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef __MOWGLI_COROUTINE_H__ | ||
#define __MOWGLI_COROUTINE_H__ | ||
|
||
typedef enum { | ||
MOWGLI_STACK_GROWS_DOWN = -1, | ||
MOWGLI_STACK_GROWS_UP = 1, | ||
} mowgli_stack_dir_t; | ||
|
||
extern mowgli_stack_dir_t mowgli_coroutine_get_stack_dir(void); | ||
|
||
typedef void mowgli_coroutine_t; | ||
typedef void (*mowgli_coroutine_start_fn_t)(void *userdata); | ||
|
||
extern int mowgli_coroutine_create(mowgli_coroutine_start_fn_t start_fn, void *userdata); | ||
extern void mowgli_coroutine_destroy(mowgli_coroutine_t *coroutine); | ||
extern void mowgli_coroutine_yield(void); | ||
extern void mowgli_coroutine_yield_to(mowgli_coroutine_t *next); | ||
extern void mowgli_coroutine_exit(void); | ||
extern void mowgli_coroutine_exit_to(mowgli_coroutine_t *next); | ||
extern mowgli_coroutine_t *mowgli_coroutine_self(void); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters