Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

update

Signed-off-by: yayanyang <yayanyang@gmail.com>
  • Loading branch information...
commit b39ababd320b5516c7c87fd347cf653fdb2308b5 1 parent f45cb39
yayanyang authored
View
5 message/CMakeLists.txt
@@ -0,0 +1,5 @@
+lemon_c_cxx_files(SRC)
+
+lemon_library_project(lemon-message ${SRC})
+
+target_link_libraries(lemon-message lemon-io lemon-sys lemon-memory lemonxx)
View
0  message/abi.cpp
No changes.
View
141 message/abi.h
@@ -0,0 +1,141 @@
+/**
+ *
+ * @file abi
+ * @brief Copyright (C) 2012 yayanyang All Rights Reserved
+ * @author yayanyang
+ * @version 1.0.0.0
+ * @date 2012/09/01
+ */
+#ifndef LEMON_MESSAGE_ABI_H
+#define LEMON_MESSAGE_ABI_H
+
+#include <lemon/sys/abi.h>
+#include <lemon/message/configure.h>
+
+LEMON_DECLARE_HANDLE(LemonMessage);
+
+LEMON_DECLARE_HANDLE(LemonMailBox);
+
+LEMON_DECLARE_HANDLE(LemonMessageService);
+
+#define LEMON_mailbox_RESPONDER 0x01
+
+#define LEMON_mailbox_REQUESTER 0x02
+
+#define LEMON_mailbox_PUBLISHER 0x03
+
+#define LEMON_mailbox_SUBSCRIBER 0x04
+
+#define LEMON_mailbox_PUSH 0x05
+
+#define LEMON_mailbox_PULL 0x06
+
+LEMON_MESSAGE_API
+ LemonMailBox
+ LemonCreateMailBox(
+ __lemon_in LemonMessageService service,
+ __lemon_in size_t type,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+LEMON_MESSAGE_API
+ void
+ LemonCloseMailBox(
+ __lemon_free LemonMailBox mailbox);
+
+LEMON_MESSAGE_API
+ void
+ LemonmailboxBind(
+ __lemon_in LemonMailBox mailbox,
+ __lemon_in const char * url,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+
+LEMON_MESSAGE_API
+ void
+ LemonmailboxConnect(
+ __lemon_in LemonMailBox mailbox,
+ __lemon_in const char * url,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+LEMON_MESSAGE_API
+ void
+ LemonSendMessage(
+ __lemon_in LemonMailBox mailbox,
+ __lemon_in LemonMessage msg,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+LEMON_MESSAGE_API
+ LemonMessage
+ LemonReceiveMessage(
+ __lemon_in LemonMailBox mailbox,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+
+typedef void(*LemonmailboxCallback)(void * userdata,LemonMessage msg,const LemonErrorInfo * errorCode);
+
+LEMON_MESSAGE_API
+ void
+ LemonAsyncReceiveMessage(
+ __lemon_in LemonMailBox mailbox,
+ __lemon_in LemonmailboxCallback callback,
+ __lemon_in void * userdata,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+LEMON_MESSAGE_API
+ void
+ LemonAsyncSendMessage(
+ __lemon_in LemonMailBox mailbox,
+ __lemon_in LemonMessage msg,
+ __lemon_in LemonmailboxCallback callback,
+ __lemon_in void * userdata,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+//////////////////////////////////////////////////////////////////////////
+LEMON_MESSAGE_API
+ LemonMessageService
+ LemonCreateMessageService(
+ __lemon_in size_t maxMessages,
+ __lemon_in size_t workThreads,
+ __lemon_inout LemonErrorInfo errorCode);
+
+LEMON_MESSAGE_API
+ void
+ LemonCloseMessageService(
+ __lemon_free LemonMessageService service);
+
+LEMON_MESSAGE_API
+ LemonMessage
+ LemonCreateMessage(
+ __lemon_in LemonMessageService service,
+ __lemon_inout LemonErrorInfo * errorCode);
+
+LEMON_MESSAGE_API
+ void LemonCloseMessage(
+ __lemon_in LemonMessageService service,
+ __lemon_free LemonMessage message);
+
+LEMON_MESSAGE_API size_t LemonMessageLength(__lemon_in LemonMessage message);
+
+LEMON_MESSAGE_API
+ size_t
+ LemonMessageWrite(
+ __lemon_in LemonMessage message,
+ __lemon_in const void * data,
+ __lemon_in size_t length,
+ __lemon_inout LemonErrorInfo *errorCode);
+
+LEMON_MESSAGE_API
+ size_t
+ LemonMessageRead(
+ __lemon_in LemonMessage message,
+ __lemon_in void * data,
+ __lemon_in size_t length,
+ __lemon_inout LemonErrorInfo *errorCode);
+
+LEMON_MESSAGE_API
+ size_t LemonMessageSeek(
+ __lemon_in LemonMessage message,
+ __lemon_in int offset,
+ __lemon_in size_t position);
+
+#endif // LEMON_MESSAGE_ABI_H
View
9 message/assemblyinfo.lua
@@ -0,0 +1,9 @@
+assembly=
+{
+ name = "lemon-message";
+
+ errorcode =
+ {
+
+ };
+}
View
0  message/node.hpp
No changes.
View
0  message/publisher.cpp
No changes.
View
0  message/publisher.hpp
No changes.
View
0  message/pull.cpp
No changes.
View
0  message/pull.hpp
No changes.
View
0  message/push.cpp
No changes.
View
0  message/push.hpp
No changes.
View
0  message/requester.cpp
No changes.
View
0  message/requester.hpp
No changes.
View
0  message/responder.cpp
No changes.
View
0  message/responder.hpp
No changes.
View
0  message/subscriber.cpp
No changes.
View
0  message/subscriber.hpp
No changes.
View
0  message/url.cpp
No changes.
View
5 play/CMakeLists.txt
@@ -1,5 +0,0 @@
-lemon_c_cxx_files(SRC)
-
-lemon_library_project(lemon-play ${SRC})
-
-target_link_libraries(lemon-play lemon-sys lemon-memory)
View
33 play/abi.h
@@ -1,33 +0,0 @@
-/**
-*
-* @file abi
-* @brief Copyright (C) 2012 yayanyang All Rights Reserved
-* @author yayanyang
-* @version 1.0.0.0
-* @date 2012/03/23
-*/
-#ifndef LEMON_PLAY_ABI_H
-#define LEMON_PLAY_ABI_H
-#include <lemon/sys/abi.h>
-#include <lemon/play/configure.h>
-
-typedef lemon_uint64_t LemonActor;
-
-typedef struct LemonActorId{
- lemon_uint32_t Id;
- lemon_uint32_t RunQueneId;
-} LemonActorId;
-
-LEMON_DECLARE_HANDLE(LemonPlay);
-
-LEMON_DECLARE_HANDLE(LemonPlayIRQ);
-
-LEMON_DECLARE_HANDLE(LemonPlayRunQueue);
-
-typedef void(*LemonActorProc)(LemonPlay play,void *uerData);
-
-#define LEMON_PLAY_NULL_ACTOR ((LemonActor)-1)
-
-#define LEMON_PLAY_COROUTINE_STACKSIZE 0
-
-#endif //LEMON_PLAY_ABI_H
View
58 play/irq.h
@@ -1,58 +0,0 @@
-/**
-*
-* @file IRQ(...)
-* @brief Copyright (C) 2012 yayanyang All Rights Reserved
-* @author yayanyang
-* @version 1.0.0.0
-* @date 2012/03/23
-*/
-#ifndef LEMON_PLAY_IRQ_H
-#define LEMON_PLAY_IRQ_H
-
-#include <lemon/play/abi.h>
-#define LEMON_PLAY_IRQ_MAX_LEVEL 0x01
-
-#define LEMON_PLAY_IRQ_PASSIVE_LEVEL 0x00
-
-
-//////////////////////////////////////////////////////////////////////////
-
-#define LEMON_PLAY_IRQ_CREATE 0x00
-
-#define LEMON_PLAY_IRQ_JOIN 0x01
-
-#define LEMON_PLAY_IRQ_WAKEUPE 0x02
-
-//////////////////////////////////////////////////////////////////////////
-
-typedef union LemonPlayIRQData{
- struct{
- LemonActorProc Proc;
- void *UserData;
- } TaskData;
-} LemonPlayIRQData;
-
-LEMON_IMPLEMENT_HANDLE(LemonPlayIRQ){
-
- size_t IRQType;
-
- LemonActor Source;/*the IRQ source actor*/
-
- LemonActor Object;/*the IRQ target actor*/
-
- LemonPlayIRQData Data;
-
- LemonPlayIRQ NextIRQ;
-};
-
-typedef struct LemonPlayIRQArray{
-
- volatile size_t IRQs;
-
- volatile LemonPlayIRQ Array;
-
- volatile LemonPlayIRQ Tail;
-
-}LemonPlayIRQArray;
-
-#endif //LEMON_PLAY_IRQ_H
View
187 play/play.cpp
@@ -1,187 +0,0 @@
-#include <assert.h>
-#include <lemon/play/task.h>
-#include <lemon/play/play.h>
-#include <lemon/sys/thread.h>
-#include <lemon/play/runquene.h>
-
-LEMON_IMPLEMENT_HANDLE(LemonPlay){
-
- lemon_atomic_t Seqence;
-
- size_t Threads;
-
- LemonTls CurrentRunQuene;
-
- LemonPlayRunQueue RunQuenes[1];
-};
-
-LEMON_PLAY_API
- LemonPlay
- LemonCreatePlay(
- __lemon_in size_t backgroundThreads,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LEMON_RESET_ERRORINFO(*errorCode);
-
- size_t bufferSize = LEMON_HANDLE_IMPLEMENT_SIZEOF(LemonPlay) + sizeof(LemonPlayRunQueue) * backgroundThreads;
-
- LemonPlay play = (LemonPlay)malloc(bufferSize);
-
- memset(play,0,bufferSize);
-
- play->Threads = backgroundThreads;
-
- play->CurrentRunQuene = LemonCreateTls(NULL,errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;
-
- for(size_t i = 0 ; i < backgroundThreads; ++ i){
-
- play->RunQuenes[i] = LemonCreatePlayRunQueue(play,(lemon_uint32_t)i,errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;
-
- }
-
- return play;
-
-Error:
- LemonReleasePlay(play);
-
- return LEMON_HANDLE_NULL_VALUE;
-}
-
-LEMON_PLAY_API
- void
- LemonReleasePlay(
- __lemon_free LemonPlay play)
-{
- for(size_t i = 0 ; i < play->Threads; ++ i){
-
- LemonReleasePlayRunQueue(play->RunQuenes[i]);
- }
-
- if(LEMON_CHECK_HANDLE(play->CurrentRunQuene)) LemonReleaseTls(play->CurrentRunQuene);
-
- free(play);
-}
-
-LEMON_PLAY_API
- LemonActor
- LemonCreateActor(
- __lemon_in LemonPlay play,
- __lemon_in LemonActorProc proc,
- __lemon_in void *userData,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonActor self = LemonGetCurrentActor(play,errorCode);
-
- if(LEMON_FAILED(*errorCode)) return LEMON_PLAY_NULL_ACTOR;
-
- size_t index = (((size_t)LemonAtomicIncrement(&play->Seqence)) - 1)%play->Threads;
-
- return LemonPlayRunQueueCreateActor(play->RunQuenes[index],self,proc,userData,errorCode);
-}
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonGetCurrentTask(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonPlayRunQueue self = (LemonPlayRunQueue)LemonTlsGet(play->CurrentRunQuene,errorCode);
-
- if(LEMON_FAILED(*errorCode)) return LEMON_HANDLE_NULL_VALUE;
-
- if(self == NULL) return LEMON_HANDLE_NULL_VALUE;
-
- return LemonPlayRunQueueCurrentTask(self);
-}
-
-LEMON_PLAY_API
- void
- LemonActorJoin(
- __lemon_in LemonPlay play,
- __lemon_in LemonActor actor,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonPlayTask task = LemonGetCurrentTask(play,errorCode);
-
- assert(task);
-
- LemonActor self = LemonPlayTaskId(task);
-
- if(LEMON_FAILED(*errorCode)) return;
-
- LemonActorId objectId = *(LemonActorId*)&actor;
-
- LemonPlayRunQueueActorJoin(play->RunQuenes[objectId.RunQueneId],actor,self,errorCode);
-
- LemonPlayTaskOnLeave(task);
-
- LemonPlayTaskYied(task,errorCode);
-}
-
-LEMON_PLAY_API
- LemonActor
- LemonGetCurrentActor(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonPlayRunQueue self = (LemonPlayRunQueue)LemonTlsGet(play->CurrentRunQuene,errorCode);
-
- if(LEMON_FAILED(*errorCode)) return LEMON_PLAY_NULL_ACTOR;
-
- if(self == NULL) return LEMON_PLAY_NULL_ACTOR;
-
- return LemonPlayRunQueueCurrentActor(self);
-}
-
-LEMON_PLAY_API
- LemonPlayRunQueue
- LemonGetActorRunQueue(
- __lemon_in LemonPlay play,
- __lemon_in LemonActor actor)
-{
- LemonActorId *objectId = (LemonActorId*)&actor;
-
- return play->RunQuenes[objectId->RunQueneId];
-}
-
-LEMON_PLAY_API
- void
- LemonPlayJoin(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- for(size_t i = 0 ; i < play->Threads; ++ i){
-
- LemonPlayRunQueueJoin(play->RunQuenes[i],errorCode);
-
- if(LEMON_FAILED(*errorCode)) return;
- }
-}
-
-LEMON_PLAY_API
- void
- LemonPlayStop(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- for(size_t i = 0 ; i < play->Threads; ++ i){
-
- LemonPlayRunQueueStop(play->RunQuenes[i],errorCode);
-
- if(LEMON_FAILED(*errorCode)) return;
- }
-}
-
-LEMON_PLAY_PRIVATE
- void
- LemonSetCurrentPlayRunQueue(
- __lemon_in LemonPlay play,
- __lemon_in LemonPlayRunQueue self,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonTlsSet(play->CurrentRunQuene,self,errorCode);
-}
View
73 play/play.h
@@ -1,73 +0,0 @@
-/**
-*
-* @file play
-* @brief Copyright (C) 2012 yayanyang All Rights Reserved
-* @author yayanyang
-* @version 1.0.0.0
-* @date 2012/03/24
-*/
-#ifndef LEMON_PLAY_PLAY_H
-#define LEMON_PLAY_PLAY_H
-#include <lemon/play/abi.h>
-
-LEMON_PLAY_API
- LemonPlay
- LemonCreatePlay(
- __lemon_in size_t backgroundThreads,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_API
- void
- LemonReleasePlay(
- __lemon_free LemonPlay play);
-
-LEMON_PLAY_API
- void
- LemonPlayJoin(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_API
- void
- LemonPlayStop(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_API
- LemonActor
- LemonCreateActor(
- __lemon_in LemonPlay play,
- __lemon_in LemonActorProc proc,
- __lemon_in void *userData,
- __lemon_inout LemonErrorInfo *errorCode);
-
-
-LEMON_PLAY_API
- LemonActor
- LemonCreateActor(
- __lemon_in LemonPlay play,
- __lemon_in LemonActorProc proc,
- __lemon_in void *userData,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_API
- void
- LemonActorJoin(
- __lemon_in LemonPlay play,
- __lemon_in LemonActor actor,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_API
- LemonActor
- LemonGetCurrentActor(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_API
- LemonPlayRunQueue
- LemonGetActorRunQueue(
- __lemon_in LemonPlay play,
- __lemon_in LemonActor actor);
-
-
-#endif //LEMON_PLAY_PLAY_H
View
440 play/runquene.cpp
@@ -1,440 +0,0 @@
-#include <assert.h>
-#include <lemon/play/task.h>
-#include <lemon/play/play.h>
-#include <lemon/sys/thread.h>
-#include <lemon/play/runquene.h>
-#include <lemon/memory/fixobj.h>
-#include <lemon/sys/assembly.h>
-#include <lemon/sys/coroutine.h>
-
-
-LEMON_IMPLEMENT_HANDLE(LemonPlayRunQueue){
-
- LemonPlay Play;
-
- lemon_uint32_t Id;
-
- lemon_atomic_t Seqence;
-
- LemonPlayTask RunningTask;
-
- volatile LemonPlayIRQArray IRQArray;
-
- LemonPlayTaskRing TaskRing;
-
- LemonMutex Mutex;
-
- LemonConditionVariable Condition;
-
- LemonFixObjectAllocator IRQAllocator;
-
- LemonThread Thread;
-
- LemonErrorInfo LastError;
-
- lemon_bool Exit;
-
- LemonCoroutine Coro;
-};
-
-void LemonPlayQueueBackThread(void * userData);
-
-LEMON_PLAY_PRIVATE
- LemonPlayRunQueue
- LemonCreatePlayRunQueue(
- __lemon_in LemonPlay play,
- __lemon_in lemon_uint32_t id,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LEMON_ALLOC_HANDLE(LemonPlayRunQueue,queue);
-
- LEMON_RESET_ERRORINFO(*errorCode);
-
- queue->Play = play;
-
- queue->Id = id;
-
- queue->Exit = lemon_false;
-
- queue->TaskRing = LemonCreatePlayTaskRing(play,errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;
-
- queue->Mutex = LemonCreateMutex(errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;
-
- queue->Condition = LemonCreateConditionVariable(errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;
-
- queue->IRQAllocator = LemonCreateFixObjectAllocator(LEMON_HANDLE_IMPLEMENT_SIZEOF(LemonPlayIRQ),errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;
-
- /*LemonMutexLock(queue->Mutex,errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;*/
-
- queue->Thread = LemonCreateThread(&LemonPlayQueueBackThread,queue,errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;
-
- /*LemonConditionVariableWait(queue->Condition,queue->Mutex,errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;
-
- LemonMutexUnLock(queue->Mutex,errorCode);
-
- if(LEMON_FAILED(*errorCode)) goto Error;*/
-
- return queue;
-Error:
-
- LemonReleasePlayRunQueue(queue);
-
- return LEMON_HANDLE_NULL_VALUE;
-}
-
-LEMON_PLAY_PRIVATE
- void
- LemonReleasePlayRunQueue(
- __lemon_free LemonPlayRunQueue queue)
-{
- if(LEMON_CHECK_HANDLE(queue->Coro)) LemonReleaseCoroutine(queue->Coro);
-
- if(LEMON_CHECK_HANDLE(queue->Thread)) LemonReleaseThread(queue->Thread);
-
- if(LEMON_CHECK_HANDLE(queue->IRQAllocator)) LemonReleaseFixObjectAllocator(queue->IRQAllocator);
-
- if(LEMON_CHECK_HANDLE(queue->Condition )) LemonReleaseConditionVariable(queue->Condition);
-
- if(LEMON_CHECK_HANDLE(queue->Mutex)) LemonReleaseMutex(queue->Mutex);
-
- if(LEMON_CHECK_HANDLE(queue->TaskRing)) LemonReleasePlayTaskRing(queue->TaskRing);
-
- LEMON_FREE_HANDLE(queue);
-}
-
-LEMON_PLAY_PRIVATE
- void LemonPlayRunQueueStop(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonMutexLock(queue->Mutex,errorCode);
-
- if(LEMON_FAILED(*errorCode)) return;
-
- queue->Exit = lemon_true;
-
- LemonMutexUnLock(queue->Mutex,errorCode);
-
- if(LEMON_SUCCESS(*errorCode)){
-
- LemonConditionVariableNotify(queue->Condition,errorCode);
- }
-}
-
-LEMON_PLAY_PRIVATE
- void LemonPlayRunQueuePushIRQ(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_in size_t type,
- __lemon_in LemonActor object,
- __lemon_in LemonActor source,
- __lemon_in LemonPlayIRQData * data,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LEMON_RESET_ERRORINFO(*errorCode);
-
- LemonMutexLock(queue->Mutex,errorCode);
-
- if(LEMON_FAILED(*errorCode)) return;
-
- LemonPlayIRQ irq = (LemonPlayIRQ)LemonFixObjectAlloc(queue->IRQAllocator);
-
- memset(irq,0,LEMON_HANDLE_IMPLEMENT_SIZEOF(LemonPlayIRQ));
-
- if(NULL == irq){
- LEMON_USER_ERROR(*errorCode,LEMON_SYS_RESOURCE_ERROR);
- goto Finally;
- }
-
- irq->IRQType = type;
-
- irq->Object = object;
-
- irq->Source = source;
-
- if(data) irq->Data = *data;
-
- if(queue->IRQArray.Tail){
-
- queue->IRQArray.Tail->NextIRQ = irq;
- }else{
- queue->IRQArray.Array = irq;
- }
-
- queue->IRQArray.Tail = irq;
-
- ++ queue->IRQArray.IRQs;
-
-Finally:
-
- if(LEMON_SUCCESS(*errorCode)){
-
- LemonConditionVariableNotify(queue->Condition,errorCode);
- }
-
- LemonMutexUnLock(queue->Mutex,errorCode);
-}
-
-LEMON_PLAY_PRIVATE
- void LemonPlayRunQueueActorWakeup(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_in LemonActor object,
- __lemon_in LemonActor source,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonPlayRunQueuePushIRQ(queue,LEMON_PLAY_IRQ_WAKEUPE,object,source,NULL,errorCode);
-}
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayRunQueueActorJoin(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_in LemonActor object,
- __lemon_in LemonActor source,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonPlayRunQueuePushIRQ(queue,LEMON_PLAY_IRQ_JOIN,object,source,NULL,errorCode);
-}
-
-LEMON_PLAY_PRIVATE
- LemonActor
- LemonPlayRunQueueCreateActor(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_in LemonActor source,
- __lemon_in LemonActorProc proc,
- __lemon_in void *userData,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonPlayIRQData data;
-
- LemonActorId id = {((size_t)LemonAtomicIncrement(&queue->Seqence)) - 1,queue->Id};
-
- LemonActor object = *(LemonActor*)&id;
-
- data.TaskData.Proc = proc;
-
- data.TaskData.UserData = userData;
-
- LemonPlayRunQueuePushIRQ(queue,LEMON_PLAY_IRQ_CREATE,object,source,&data,errorCode);
-
- return object;
-}
-
-LEMON_PLAY_PRIVATE
- LemonActor
- LemonPlayRunQueueCurrentActor(
- __lemon_in LemonPlayRunQueue queue)
-{
- return LemonPlayTaskId(queue->RunningTask);
-}
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonPlayRunQueueCurrentTask(
- __lemon_in LemonPlayRunQueue queue)
-{
- return queue->RunningTask;
-}
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayRunQueueJoin(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonThreadJoin(queue->Thread,errorCode);
-
- if(LEMON_SUCCESS(*errorCode)) *errorCode = queue->LastError;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-
-void LemonPlayQueueDispatchIRQs(
- LemonPlayRunQueue queue,
- LemonPlayIRQ irqs,
- LemonErrorInfo *errorCode)
-{
- LemonPlayIRQ release = irqs;
-
- while(irqs){
-
- LemonPlayIRQ iter = irqs;
-
- irqs = irqs->NextIRQ;
-
- switch(iter->IRQType)
- {
- case LEMON_PLAY_IRQ_CREATE:
- {
- LemonPlayTask task = LemonPlayTaskRingAdd(
- queue->TaskRing,
- queue->Coro,
- iter->Object,
- iter->Data.TaskData.Proc,
- iter->Data.TaskData.UserData,
- errorCode);
-
- if(LEMON_SUCCESS(*errorCode)){
-
- queue->RunningTask = task;
-
- LemonPlayTaskRun(task,errorCode);
- }
-
- break;
- }
-
- case LEMON_PLAY_IRQ_JOIN:
- {
- LemonPlayTask task = LemonPlayTaskRingSearch(queue->TaskRing,iter->Object);
-
- if(!task){
-
- LemonPlayRunQueue sourceRunQueue = LemonGetActorRunQueue(queue->Play,iter->Source);
-
- LemonPlayRunQueueActorWakeup(sourceRunQueue,iter->Source,iter->Object,errorCode);
-
- }else{
-
- LemonPlayTaskJoin(task,iter->Source,errorCode);
- }
-
- break;
- }
-
- case LEMON_PLAY_IRQ_WAKEUPE:
- {
- LemonPlayTask task = LemonPlayTaskRingSearch(queue->TaskRing,iter->Object);
-
- if(task){
-
- LemonPlayTaskStandby(task);
- }
-
- break;
- }
-
- default:
- assert(false);
- }
-
- if(LEMON_FAILED(*errorCode)) goto Finally;
- }
-
-Finally:
-
- LemonMutexLock(queue->Mutex,errorCode);
-
- if(LEMON_FAILED(*errorCode)) return;
-
- while(release){
-
- LemonPlayIRQ current = release;
-
- release = release->NextIRQ;
-
- LemonFixObjectFree(queue->IRQAllocator,current);
- }
-
- LemonMutexUnLock(queue->Mutex,errorCode);
-}
-
-void LemonPlayQueueBackThread(void * userData)
-{
- LEMON_DECLARE_ERRORINFO(errorCode);
-
- LemonPlayRunQueue queue = (LemonPlayRunQueue)userData;
-
- queue->Coro = LemonThreadToCoroutine(&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Error;
-
- LemonSetCurrentPlayRunQueue(queue->Play,queue,&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Error;
-
- LemonMutexLock(queue->Mutex,&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Error;
-
- /*LemonConditionVariableNotify(queue->Condition,&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Finally;*/
-
- while(!queue->Exit){
-
- LemonPlayIRQ irqs = LEMON_HANDLE_NULL_VALUE;
-
- if(0 == queue->IRQArray.IRQs && LemonPlayTaskRingValidTasks(queue->TaskRing) == 0){
-
- LemonConditionVariableWait(queue->Condition,queue->Mutex,&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Finally;
-
- continue;
- }
-
- if(queue->IRQArray.IRQs){
-
- irqs = queue->IRQArray.Array;
-
- queue->IRQArray.Array = LEMON_HANDLE_NULL_VALUE;
-
- queue->IRQArray.Tail = LEMON_HANDLE_NULL_VALUE;
-
- queue->IRQArray.IRQs = 0;
- }
-
- LemonMutexUnLock(queue->Mutex,&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Error;
-
- if(irqs){
-
- LemonPlayQueueDispatchIRQs(queue,irqs,&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Error;
- }
-
- LemonPlayTask task ;
-
- LemonPlayTaskRingReset(queue->TaskRing);
-
- while(NULL != (task = LemonPlayTaskRingLoop(queue->TaskRing))){
-
- queue->RunningTask = task;
-
- LemonPlayTaskRun(task,&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Finally;
-
- }
-
- LemonMutexLock(queue->Mutex,&errorCode);
-
- if(LEMON_FAILED(errorCode)) goto Error;
-
- }
-
-
-Finally:
-
- LemonMutexUnLock(queue->Mutex,&errorCode);
-
-Error:
- queue->LastError = errorCode;
-}
View
87 play/runquene.h
@@ -1,87 +0,0 @@
-/**
-*
-* @file runquene
-* @brief Copyright (C) 2012 yayanyang All Rights Reserved
-* @author yayanyang
-* @version 1.0.0.0
-* @date 2012/03/24
-*/
-#ifndef LEMON_PLAY_RUNQUEUE_H
-#define LEMON_PLAY_RUNQUEUE_H
-#include <lemon/play/abi.h>
-#include <lemon/play/irq.h>
-
-LEMON_PLAY_PRIVATE
- LemonPlayRunQueue
- LemonCreatePlayRunQueue(
- __lemon_in LemonPlay play,
- __lemon_in lemon_uint32_t id,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- void
- LemonReleasePlayRunQueue(
- __lemon_free LemonPlayRunQueue queue);
-
-LEMON_PLAY_PRIVATE
- void LemonPlayRunQueueStop(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- void LemonPlayRunQueuePushIRQ(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_in size_t type,
- __lemon_in LemonActor object,
- __lemon_in LemonActor source,
- __lemon_in LemonPlayIRQData * data,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- void LemonPlayRunQueueActorWakeup(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_in LemonActor object,
- __lemon_in LemonActor source,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayRunQueueActorJoin(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_in LemonActor object,
- __lemon_in LemonActor source,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- LemonActor
- LemonPlayRunQueueCreateActor(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_in LemonActor source,
- __lemon_in LemonActorProc proc,
- __lemon_in void *userData,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- LemonActor
- LemonPlayRunQueueCurrentActor(
- __lemon_in LemonPlayRunQueue queue);
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonPlayRunQueueCurrentTask(
- __lemon_in LemonPlayRunQueue queue);
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayRunQueueJoin(
- __lemon_in LemonPlayRunQueue queue,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- void
- LemonSetCurrentPlayRunQueue(
- __lemon_in LemonPlay play,
- __lemon_in LemonPlayRunQueue self,
- __lemon_inout LemonErrorInfo *errorCode);
-
-#endif //LEMON_PLAY_RUNQUEUE_H
View
375 play/task.cpp
@@ -1,375 +0,0 @@
-#include <assert.h>
-#include <lemon/play/task.h>
-#include <lemon/play/play.h>
-#include <lemon/play/runquene.h>
-#include <lemon/sys/coroutine.h>
-#include <lemon/memory/fixobj.h>
-#include <lemon/sys/assembly.h>
-
-typedef struct LemonPlayTaskJoinData{
- struct LemonPlayTaskJoinData *Next;
- LemonActor JoinActor;
-}LemonPlayTaskJoinData;
-
-LEMON_IMPLEMENT_HANDLE(LemonPlayTask){
- LemonPlayTask Prev;
-
- LemonPlayTask Next;
-
- LemonActor Id;
-
- LemonPlayTaskJoinData *JoinDatas;
-
- LemonCoroutine Coro;
-
- LemonActorProc Proc;
-
- void *UserData;
-
- LemonPlayTaskRing Ring;
-};
-
-LEMON_IMPLEMENT_HANDLE(LemonPlayTaskRing){
-
- size_t Tasks;
-
- size_t ValidTasks;
-
- LemonPlayTask CurrentTask;
-
- LemonPlayTask OnLeaveTasks;
-
- LemonPlayTask StandbyTasks;
-
- LemonFixObjectAllocator TaskAllocator;
-
- LemonFixObjectAllocator JoinDataAllocator;
-
- LemonPlay Play;
-};
-
-LEMON_PLAY_PRIVATE
- void LemonPlayTaskProc(
- __lemon_in LemonCoroutine /*self*/,
- __lemon_in void * userData)
-{
- LemonPlayTask task = (LemonPlayTask)userData;
-
- task->Proc(task->Ring->Play,task->UserData);
-}
-
-//////////////////////////////////////////////////////////////////////////
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayTaskYied(
- __lemon_in LemonPlayTask task,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonCoroutineYield(task->Coro,errorCode);
-}
-
-LEMON_PLAY_PRIVATE
- void
- LemonReleasePlayTask(
- __lemon_in LemonPlayTask task)
-{
- LEMON_DECLARE_ERRORINFO(errorCode);
-
- if(task->Coro) LemonReleaseCoroutine(task->Coro);
-
- LemonPlayTaskJoinData * iter = task->JoinDatas;
-
- LemonPlay play = task->Ring->Play;
-
- while(iter){
-
- LemonPlayTaskJoinData * current = iter;
-
- iter = iter->Next;
-
- LemonPlayRunQueue target = LemonGetActorRunQueue(play,iter->JoinActor);
-
- LemonPlayRunQueueActorWakeup(target,iter->JoinActor,task->Id,&errorCode);
-
- assert(LEMON_SUCCESS(errorCode));
-
- LemonFixObjectFree(task->Ring->JoinDataAllocator,current);
- }
-
- LemonFixObjectFree(task->Ring->TaskAllocator,task);
-}
-
-LEMON_PLAY_PRIVATE void LemonPlayTaskRun(
- __lemon_in LemonPlayTask task,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonCoroutineResume(task->Coro,errorCode);
-
- if(LemonGetCoroutineStatus(task->Coro) == LemonCoroutineStatuts_Stopped){
-
- if(task->Prev) task->Prev->Next = task->Next;
-
- else task->Ring->StandbyTasks = NULL;
-
- if(task->Next) task->Next->Prev = task->Prev;
-
- task->Prev = task->Next = NULL;
-
- -- task->Ring->Tasks;
-
- -- task->Ring->ValidTasks;
-
- LemonReleasePlayTask(task);
- }
-}
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayTaskOnLeave(__lemon_in LemonPlayTask task)
-{
- if(task->Prev) task->Prev->Next = task->Next;
-
- else task->Ring->StandbyTasks = NULL;
-
- if(task->Next) task->Next->Prev = task->Prev;
-
- task->Prev = task->Next = NULL;
-
- task->Next = task->Ring->OnLeaveTasks;
-
- task->Ring->OnLeaveTasks = task;
-
- if(task->Next) task->Next->Prev = task;
-
- -- task->Ring->ValidTasks;
-}
-
-LEMON_PLAY_PRIVATE void LemonPlayTaskStandby(__lemon_in LemonPlayTask task)
-{
- if(task->Prev) task->Prev->Next = task->Next;
-
- else task->Ring->OnLeaveTasks = NULL;
-
- if(task->Next) task->Next->Prev = task->Prev;
-
- task->Prev = task->Next = NULL;
-
- task->Next = task->Ring->OnLeaveTasks;
-
- task->Ring->StandbyTasks = task;
-
- if(task->Next) task->Next->Prev = task;
-
- ++ task->Ring->ValidTasks;
-}
-
-LEMON_PLAY_PRIVATE LemonActor LemonPlayTaskId(__lemon_in LemonPlayTask task)
-{
- return task->Id;
-}
-
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayTaskJoin(
- __lemon_in LemonPlayTask task,
- __lemon_in LemonActor source,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonPlayTaskJoinData * data
- = (LemonPlayTaskJoinData *)LemonFixObjectAlloc(task->Ring->JoinDataAllocator);
-
- if(!data){
- LEMON_USER_ERROR(*errorCode,LEMON_SYS_RESOURCE_ERROR);
- return;
- }
-
- data->Next = task->JoinDatas;
-
- task->JoinDatas = data;
-
- data->JoinActor = source;
-}
-
-
-//////////////////////////////////////////////////////////////////////////
-
-LEMON_PLAY_PRIVATE
- LemonPlayTaskRing
- LemonCreatePlayTaskRing(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LEMON_ALLOC_HANDLE(LemonPlayTaskRing,ring);
-
- ring->Play = play;
-
- ring->TaskAllocator =
- LemonCreateFixObjectAllocator(
- LEMON_HANDLE_IMPLEMENT_SIZEOF(LemonPlayTask),
- errorCode);
-
- if(LEMON_FAILED(*errorCode)){
- LEMON_FREE_HANDLE(ring);
-
- return LEMON_HANDLE_NULL_VALUE;
- }
-
- ring->JoinDataAllocator =
- LemonCreateFixObjectAllocator(
- sizeof(LemonPlayTaskJoinData),
- errorCode);
-
- if(LEMON_FAILED(*errorCode)){
-
- LemonReleaseFixObjectAllocator(ring->TaskAllocator);
-
- LEMON_FREE_HANDLE(ring);
-
- return LEMON_HANDLE_NULL_VALUE;
- }
-
- return ring;
-}
-
-
-LEMON_PLAY_PRIVATE
- void
- LemonReleasePlayTaskRing(
- __lemon_free LemonPlayTaskRing list)
-{
- LemonPlayTask current = list->OnLeaveTasks;
-
- while(current){
-
- LemonPlayTask release = current;
-
- current = current->Next;
-
- LemonReleasePlayTask(release);
- }
-
- current = list->StandbyTasks;
-
- while(current){
-
- LemonPlayTask release = current;
-
- current = current->Next;
-
- LemonReleasePlayTask(release);
- }
-
- LemonReleaseFixObjectAllocator(list->TaskAllocator);
-
- LemonReleaseFixObjectAllocator(list->JoinDataAllocator);
-
- LEMON_FREE_HANDLE(list);
-}
-
-
-LEMON_PLAY_PRIVATE
- size_t
- LemonPlayTaskRingValidTasks(
- __lemon_in LemonPlayTaskRing list)
-{
- return list->ValidTasks;
-}
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonPlayTaskRingAdd(
- __lemon_in LemonPlayTaskRing list,
- __lemon_in LemonCoroutine coro,
- __lemon_in LemonActor id,
- __lemon_in LemonActorProc proc,
- __lemon_in void *userData,
- __lemon_inout LemonErrorInfo *errorCode)
-{
- LemonPlayTask task = (LemonPlayTask)LemonFixObjectAlloc(list->TaskAllocator);
-
- if(NULL == task){
- LEMON_USER_ERROR(*errorCode,LEMON_SYS_RESOURCE_ERROR);
-
- return LEMON_HANDLE_NULL_VALUE;
- }
-
- task->Id = id;
-
- task->Proc = proc;
-
- task->UserData = userData;
-
- task->Ring = list;
-
- task->Coro =
- LemonCreateCoroutine(
- coro,
- LemonPlayTaskProc,
- task,
- LEMON_PLAY_COROUTINE_STACKSIZE,
- errorCode);
-
- if(LEMON_FAILED(*errorCode)) return LEMON_HANDLE_NULL_VALUE;;
-
- task->Next = list->StandbyTasks;
-
- if(task->Next) task->Next->Prev = task;
-
- list->StandbyTasks = task;
-
- ++ list->Tasks;
-
- ++ list->ValidTasks;
-
- return task;
-}
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonPlayTaskRingLoop(
- __lemon_in LemonPlayTaskRing list)
-{
- LemonPlayTask currnet = list->CurrentTask;
-
- if(list->CurrentTask)
- list->CurrentTask = list->CurrentTask->Next;
-
- return currnet;
-}
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayTaskRingReset(
- __lemon_in LemonPlayTaskRing list)
-{
- list->CurrentTask = list->StandbyTasks;
-}
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonPlayTaskRingSearch(
- __lemon_in LemonPlayTaskRing list,
- __lemon_in LemonActor id)
-{
- LemonPlayTask current = list->OnLeaveTasks;
-
- while(current){
-
- if(current->Id == id) return current;
-
- current = current->Next;
- }
-
- current = list->StandbyTasks;
-
- while(current){
-
- if(current->Id == id) return current;
-
- current = current->Next;
- }
-
- return LEMON_HANDLE_NULL_VALUE;
-}
View
88 play/task.h
@@ -1,88 +0,0 @@
-/**
-* All function of TaskList is not thread safe
-* @file task
-* @brief Copyright (C) 2012 yayanyang All Rights Reserved
-* @author yayanyang
-* @version 1.0.0.0
-* @date 2012/03/23
-*/
-#ifndef LEMON_PLAY_TASK_H
-#define LEMON_PLAY_TASK_H
-#include <lemon/play/abi.h>
-#include <lemon/sys/coroutine.h>
-
-LEMON_DECLARE_HANDLE(LemonPlayTask);
-LEMON_DECLARE_HANDLE(LemonPlayTaskRing);
-
-LEMON_PLAY_PRIVATE void LemonPlayTaskOnLeave(__lemon_in LemonPlayTask task);
-
-LEMON_PLAY_PRIVATE void LemonPlayTaskStandby(__lemon_in LemonPlayTask task);
-
-LEMON_PLAY_PRIVATE LemonActor LemonPlayTaskId(__lemon_in LemonPlayTask task);
-
-LEMON_PLAY_PRIVATE void LemonPlayTaskRun(
- __lemon_in LemonPlayTask task,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayTaskYied(
- __lemon_in LemonPlayTask task,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayTaskJoin(
- __lemon_in LemonPlayTask task,
- __lemon_in LemonActor source,
- __lemon_inout LemonErrorInfo *errorCode);
-
-//////////////////////////////////////////////////////////////////////////
-//task list
-//
-
-
-LEMON_PLAY_PRIVATE
- LemonPlayTaskRing
- LemonCreatePlayTaskRing(
- __lemon_in LemonPlay play,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- void
- LemonReleasePlayTaskRing(
- __lemon_free LemonPlayTaskRing list);
-
-LEMON_PLAY_PRIVATE
- size_t
- LemonPlayTaskRingValidTasks(
- __lemon_in LemonPlayTaskRing list);
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonPlayTaskRingAdd(
- __lemon_in LemonPlayTaskRing list,
- __lemon_in LemonCoroutine coro,
- __lemon_in LemonActor id,
- __lemon_in LemonActorProc proc,
- __lemon_in void *userData,
- __lemon_inout LemonErrorInfo *errorCode);
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonPlayTaskRingSearch(
- __lemon_in LemonPlayTaskRing list,
- __lemon_in LemonActor id);
-
-LEMON_PLAY_PRIVATE
- LemonPlayTask
- LemonPlayTaskRingLoop(
- __lemon_in LemonPlayTaskRing list);
-
-LEMON_PLAY_PRIVATE
- void
- LemonPlayTaskRingReset(
- __lemon_in LemonPlayTaskRing list);
-
-
-#endif //LEMON_PLAY_TASK_H
Please sign in to comment.
Something went wrong with that request. Please try again.