提交 | 用户 | age
|
3bd1f2
|
1 |
// Copyright 2016 Tom Thorogood. All rights reserved. |
Z |
2 |
// Use of this source code is governed by a |
|
3 |
// Modified BSD License license that can be found in |
|
4 |
// the LICENSE file. |
|
5 |
|
|
6 |
// +build !linux !386,!amd64 |
|
7 |
|
|
8 |
package shm |
|
9 |
|
|
10 |
/* |
|
11 |
#include <stdint.h> // For (u)int*_t |
|
12 |
#include <semaphore.h> // For sem_* |
|
13 |
|
|
14 |
typedef struct { |
|
15 |
uint32_t Next; |
|
16 |
uint32_t Prev; |
|
17 |
|
|
18 |
uint32_t DoneRead; |
|
19 |
uint32_t DoneWrite; |
|
20 |
|
|
21 |
uint64_t Size; |
|
22 |
|
|
23 |
uint8_t Flags[(0x40-(2*2*sizeof(uint32_t)+sizeof(uint64_t))&0x3f)&0x3f]; |
|
24 |
|
|
25 |
uint8_t Data[]; |
|
26 |
} shared_block_t; |
|
27 |
|
|
28 |
typedef struct { |
|
29 |
uint32_t Version; |
|
30 |
uint32_t __padding0; |
|
31 |
|
|
32 |
uint32_t BlockCount; |
|
33 |
uint32_t __padding1; |
|
34 |
|
|
35 |
uint64_t BlockSize; |
|
36 |
|
|
37 |
uint32_t ReadStart; |
|
38 |
uint32_t ReadEnd; |
|
39 |
|
|
40 |
uint32_t WriteStart; |
|
41 |
uint32_t WriteEnd; |
|
42 |
|
|
43 |
sem_t SemSignal; |
|
44 |
sem_t SemAvail; |
|
45 |
|
|
46 |
uint32_t Flags[((0x40-(4*2*sizeof(uint32_t)+sizeof(uint64_t)+2*sizeof(sem_t))&0x3f)&0x3f)/4]; |
|
47 |
|
|
48 |
shared_block_t Blocks[]; |
|
49 |
} shared_mem_t; |
|
50 |
*/ |
|
51 |
import "C" |
|
52 |
|
|
53 |
type sharedBlock C.shared_block_t |
|
54 |
|
|
55 |
type sharedMem C.shared_mem_t |
|
56 |
|
|
57 |
const ( |
|
58 |
sharedHeaderSize = C.sizeof_shared_mem_t |
|
59 |
sharedFlagsSize = len(sharedMem{}.Flags) |
|
60 |
blockHeaderSize = C.sizeof_shared_block_t |
|
61 |
blockFlagsSize = len(sharedBlock{}.Flags) |
|
62 |
|
|
63 |
version = uint32((^uint(0)>>32)&0x80000000) | 0x00000001 |
|
64 |
) |