Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
03fde419
Commit
03fde419
authored
Nov 02, 2011
by
neverlord
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
c test
parent
0d233f48
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
61 deletions
+82
-61
blob/c_context_impl.c
blob/c_context_impl.c
+0
-25
blob/context_impl_test.cpp
blob/context_impl_test.cpp
+46
-0
blob/cppa_fibre.c
blob/cppa_fibre.c
+32
-31
blob/cppa_fibre.h
blob/cppa_fibre.h
+4
-5
No files found.
blob/c_context_impl.c
View file @
03fde419
...
@@ -11,31 +11,6 @@
...
@@ -11,31 +11,6 @@
#include "cppa_fibre.h"
#include "cppa_fibre.h"
static
ucontext_t
ctx
[
2
];
__thread
int
m_count
=
0
;
struct
cppa_fibre
{
ucontext_t
m_context
;
};
void
cppa_fibre_ctor
(
cppa_fibre
*
instance
);
void
cppa_fibre_ctor
(
cppa_fibre
*
instance
,
void
(
*
fun
)());
void
cppa_fibre_dtor
(
cppa_fibre
*
instance
);
void
cppa_fibre_switch
(
cppa_fibre
*
from
,
cppa_fibre
*
to
);
void
cppa_fibre_yield
(
int
value
);
int
cppa_fibre_yielded_value
();
typedef
struct
fibre_wrapper
*
fibre_ptr
;
fibre_ptr
get_fibre
();
void
coroutine
()
void
coroutine
()
{
{
for
(;;)
for
(;;)
...
...
blob/context_impl_test.cpp
0 → 100644
View file @
03fde419
#include <iostream>
#include "cppa_fibre.h"
using
std
::
cout
;
using
std
::
endl
;
struct
pseudo_worker
{
int
m_value
;
pseudo_worker
()
:
m_value
(
0
)
{
}
void
operator
()()
{
for
(;;)
{
++
m_value
;
cout
<<
"value = "
<<
m_value
<<
endl
;
cppa_fibre_yield
(
0
);
}
}
};
void
coroutine
()
{
auto
pw
=
reinterpret_cast
<
pseudo_worker
*>
(
cppa_fibre_init_switch_arg
());
(
*
pw
)();
}
int
main
()
{
pseudo_worker
pw
;
cppa_fibre
fself
;
cppa_fibre
fcoroutine
;
cppa_fibre_ctor
(
&
fself
);
cppa_fibre_ctor2
(
&
fcoroutine
,
coroutine
,
&
pw
);
cppa_fibre_initialize
(
&
fcoroutine
);
for
(
int
i
=
1
;
i
<
11
;
++
i
)
{
cout
<<
"i = "
<<
i
<<
endl
;
cppa_fibre_switch
(
&
fself
,
&
fcoroutine
);
}
cppa_fibre_dtor
(
&
fself
);
cppa_fibre_dtor
(
&
fcoroutine
);
return
0
;
}
blob/cppa_fibre.c
View file @
03fde419
...
@@ -2,24 +2,20 @@
...
@@ -2,24 +2,20 @@
#define _XOPEN_SOURCE
#define _XOPEN_SOURCE
#endif
#endif
#include <stdio.h>
#include <ucontext.h>
#include <ucontext.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <signal.h>
#include <signal.h>
#include <stddef.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
#include "cppa_fibre.h"
#include "cppa_fibre.h"
/*
__thread
void
*
s_switch_arg
;
struct cppa_fibre_struct
__thread
int
s_yield_value
;
{
__thread
ucontext_t
*
s_caller
;
int m_initialized;
__thread
ucontext_t
*
s_callee
;
ucontext_t m_context;
void (*m_fun)();
void* m_init_arg;
};
*/
void
cppa_fibre_ctor
(
cppa_fibre
*
instance
)
void
cppa_fibre_ctor
(
cppa_fibre
*
instance
)
{
{
...
@@ -51,34 +47,39 @@ void cppa_fibre_initialize(cppa_fibre* instance)
...
@@ -51,34 +47,39 @@ void cppa_fibre_initialize(cppa_fibre* instance)
0
);
0
);
instance
->
m_context
.
uc_stack
.
ss_size
=
SIGSTKSZ
;
instance
->
m_context
.
uc_stack
.
ss_size
=
SIGSTKSZ
;
makecontext
(
&
(
instance
->
m_context
),
instance
->
m_fun
,
0
);
makecontext
(
&
(
instance
->
m_context
),
instance
->
m_fun
,
0
);
s_switch_arg
=
instance
->
m_init_arg
;
}
}
}
}
void
cppa_fibre_dtor
(
cppa_fibre
*
instance
)
void
cppa_fibre_dtor
(
cppa_fibre
*
instance
)
{
{
if
(
instance
->
m_state
==
2
)
{
munmap
(
instance
->
m_context
.
uc_stack
.
ss_sp
,
SIGSTKSZ
);
}
}
}
/*
void
*
cppa_fibre_init_switch_arg
()
* @brief Returns
{
*/
return
s_switch_arg
;
void
*
cppa_fibre_init_switch_arg
();
}
void
cppa_fibre_switch
(
cppa_fibre
*
from
,
cppa_fibre
*
to
);
/*
* Switches back to the calling fibre.
*/
void
cppa_fibre_yield
(
int
value
);
/*
* Gets the yielded value of the client fibre.
*/
int
cppa_fibre_yielded_value
();
#ifdef __cplusplus
void
cppa_fibre_switch
(
cppa_fibre
*
from
,
cppa_fibre
*
to
)
{
ucontext_t
*
ctx_from
=
&
(
from
->
m_context
);
ucontext_t
*
ctx_to
=
&
(
to
->
m_context
);
s_caller
=
ctx_from
;
s_callee
=
ctx_to
;
swapcontext
(
ctx_from
,
ctx_to
);
}
}
#endif
#endif
void
cppa_fibre_yield
(
int
value
)
{
s_yield_value
=
value
;
swapcontext
(
s_callee
,
s_caller
);
}
int
cppa_fibre_yielded_value
()
{
return
s_yield_value
;
}
blob/cppa_fibre.h
View file @
03fde419
...
@@ -10,11 +10,7 @@ extern "C" {
...
@@ -10,11 +10,7 @@ extern "C" {
#endif
#endif
#include <stdio.h>
#include <stdio.h>
#include <ucontext.h>
#include <ucontext.h>
#include <sys/mman.h>
#include <signal.h>
#include <stddef.h>
struct
cppa_fibre_struct
struct
cppa_fibre_struct
{
{
...
@@ -27,7 +23,7 @@ struct cppa_fibre_struct
...
@@ -27,7 +23,7 @@ struct cppa_fibre_struct
void
*
m_init_arg
;
void
*
m_init_arg
;
};
};
typedef
cppa_fibre_struct
cppa_fibre
;
typedef
struct
cppa_fibre_struct
cppa_fibre
;
void
cppa_fibre_ctor
(
cppa_fibre
*
instance
);
void
cppa_fibre_ctor
(
cppa_fibre
*
instance
);
...
@@ -43,6 +39,9 @@ void cppa_fibre_ctor2(cppa_fibre* instance,
...
@@ -43,6 +39,9 @@ void cppa_fibre_ctor2(cppa_fibre* instance,
void
(
*
fun
)(),
void
(
*
fun
)(),
void
*
switch_arg
);
void
*
switch_arg
);
/*
* @warning call directly before the first switch
*/
void
cppa_fibre_initialize
(
cppa_fibre
*
instance
);
void
cppa_fibre_initialize
(
cppa_fibre
*
instance
);
void
cppa_fibre_dtor
(
cppa_fibre
*
instance
);
void
cppa_fibre_dtor
(
cppa_fibre
*
instance
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment