File: syslib.c

package info (click to toggle)
rtai 3.1.0-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 23,560 kB
  • ctags: 19,698
  • sloc: ansic: 88,861; cpp: 31,340; tcl: 14,684; sh: 10,652; xml: 760; yacc: 575; lex: 537; makefile: 394; asm: 310; php: 300; perl: 108
file content (167 lines) | stat: -rw-r--r-- 4,801 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
/*
 * Copyright (C) 2001,2002,2003 Philippe Gerum <rpm@xenomai.org>.
 *
 * Xenomai is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * Xenomai is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Xenomai; if not, write to the Free Software Foundation,
 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * As a special exception, the RTAI project gives permission
 * for additional uses of the text contained in its release of
 * Xenomai.
 *
 * The exception is that, if you link the Xenomai libraries with other
 * files to produce an executable, this does not by itself cause the
 * resulting executable to be covered by the GNU General Public License.
 * Your use of that executable is in no way restricted on account of
 * linking the Xenomai libraries code into it.
 *
 * This exception does not however invalidate any other reasons why
 * the executable file might be covered by the GNU General Public
 * License.
 *
 * This exception applies only to the code released by the
 * RTAI project under the name Xenomai.  If you copy code from other
 * RTAI project releases into a copy of Xenomai, as the General Public
 * License permits, the exception does not apply to the code that you
 * add in this way.  To avoid misleading anyone as to the status of
 * such modified files, you must delete this exception notice from
 * them.
 *
 * If you write modifications of your own for Xenomai, it is your
 * choice whether to permit this exception to apply to your
 * modifications. If you do not wish that, delete this exception
 * notice.
 */

#include <sys/types.h>
#include <sys/mman.h>
#include <stdio.h>
#include <memory.h>
#include <errno.h>
#include <unistd.h>
#include <xenomai/fusion.h>

static int __fusion_muxid;

static xnsysinfo_t __fusion_info;

static inline int __init_skin (void)

{
    __fusion_muxid = XENOMAI_SYSCALL2(__xn_sys_attach,FUSION_SKIN_MAGIC,&__fusion_info);
    return __fusion_muxid;
}

/* Public RTAI/fusion interface. */

int pthread_info_rt (xnsysinfo_t *infop)

{
    if (__fusion_muxid == 0 && __init_skin() < 0)
	return -1;

    memcpy(infop,&__fusion_info,sizeof(*infop));

    return 0;
}

int pthread_init_rt (const char *name, void *uhandle, void **khandlep)

{
    char stack[32768];

    if (__fusion_muxid == 0 && __init_skin() < 0)
	return -1;

    XENOMAI_SYSCALL1(__xn_sys_migrate,0);

    mlockall(MCL_CURRENT|MCL_FUTURE);
    memset(stack,0,sizeof(stack));

    /* Move the current thread into the RTAI realm. */
    return XENOMAI_SKINCALL3(__fusion_muxid,__xn_fusion_init,name,khandlep,uhandle);
}

int pthread_create_rt (const char *name,
		       void *uhandle,
		       pid_t syncpid,
		       int *syncp,
		       void **khandlep)
{
    char stack[32768];

    if (__fusion_muxid == 0 && __init_skin() < 0)
	return -1;

    XENOMAI_SYSCALL1(__xn_sys_migrate,0);

    mlockall(MCL_CURRENT|MCL_FUTURE);
    memset(stack,0,sizeof(stack));

    /* Move the current thread into the RTAI realm. */
    return XENOMAI_SKINCALL5(__fusion_muxid,__xn_fusion_create,name,khandlep,uhandle,syncpid,syncp);
}

int pthread_start_rt (void *khandle) {

    return XENOMAI_SKINCALL1(__fusion_muxid,__xn_fusion_start,khandle);
}

int pthread_sync_rt (int *syncp)

{
    XENOMAI_SYSCALL1(__xn_sys_migrate,0);
    return XENOMAI_SYSCALL1(__xn_sys_sync,syncp);
}

int pthread_time_rt (unsigned long long *tp) {

    return XENOMAI_SKINCALL1(__fusion_muxid,__xn_fusion_time,tp);
}

int pthread_inquire_rt (xninquiry_t *buf) {

    return XENOMAI_SKINCALL1(__fusion_muxid,__xn_fusion_inquire,buf);
}

int pthread_migrate_rt (int domain) {

    return XENOMAI_SKINCALL1(__fusion_muxid,__xn_fusion_migrate,domain);
}

/* Private RTAI/vm interface. */

int __pthread_idle_vm (int *lockp) {

    return XENOMAI_SKINCALL1(__fusion_muxid,__xn_fusion_idle,lockp);
}

int __pthread_cancel_vm (void *deadhandle, void *nexthandle) {

    return XENOMAI_SKINCALL2(__fusion_muxid,__xn_fusion_cancel,deadhandle,nexthandle);
}

int __pthread_activate_vm (void *nexthandle, void *prevhandle) {

    return XENOMAI_SKINCALL2(__fusion_muxid,__xn_fusion_activate,nexthandle,prevhandle);
}

int __pthread_hold_vm (int *pendp) {

    return XENOMAI_SKINCALL1(__fusion_muxid,__xn_fusion_hold,pendp);
}

int __pthread_release_vm (int *lockp) {

    return XENOMAI_SKINCALL1(__fusion_muxid,__xn_fusion_release,lockp);
}