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
15 * \param Length Length of the message
16 * \param Data Message data
18 int Proc_SendMessage(Uint *Err, Uint Dest, int Length, void *Data)
23 Log("Proc_SendMessage: (Err=%p, Dest=%i, Length=%i, Data=%p)", Err, Dest, Length, Data);
25 if(Length <= 0 || !Data) {
31 thread = Threads_GetThread( Dest );
34 if(!thread) { return -1; }
37 LOCK( &thread->IsLocked );
39 // Check if thread is still alive
40 if(thread->Status == THREAD_STAT_DEAD) return -1;
43 msg = malloc( sizeof(tMsg)+Length );
45 msg->Source = Proc_GetCurThread()->TID;
47 memcpy(msg->Data, Data, Length);
49 // If there are already messages
50 if(thread->LastMessage) {
51 thread->LastMessage->Next = msg;
52 thread->LastMessage = msg;
54 thread->Messages = msg;
55 thread->LastMessage = msg;
58 RELEASE(&thread->IsLocked);
60 Threads_Wake( thread );
66 * \fn int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
67 * \brief Gets a message
68 * \param Err Pointer to \a errno
69 * \param Source Where to put the source TID
70 * \param Buffer Buffer to place the message data (set to NULL to just get message length)
72 int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
76 tThread *cur = Proc_GetCurThread();
78 // Check if queue has any items
83 LOCK( &cur->IsLocked );
86 *Source = cur->Messages->Source;
90 ret = cur->Messages->Length;
91 RELEASE( &cur->IsLocked );
96 if(Buffer != GETMSG_IGNORE)
98 if( !CheckMem( Buffer, cur->Messages->Length ) )
101 RELEASE( &cur->IsLocked );
104 memcpy(Buffer, cur->Messages->Data, cur->Messages->Length);
106 ret = cur->Messages->Length;
109 tmp = cur->Messages->Next;
110 free( (void*)cur->Messages );
113 RELEASE( &cur->IsLocked );