Skip to content
Snippets Groups Projects
Commit 7af3a044 authored by Ludovic Apvrille's avatar Ludovic Apvrille
Browse files

new header and code files

parent c8fcb752
Branches minh-cpu_node_help
No related tags found
No related merge requests found
...@@ -20,7 +20,7 @@ OBJDIR = lib ...@@ -20,7 +20,7 @@ OBJDIR = lib
MODULE = run MODULE = run
SRCS_generated_DIR = generated_src/ SRCS_generated_DIR = generated_src/
include Makefile.src include Makefile.src
SRCS_base = src/transactions.c src/syncchannel.c src/timers.c src/myerrors.c src/debug.c src/storeevents.c SRCS_base = src/request.c src/message.c src/myerrors.c src/debug.c src/syncchannel.c src/asyncchannel.c
SRCS_base_DIR = . SRCS_base_DIR = .
SRCS_base_DIRSRC = src/ SRCS_base_DIRSRC = src/
OBJS_executor = $(SRCS_base:%.c=lib/%.o) OBJS_executor = $(SRCS_base:%.c=lib/%.o)
......
...@@ -4,9 +4,11 @@ ...@@ -4,9 +4,11 @@
#include <stdlib.h> #include <stdlib.h>
#include "request.h" #include "request.h"
#include "syncchannel.h"
#include "debug.h" #include "debug.h"
syncchannel * syncchannels[1];
void *send(void *arg) { void *send(void *arg) {
...@@ -62,6 +64,9 @@ void *receive(void *arg) { ...@@ -62,6 +64,9 @@ void *receive(void *arg) {
int main(int argc, char * argv[]) { int main(int argc, char * argv[]) {
syncchannels[0] = getNewSyncchannel("outch", "inch");
pthread_t sender; pthread_t sender;
pthread_t receiver0, receiver1; pthread_t receiver0, receiver1;
......
#include <stdlib.h>
#include "asyncchannel.h"
#include "myerrors.h"
asyncchannel *getNewAsyncchannel(char *outname, char *inname, int nbOfParams) {
asyncchannel * asyncch = (asyncchannel *)(malloc(sizeof(struct asyncchannel)));
if (asyncch == NULL) {
criticalError("Allocation of asyncchannel failed");
}
asyncch->inname = inname;
asyncch->outname = outname;
return asyncch;
}
void destroyAsyncchannel(asyncchannel *asyncch) {
free(asyncch);
}
#ifndef ASYNCCHANNEL_H
#define ASYNCCHANNEL_H
#include "request.h"
#include "message.h"
struct asyncchannel;
struct asyncchannel {
char *outname;
char *inname;
int isInfinite;
int isBlocking;
int maxNbOfMssages;
request* outWaitQueue;
request* inWaitQueue;
setOfMessages *pendingMessages;
int nbOfParams;
};
typedef struct asyncchannel asyncchannel;
asyncchannel *getNewAsyncchannel(char *inname, char *outname, int nbOfParams);
void destroyAsyncchannel(asyncchannel *syncch);
#endif
#include <stdlib.h>
#include <unistd.h>
#include "message.h"
#include "myerrors.h"
message *getNewMessage(int nbOfParams, int *params[]) {
int i;
message *msg = (message *)(malloc(sizeof(struct message) + nbOfParams*sizeof(int *) ));
if (msg == NULL) {
criticalError("Allocation of request failed");
}
msg->nbOfParams = nbOfParams;
for(i=0; i<nbOfParams; i++) {
msg->params[i] = params[i];
}
return msg;
}
void *destroyMessage(message *msg) {
free(msg);
}
#ifndef MESSAGE_H
#define MESSAGE_H
struct message;
struct setOfMessages {
struct message *head;
};
typedef struct setOfMessages setOfMessages;
struct message {
int nbOfParams;
int *params[];
};
typedef struct message message;
message * getNewMessage(int nbOfParams, int *params[]);
void *destroyMessage(message *msg);
#endif
#include <stdlib.h>
#include <unistd.h>
#include "request.h"
#include "myerrors.h"
request *getNewRequest(int type) {
request *req = (request *)(malloc(sizeof(struct request)));
if (req == NULL) {
criticalError("Allocation of request failed");
}
req->type = type;
return req;
}
void *destroyRequest(request *req) {
free(req);
}
#ifndef REQUEST_H
#define REQUEST_H
#define SYNC_REQUEST 0
#define SYNC_REQUEST_WITH_DELAY 1
#define ASYNC_REQUEST 2
#define ASYNC_REQUEST_WITH_DELAY 3
#define DELAY 4
struct request;
struct setOfRequests {
struct request *head;
};
typedef struct setOfRequests setOfRequests;
struct request {
int type;
setOfRequests* listOfRequests;
int hasDelay;
long delay;
int delayElapsed;
int nbOfParams;
int *params[];
};
typedef struct request request;
request * getNewRequest(int type);
void *destroyRequest(request *req);
#endif
#include <stdlib.h>
#include "syncchannel.h"
#include "myerrors.h"
syncchannel *getNewSyncchannel(char *outname, char *inname) {
syncchannel * syncch = (syncchannel *)(malloc(sizeof(struct syncchannel)));
if (syncch == NULL) {
criticalError("Allocation of request failed");
}
syncch->inname = inname;
syncch->outname = outname;
return syncch;
}
void destroySyncchannel(syncchannel *syncch) {
free(syncch);
}
#ifndef SYNCCHANNEL_H
#define SYNCCHANNEL_H
#include "request.h"
struct syncchannel {
char *outname;
char *inname;
request* inWaitQueue;
request* outWaitQueue;
};
typedef struct syncchannel syncchannel;
syncchannel *getNewSyncchannel(char *inname, char *outname);
void destroySyncchannel(syncchannel *syncch);
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment