2 * AcessOS Microkernel Version
11 * \fn int Proc_SendMessage(Uint *Err, Uint Dest, int Length, void *Data)
12 * \brief Send an IPC message
13 * \param Err Pointer to the errno variable
14 * \param Dest Destination Thread
16 int Proc_SendMessage(Uint *Err, Uint Dest, int Length, void *Data)
21 Log("Proc_SendMessage: (Err=%p, Dest=%i, Length=%i, Data=%p)", Err, Dest, Length, Data);
23 if(Length <= 0 || !Data) {
29 thread = Threads_GetThread( Dest );
32 if(!thread) { return -1; }
35 LOCK( &thread->IsLocked );
37 // Check if thread is still alive
38 if(thread->Status == THREAD_STAT_DEAD) return -1;
41 msg = malloc( sizeof(tMsg)+Length );
43 msg->Source = Proc_GetCurThread()->TID;
45 memcpy(msg->Data, Data, Length);
47 // If there are already messages
48 if(thread->LastMessage) {
49 thread->LastMessage->Next = msg;
50 thread->LastMessage = msg;
52 thread->Messages = msg;
53 thread->LastMessage = msg;
56 RELEASE(&thread->IsLocked);
58 Threads_Wake( thread );
64 * \fn int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
65 * \brief Gets a message
67 int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
71 tThread *cur = Proc_GetCurThread();
73 // Check if queue has any items
78 LOCK( &cur->IsLocked );
81 *Source = cur->Messages->Source;
85 ret = cur->Messages->Length;
86 RELEASE( &cur->IsLocked );
91 if(Buffer != GETMSG_IGNORE)
92 memcpy(Buffer, cur->Messages->Data, cur->Messages->Length);
93 ret = cur->Messages->Length;
96 tmp = cur->Messages->Next;
100 RELEASE( &cur->IsLocked );