summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexis211 <alexis211@gmail.com>2010-03-26 16:04:01 +0100
committerAlexis211 <alexis211@gmail.com>2010-03-26 16:04:01 +0100
commit50152369119ffc92d7790ddcfd26f32613366ede (patch)
treee40feb305fa435e2d1bf6c60b16e7bd2c00b1c95 /src
parentdbfa8cae66811247e5110e2e17f1c6ae5d1b2bcd (diff)
downloadTCE-50152369119ffc92d7790ddcfd26f32613366ede.tar.gz
TCE-50152369119ffc92d7790ddcfd26f32613366ede.zip
IPC documented, still not tested.
Diffstat (limited to 'src')
-rw-r--r--src/kernel/ipc/object.c2
-rw-r--r--src/kernel/ipc/request.c22
-rw-r--r--src/modules/test/main.c18
3 files changed, 26 insertions, 16 deletions
diff --git a/src/kernel/ipc/object.c b/src/kernel/ipc/object.c
index ea59d28..e381c89 100644
--- a/src/kernel/ipc/object.c
+++ b/src/kernel/ipc/object.c
@@ -107,7 +107,7 @@ int object_create() {
int object_owned(int id) {
struct object *obj = objdesc_read(current_thread->process, id);
- if (obj == 0) return -1;
+ if (obj == 0) return -10;
if (obj->owner == current_thread->process) return 1;
return 0;
}
diff --git a/src/kernel/ipc/request.c b/src/kernel/ipc/request.c
index 25c778a..9e42d6a 100644
--- a/src/kernel/ipc/request.c
+++ b/src/kernel/ipc/request.c
@@ -14,7 +14,7 @@ int request_get(int id, uint32_t ptr, int wait) {
//check if a request is pending. if request is being processed (acknowledged), return -3
if (obj->request != 0 && obj->request->acknowledged != RS_PENDING) return -3;
//if not (busymutex unlocked and request==0) && wait, then wait, else return -1
- if (wait == 0) return -1;
+ if (wait == 0 && obj->request == 0) return -1;
while (obj->busyMutex != MUTEX_LOCKED && (obj->request == 0 || obj->request->acknowledged != RS_PENDING)) thread_sleep(1);
obj->request->acknowledged = RS_PROCESSED;
//when request pending (wait finished), write it to ptr
@@ -95,7 +95,7 @@ int request_mapShm(int id, uint32_t pos, int number) {
if (obj == 0) return -10;
if (obj->owner != current_thread->process) return -2;
//if no request is being processes (including non-acknowledged waiting requests), return -3
- if (obj->request == 0 || obj->request->acknowledged == RS_PENDING || obj->request->requester == 0) return -3;
+ if (obj->request == 0 || obj->request->acknowledged == RS_PENDING) return -3;
//check if the requests should have shm in parameter [number], if not return -4
int n = (obj->request->func >> (28 - (2 * number))) & 3;
if (n != PT_SHM) return -4;
@@ -117,16 +117,20 @@ int request_mapShm(int id, uint32_t pos, int number) {
}
static struct request *mkrequest(int id, struct thread *requester,
- uint32_t func, uint32_t a, uint32_t b, uint32_t c) {
+ uint32_t func, uint32_t a, uint32_t b, uint32_t c, uint32_t *err) {
int i;
// get object from descriptor id, if none return 0
struct object *obj = objdesc_read(current_thread->process, id);
- if (obj == 0) return 0;
+ if (obj == 0) {
+ *err = -10;
+ return 0;
+ }
// waitlock object's busy mutex
mutex_lock(&obj->busyMutex);
// if object cannot answer (owner == 0) return 0
if (obj->owner == 0) {
mutex_unlock(&obj->busyMutex);
+ *err = -11;
return 0;
}
// create request, fill it up :
@@ -176,10 +180,13 @@ static struct request *mkrequest(int id, struct thread *requester,
}
int request(int obj, uint32_t rq_ptr) {
+ uint32_t e = 0;
+
struct user_sendrequest *urq = (void*)rq_ptr;
//call mkrequest with parameters (requester thread = current thread)
- struct request *rq = mkrequest(obj, current_thread, urq->func, urq->a, urq->b, urq->c);
+ struct request *rq = mkrequest(obj, current_thread, urq->func, urq->a, urq->b, urq->c, &e);
//if returned value is 0 (could not create request), return -1
+ if (e != 0) return e;
if (rq == 0) return -1;
//sleep until request is handled
thread_goInactive();
@@ -199,10 +206,13 @@ int request(int obj, uint32_t rq_ptr) {
}
int send_msg(int obj, uint32_t rq_ptr) {
+ uint32_t e = 0;
+
struct user_sendrequest *urq = (void*)rq_ptr;
//call mkrequest with parameters (requester thread = 0)
- struct request *rq = mkrequest(obj, 0, urq->func, urq->a, urq->b, urq->c);
+ struct request *rq = mkrequest(obj, 0, urq->func, urq->a, urq->b, urq->c, &e);
//if returned value is 0, return -1 else return 0
+ if (e != 0) return e;
if (rq == 0) return -1;
return 0;
}
diff --git a/src/modules/test/main.c b/src/modules/test/main.c
index d2a4692..df8b2ef 100644
--- a/src/modules/test/main.c
+++ b/src/modules/test/main.c
@@ -5,33 +5,33 @@
int obj = -1;
void thread2(void* d) {
- printk("[module:test:2] Creating new object...\n");
+ printk("[test:2] Creating new object...\n");
obj = object_create();
struct user_request rq;
while (1) {
- printk("[module:test:2] Waiting for a request...\n");
+ printk("[test:2] Waiting for a request...\n");
request_get(obj, &rq, 1);
if (rq.isBlocking) {
- printk("[module:test:2] Got request. Answering...\n");
+ printk("[test:2] Got request. Answering...\n");
request_answer(obj, 42, 0);
} else {
- printk("[module:test:2] Got message. Ignoring it.\n");
+ printk("[test:2] Got message. Ignoring it.\n");
}
}
}
int main() {
- printk("[module:test:1] Hi world !\n");
- printk("[module:test:1] Creating new thread...\n");
+ printk("[test:1] Hi world !\n");
+ printk("[test:1] Creating new thread...\n");
thread_new(thread2, 0);
while (obj == -1);
- printk("[module:test:1] Object was created. Sending request...\n");
+ printk("[test:1] Object was created. Sending request...\n");
struct user_sendrequest sr;
sr.func = 0x80000001;
request(obj, &sr);
- printk("[module:test:1] Got answer. Sending message...\n");
+ printk("[test:1] Got answer. Sending message...\n");
send_msg(obj, &sr);
- printk("[module:test:1] HAHA !!! Death in 10 seconds!\n");
+ printk("[test:1] HAHA !!! Death in 10 seconds!\n");
thread_sleep(10000);
return 0;
}