1 /* Very Linux-specific context switching.
2 * Written by RWMJ with lots of help from GNU pth library.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the Free
16 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: pthr_context.h,v 1.7 2003/02/05 22:13:32 rich Exp $
21 #ifndef PTHR_CONTEXT_H
22 #define PTHR_CONTEXT_H
26 #ifdef HAVE_WORKING_SETCONTEXT
30 typedef struct mctx_st {
34 /* Save machine context. */
35 #define mctx_save(mctx) (void) getcontext (&(mctx)->uc)
37 /* Restore machine context. */
38 #define mctx_restore(mctx) (void) setcontext (&(mctx)->uc)
40 /* Switch machine context. */
41 #define mctx_switch(mctx_old, mctx_new) \
42 (void) swapcontext (&((mctx_old)->uc), &((mctx_new)->uc))
44 #else /* setjmp implementation */
48 typedef struct mctx_st {
52 /* Save machine context. */
53 #define mctx_save(mctx) (void) setjmp ((mctx)->jb)
55 /* Restore machine context. */
56 #define mctx_restore(mctx) longjmp ((mctx)->jb, 1)
58 /* Switch machine context. */
59 #define mctx_switch(mctx_old, mctx_new) \
60 do { if (setjmp ((mctx_old)->jb) == 0) longjmp ((mctx_new)->jb, 1); } while(0)
62 #endif /* ! USE_UCONTEXT */
64 /* Create machine context. */
65 extern void mctx_set (mctx_t *mctx,
66 void (*sf_addr) (void *), void *sf_arg,
67 void *sk_addr, int sk_size);
70 extern unsigned long mctx_get_PC (mctx_t *mctx);
73 extern unsigned long mctx_get_SP (mctx_t *mctx);
75 #endif /* PTHR_CONTEXT_H */