mirror of
https://github.com/bsnes-emu/bsnes.git
synced 2025-04-02 10:42:14 -04:00
This represents a major code restructuring. The dot-based and scanline-based renderers are now split into two separate core libraries, asnes and bsnes. For now at least, these are -internal- names. I'm not entirely decided on how I'm going to handle releasing these two separate builds. Regardless, the folders need names. asnes has had all of the processor subfolders collapsed back into their parent folders. In other words, ppu's functions were moved into ppu/sppu, and then ppu was deleted, and then ppu/sppu became the new ppu. Repeat this for the cpu, smp and dsp and there you go. asnes/dsp also removed the DSP_STATE_MACHINE option. This was done for the sake of consistency with the rest of the core. asnes' debugger mode is currently extremely broken, but I will be fixing it in time. And for now, bsnes has kept the processor abstraction layer. I may keep it around, not sure yet. It doesn't hurt speed or anything, so I'm not too worried about making a decision right away. I may throw snesfilter, snesreader and supergameboy into this folder, just to have everything in one place. The alternate GUI forks are definitely going in there as dotnet, cocoa and python. Compiled output goes to the out/ folder now, to prevent conflicts with a file and folder named bsnes, for instance.
102 lines
2.2 KiB
C
102 lines
2.2 KiB
C
/*
|
|
libco.sjlj (2008-01-28)
|
|
author: Nach
|
|
license: public domain
|
|
*/
|
|
|
|
/*
|
|
* Note this was designed for UNIX systems. Based on ideas expressed in a paper
|
|
* by Ralf Engelschall.
|
|
* For SJLJ on other systems, one would want to rewrite springboard() and
|
|
* co_create() and hack the jmb_buf stack pointer.
|
|
*/
|
|
|
|
#define LIBCO_C
|
|
#include "libco.h"
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
#include <setjmp.h>
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef struct {
|
|
sigjmp_buf context;
|
|
void (*coentry)(void);
|
|
void *stack;
|
|
} cothread_struct;
|
|
|
|
static thread_local cothread_struct co_primary;
|
|
static thread_local cothread_struct *creating, *co_running = 0;
|
|
|
|
static void springboard(int ignored) {
|
|
if(sigsetjmp(creating->context, 0)) {
|
|
co_running->coentry();
|
|
}
|
|
}
|
|
|
|
cothread_t co_active() {
|
|
if(!co_running) co_running = &co_primary;
|
|
return (cothread_t)co_running;
|
|
}
|
|
|
|
cothread_t co_create(unsigned int size, void (*coentry)(void)) {
|
|
if(!co_running) co_running = &co_primary;
|
|
|
|
cothread_struct *thread = (cothread_struct*)malloc(sizeof(cothread_struct));
|
|
if(thread) {
|
|
struct sigaction handler;
|
|
struct sigaction old_handler;
|
|
|
|
stack_t stack;
|
|
stack_t old_stack;
|
|
|
|
thread->coentry = thread->stack = 0;
|
|
|
|
stack.ss_flags = 0;
|
|
stack.ss_size = size;
|
|
thread->stack = stack.ss_sp = malloc(size);
|
|
if(stack.ss_sp && !sigaltstack(&stack, &old_stack)) {
|
|
handler.sa_handler = springboard;
|
|
handler.sa_flags = SA_ONSTACK;
|
|
sigemptyset(&handler.sa_mask);
|
|
creating = thread;
|
|
|
|
if(!sigaction(SIGUSR1, &handler, &old_handler)) {
|
|
if(!raise(SIGUSR1)) {
|
|
thread->coentry = coentry;
|
|
}
|
|
sigaltstack(&old_stack, 0);
|
|
sigaction(SIGUSR1, &old_handler, 0);
|
|
}
|
|
}
|
|
|
|
if(thread->coentry != coentry) {
|
|
co_delete(thread);
|
|
thread = 0;
|
|
}
|
|
}
|
|
|
|
return (cothread_t)thread;
|
|
}
|
|
|
|
void co_delete(cothread_t cothread) {
|
|
if(cothread) {
|
|
if(((cothread_struct*)cothread)->stack) {
|
|
free(((cothread_struct*)cothread)->stack);
|
|
}
|
|
free(cothread);
|
|
}
|
|
}
|
|
|
|
void co_switch(cothread_t cothread) {
|
|
if(!sigsetjmp(co_running->context, 0)) {
|
|
co_running = (cothread_struct*)cothread;
|
|
siglongjmp(co_running->context, 1);
|
|
}
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|