Mercurial > hg > Members > kono > Cerium
diff Renderer/Engine/lindaapi.cc @ 606:32a7260fad2f
32bit/64bit ABI (64 bit is not tested yet).
64bit ABI requires 64bit SDL library etc.
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 07 Nov 2009 18:05:52 +0900 |
parents | 90c61fe2b109 |
children | 0decff4e867b |
line wrap: on
line diff
--- a/Renderer/Engine/lindaapi.cc Sat Nov 07 17:42:21 2009 +0900 +++ b/Renderer/Engine/lindaapi.cc Sat Nov 07 18:05:52 2009 +0900 @@ -20,7 +20,7 @@ #include <arpa/inet.h> #include "lindaapi.h" -#if 0 + #if 0 #define PSX_Debug(deb) (putchar(PS_DEB)),\ @@ -42,7 +42,7 @@ /* Static Functions */ static void unix_chkserv(int ps); void psx_free(void *); -static int psx_queue(unsigned int tspace_id, unsigned int id, +static long psx_queue(unsigned int tspace_id, unsigned int id, unsigned int size, unsigned char *data, char mode, void(*callback)(unsigned char *,void *),void * obj); @@ -314,10 +314,10 @@ 返り値: シーケンス番号 /-------------------------------------------------------------------*/ -int +long psx_out(unsigned int tspace_id, unsigned int id, unsigned char *data, unsigned int size){ - int r; + long r; if ((r = psx_queue(tspace_id, id, size, data, 'o', NULL, NULL)) == FAIL) { return(FAIL); } @@ -343,10 +343,10 @@ 返り値: psx_queue内でmallocされたREPLY構造体へのポインタ /-------------------------------------------------------------------*/ -int +long psx_ld(unsigned int tspace_id, unsigned int id, char mode, void(*callback)(unsigned char *,void *), void * obj){ - int r; + long r; if ((r = psx_queue(tspace_id, id, 0, NULL, mode, callback, obj)) == FAIL) { return(FAIL); } @@ -371,7 +371,6 @@ DEB(fprintf(stdout, "psx_reply: search of seq = %d\n", seq)); PSX_Debug(("psx_reply: seq %d", seq)); - // linear search なの? for(q = NULL,p = reply; p; q = p,p = p->next){ if (p->seq == seq){ DEB(fprintf(stdout, "psx_reply: match of seq = %d\n", seq)); @@ -450,7 +449,7 @@ } /*-------------------------------------------------------------------/ - static long + static int psx_queue (unsigned int tspace_id, unsigned int id, unsigned int size, unsigned char *data, char mode, void(*callback)(char*,void*), void * obj): @@ -472,7 +471,7 @@ 0が返る。 失敗した場合 - FAIL(-1)が返る。 /-------------------------------------------------------------------*/ -static int +static long psx_queue(unsigned int tspace_id, unsigned int id, unsigned int size, unsigned char *data, char mode, void(*callback)(unsigned char *,void *), void * obj){ @@ -507,14 +506,18 @@ /* データ受け取り要求(in,rd,wait)なら受け取り用の箱を用意 */ if (mode != 'o') { if (reply == NULL){ - reply = new_reply(); + if ((reply = (REPLY *) malloc (sizeof(REPLY))) == NULL){ + return(FAIL); + } p = r_end = reply; p->next = NULL; } else { - r_end->next = new_reply(); + if ((r_end->next = (REPLY *) malloc (sizeof(REPLY))) == NULL){ + return(FAIL); + } p = r_end->next; r_end = p; p->next = NULL; } p->mode = '?'; - p->seq = p->reply_id; + p->seq = (long)p; // 構造体のアドレスで識別 p->callback = callback; p->obj = obj; PSX_Debug(("psx_queue: seq %d reply %x p %x r_end %x",seq,reply,p,r_end)); @@ -530,7 +533,11 @@ q_end->command[LINDA_SEQ_OFFSET+1] = ((long)p>>16) & 0xff; q_end->command[LINDA_SEQ_OFFSET+2] = ((long)p>>8) & 0xff; q_end->command[LINDA_SEQ_OFFSET+3] = ((long)p) & 0xff; - + + q_end->command[LINDA_DATA_LENGTH_OFFSET] = (size>>24) & 0xff; + q_end->command[LINDA_DATA_LENGTH_OFFSET+1] = (size>>16) & 0xff; + q_end->command[LINDA_DATA_LENGTH_OFFSET+2] = (size>>8) & 0xff; + q_end->command[LINDA_DATA_LENGTH_OFFSET+3] = (size) & 0xff; q_end->size = size+LINDA_HEADER_SIZE; /* command size */ q_end->tspace_id = tspace_id; /* destination id */ @@ -713,139 +720,4 @@ - -static ReplyPtr freeReply; /* Free Pool of Reply */ -static ReplyPtr replyPool; /* List of malloced free Reply */ - -static ReplyPtr extend_reply_pool(int num); - -static const int QUEUE_MALLOC_ERROR = 10; -static const int POOL_SIZE_OVER_ERROR = 11; - -static int reply_errno; - -// -// Initialize Reply Pool -// return NULL on error -// - -static ReplyPtr -init_reply(int num) -{ - ReplyPtr q; - if (! replyPool) { - return extend_reply_pool(num); - } - return replyPool; -} - -static ReplyPtr -extend_reply_pool(int num) -{ - ReplyPtr q; - // Keep malloc history in ReplyPool - q = (ReplyPtr) malloc(sizeof(Reply) * (num+1)); - if (!q) { - reply_errno = QUEUE_MALLOC_ERROR; - retrun q; - } - q->next = replyPool; - replyPool = q; - // Connect all free reply in the pool - q = queeuePool + 1; - for(q = replyPool+1; num-->0; q++) q->next = q+1; - q->next = freeReply; - freeReply = replyPool+1; - return replyPool; -} - -static void -destory_reply() -{ - ReplyPtr q; - for(q = replyPool ;q; q = q->next) { - free(q); - } - freeReply = replyPool = NULL; -} - -static ReplyPtr -new_reply(int priority, int task) -{ - ReplyPtr q; - if (!freeReply) { - pool_size *= 2; - if (pool_size > MAX_POOL_SIZE) { - reply_errno = POOL_SIZE_OVER_ERROR; - return NULL; - } - if (!extend_reply_pool(pool_size)) { - return NULL; - } - } - q = freeReply; - freeReply = freeReply->next; - q->next = NULL; - q->priority = priority; - q->task = task; - return q; -} - -static void -free_reply(ReplyPtr q) -{ - q->next = freeReply; - freeReply = q; -} - -static TaskListPtr -new_task_list(char *name) -{ - TaskLilstPtr task; - task = (TaskListPtr) malloc(sizeof(TaskList)); - task->reply = NULL; - task->name = name; -} - -static void -free_task_list(TaskListPtr task) -{ - free(task); -} - -static void -insert_reply(TaskListPtr list,ReplyPtr q) -{ - q->next = list->reply; - list->reply = q; -} - -static void -qppend_reply(TaskListPtr list,ReplyPtr q) -{ - ReplyPtr p = list->reply; - while(p->next) p = p->next; - p->next = q; -} - -static void -remove_reply(TaskListPtr list,ReplyPtr q) -{ - ReplyPtr p = list->reply; - ReplyPtr p1 = p->next; - - while(p1 && p1 != q) { p1 = p1->next; p = p->next; } - if (p1) { - p->next = p1->next; - } -} - -#else - -void -psx_sync_n(){ -} - -#endif - /* end */