1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-02-13 03:41:55 +00:00
srs/trunk/research/arm/jmp.cpp

50 lines
969 B
C++
Raw Normal View History

/*
2015-11-11 02:37:50 +00:00
# see: https://github.com/ossrs/srs/wiki/v1_CN_SrsLinuxArm
2014-11-07 08:47:49 +00:00
g++ -g -O0 -o jmp jmp.cpp
arm-linux-gnueabi-g++ -o jmp jmp.cpp -static
arm-linux-gnueabi-strip jmp
*/
#include <stdio.h>
#include <stdlib.h>
2014-11-07 08:47:49 +00:00
#include <unistd.h>
#include <setjmp.h>
2014-11-07 08:47:49 +00:00
bool func1_ok = false, func2_ok = false;
jmp_buf env_func1, env_func2;
int sum = 0;
void func1() {
int ret = setjmp(env_func1);
2014-11-07 08:47:49 +00:00
printf("[func1] setjmp ret=%d, sum++=%d\n", ret, sum++);
func1_ok = true;
2014-11-07 08:47:49 +00:00
sleep(1);
// jmp to func2
2014-11-07 08:47:49 +00:00
if (func2_ok) {
longjmp(env_func2, 1);
}
}
void func2() {
int ret = setjmp(env_func2);
2014-11-07 08:47:49 +00:00
printf("[func2] setjmp ret=%d, sum++=%d\n", ret, sum++);
func2_ok = true;
2014-11-07 08:47:49 +00:00
sleep(1);
// jmp to func1
2014-11-07 08:47:49 +00:00
if (func1_ok) {
longjmp(env_func1, 2);
}
}
int main(int argc, char** argv) {
printf("hello, setjmp/longjmp!\n");
func1();
func2();
printf("jmp finished, sum=%d\n", sum);
return 0;
}