gmisc.c
1.91 KB
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
#ifdef NOT_NEEDED
#include "gdisplay.h"
#endif
#include <stdio.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/sem.h>
#include "ms_sync.h"
#include "vcsuser.h"
#define N_CHANNELS 16
static char * sh = 0;
static int s0 = 0;
gb_init(a,b)
{
int i,n,size,key;
key = tf_getp(3);
size = tf_getp(2);
n = tf_getp(1);
#ifdef DEBUG
fprintf(stderr,"gb_init(n = %d, size = %d, key = %d)\n", n, size, key);
#endif
s0 = shmget(key,size+sizeof(ms_sync_t),IPC_CREAT|0600);
if(s0 == -1)
{
perror("Error getting shared memory\n");
exit(1);
}
sh = shmat(s0,0,0);
if((int)sh == -1)
{
perror("Error attaching to shared memory");
exit(1);
}
ms = (ms_sync_t *)((long)sh+size);
if(n>=0)
ms_init_slave(n);
else
ms_init_master(-n-1);
}
gb_get(a,b)
{
struct t_tfexprinfo ee;
long ptr;
int i,n;
ptr = tf_getp(2);
tf_exprinfo(1,&ee);
n = ee.expr_ngroups;
#ifdef DEBUG
fprintf(stderr,"gb_get(n = %d, ptr = %d)\n", n, ptr);
#endif
for(i=0;i<n;i++)
{
ee.expr_value_p[i].avalbits = *(int *)((long)sh+ptr+i*4);
ee.expr_value_p[i].bvalbits = 0;
#ifdef DEBUG
fprintf(stderr,"gb_get(avalbits = %d, bvalbits = %d)\n",
ee.expr_value_p[i].avalbits, ee.expr_value_p[i].bvalbits);
#endif
}
tf_propagatep(1);
}
gb_put(a,b)
{
struct t_tfexprinfo ee;
long ptr;
int i,n;
ptr = tf_getp(1);
tf_exprinfo(2,&ee);
n = ee.expr_ngroups;
#ifdef DEBUG
fprintf(stderr,"gb_put(n = %d, ptr = %d)\n", n, ptr);
#endif
for(i=0;i<n;i++)
{
*(int *)((long)sh+ptr+i*4) = ee.expr_value_p[i].avalbits;
#ifdef DEBUG
fprintf(stderr,"gb_put(val = %d)\n", ee.expr_value_p[i].avalbits);
#endif
}
}
gb_sync(a,b)
{
int a0;
a0 = tf_getp(1);
#ifdef DEBUG
fprintf(stderr,"gb_sync(a0 = %d)\n", a0);
#endif
if(a0>=0)
ms_slave_sync(a0);
else
ms_master_sync(-a0-1);
}
int gb_rmid(a,b)
{
if(sh)
shmdt(sh);
if(s0>=0)
shmctl(s0,IPC_RMID,0);
}