seperate type declaration and implementation
This commit is contained in:
parent
187df97227
commit
78cd455b20
4 changed files with 101 additions and 19 deletions
|
@ -21,7 +21,7 @@
|
|||
#define __MAILBOX_H__
|
||||
|
||||
#include <metalsvm/string.h>
|
||||
#include <metalsvm/tasks.h>
|
||||
#include <metalsvm/mailbox_types.h>
|
||||
#include <metalsvm/semaphore.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
@ -29,14 +29,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
#define MAILBOX(name, type) \
|
||||
typedef struct mailbox_##name { \
|
||||
type buffer[MAILBOX_SIZE]; \
|
||||
int wpos, rpos; \
|
||||
sem_t mails; \
|
||||
sem_t boxes; \
|
||||
spinlock_t rlock, wlock; \
|
||||
} mailbox_##name##_t; \
|
||||
\
|
||||
inline static int mailbox_##name##_init(mailbox_##name##_t* m) { \
|
||||
if (BUILTIN_EXPECT(!m, 0)) \
|
||||
return -1; \
|
||||
|
@ -106,6 +98,7 @@ extern "C" {
|
|||
return 0; \
|
||||
}\
|
||||
|
||||
MAILBOX(wait_msg, wait_msg_t)
|
||||
MAILBOX(int32, int32_t)
|
||||
MAILBOX(int16, int16_t)
|
||||
MAILBOX(int8, int8_t)
|
||||
|
|
56
include/metalsvm/mailbox_types.h
Normal file
56
include/metalsvm/mailbox_types.h
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
|
||||
* RWTH Aachen University
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of MetalSVM.
|
||||
*/
|
||||
|
||||
#ifndef __MAILBOX_TYPES_H__
|
||||
#define __MAILBOX_TYPES_H__
|
||||
|
||||
#include <metalsvm/semaphore_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
tid_t id;
|
||||
int32_t result;
|
||||
} wait_msg_t;
|
||||
|
||||
#define MAILBOX_TYPES(name, type) \
|
||||
typedef struct mailbox_##name { \
|
||||
type buffer[MAILBOX_SIZE]; \
|
||||
int wpos, rpos; \
|
||||
sem_t mails; \
|
||||
sem_t boxes; \
|
||||
spinlock_t rlock, wlock; \
|
||||
} mailbox_##name##_t;
|
||||
|
||||
MAILBOX_TYPES(wait_msg, wait_msg_t)
|
||||
MAILBOX_TYPES(int32, int32_t)
|
||||
MAILBOX_TYPES(int16, int16_t)
|
||||
MAILBOX_TYPES(int8, int8_t)
|
||||
MAILBOX_TYPES(uint32, uint32_t)
|
||||
MAILBOX_TYPES(uint16, uint16_t)
|
||||
MAILBOX_TYPES(uint8, uint8_t)
|
||||
MAILBOX_TYPES(ptr, void*)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -21,22 +21,13 @@
|
|||
#define __SEMAPHORE_H__
|
||||
|
||||
#include <metalsvm/string.h>
|
||||
#include <metalsvm/tasks.h>
|
||||
#include <metalsvm/semaphore_types.h>
|
||||
#include <metalsvm/spinlock.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
unsigned int value;
|
||||
tid_t queue[MAX_TASKS];
|
||||
unsigned int pos;
|
||||
spinlock_t lock;
|
||||
} sem_t;
|
||||
|
||||
#define SEM_INIT(v) {v, {[0 ... MAX_TASKS-1] = MAX_TASKS}, 0, SPINLOCK_INIT}
|
||||
|
||||
inline static int sem_init(sem_t* s, unsigned int v) {
|
||||
unsigned int i;
|
||||
|
||||
|
|
42
include/metalsvm/semaphore_types.h
Normal file
42
include/metalsvm/semaphore_types.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright 2010 Stefan Lankes, Chair for Operating Systems,
|
||||
* RWTH Aachen University
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* This file is part of MetalSVM.
|
||||
*/
|
||||
|
||||
#ifndef __SEMAPHORE_TYPES_H__
|
||||
#define __SEMAPHORE_TYPES_H__
|
||||
|
||||
#include <metalsvm/spinlock_types.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
unsigned int value;
|
||||
tid_t queue[MAX_TASKS];
|
||||
unsigned int pos;
|
||||
spinlock_t lock;
|
||||
} sem_t;
|
||||
|
||||
#define SEM_INIT(v) {v, {[0 ... MAX_TASKS-1] = MAX_TASKS}, 0, SPINLOCK_INIT}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Loading…
Add table
Reference in a new issue