diff --git a/executablecode/Makefile b/executablecode/Makefile index 2a513488f83a4a18479463c2e4e9ca37a2533a3f..c76b0fa419c3c09c798e1441761cdbd0dfc4dcd6 100755 --- a/executablecode/Makefile +++ b/executablecode/Makefile @@ -20,7 +20,7 @@ OBJDIR = lib MODULE = run SRCS_generated_DIR = generated_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_DIRSRC = src/ OBJS_executor = $(SRCS_base:%.c=lib/%.o) diff --git a/executablecode/generated_src/main.c b/executablecode/generated_src/main.c index 13f6f769249ea6b8507110a031c7a164ac3eafca..510fee7c6d0fc5d1408101253acab3a500389023 100644 --- a/executablecode/generated_src/main.c +++ b/executablecode/generated_src/main.c @@ -4,9 +4,11 @@ #include <stdlib.h> #include "request.h" +#include "syncchannel.h" #include "debug.h" +syncchannel * syncchannels[1]; void *send(void *arg) { @@ -62,6 +64,9 @@ void *receive(void *arg) { int main(int argc, char * argv[]) { + + syncchannels[0] = getNewSyncchannel("outch", "inch"); + pthread_t sender; pthread_t receiver0, receiver1; diff --git a/executablecode/src/asyncchannel.c b/executablecode/src/asyncchannel.c new file mode 100644 index 0000000000000000000000000000000000000000..6bc670b17bf7d5672e3bc190716456d6c31c44e4 --- /dev/null +++ b/executablecode/src/asyncchannel.c @@ -0,0 +1,19 @@ +#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); +} diff --git a/executablecode/src/asyncchannel.h b/executablecode/src/asyncchannel.h new file mode 100644 index 0000000000000000000000000000000000000000..6d0d37bb1f6890e60d93b588c49a424540905f3d --- /dev/null +++ b/executablecode/src/asyncchannel.h @@ -0,0 +1,29 @@ +#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 diff --git a/executablecode/src/message.c b/executablecode/src/message.c new file mode 100644 index 0000000000000000000000000000000000000000..6c7eef7200ca50982691eb790f8d15902261030f --- /dev/null +++ b/executablecode/src/message.c @@ -0,0 +1,25 @@ + +#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); +} diff --git a/executablecode/src/message.h b/executablecode/src/message.h new file mode 100644 index 0000000000000000000000000000000000000000..f67236fd9d711aa3db4cf81917686d685a017d22 --- /dev/null +++ b/executablecode/src/message.h @@ -0,0 +1,23 @@ +#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 diff --git a/executablecode/src/request.c b/executablecode/src/request.c new file mode 100644 index 0000000000000000000000000000000000000000..12c38cca93632df44379e31c48f4df5b18ab2593 --- /dev/null +++ b/executablecode/src/request.c @@ -0,0 +1,20 @@ + +#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); +} diff --git a/executablecode/src/request.h b/executablecode/src/request.h new file mode 100644 index 0000000000000000000000000000000000000000..cb4d0d009b63a4295014ab25e0a9c9165d2466f6 --- /dev/null +++ b/executablecode/src/request.h @@ -0,0 +1,33 @@ +#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 diff --git a/executablecode/src/syncchannel.c b/executablecode/src/syncchannel.c new file mode 100644 index 0000000000000000000000000000000000000000..e345e7c1da5fa809c0c94588d90a10c0c185e2cf --- /dev/null +++ b/executablecode/src/syncchannel.c @@ -0,0 +1,19 @@ +#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); +} diff --git a/executablecode/src/syncchannel.h b/executablecode/src/syncchannel.h new file mode 100644 index 0000000000000000000000000000000000000000..b9d9baea404f532dec05949ec51a8aafd6c0046c --- /dev/null +++ b/executablecode/src/syncchannel.h @@ -0,0 +1,19 @@ +#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