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 SHORTLOCK( &thread->IsLocked );
39 // Check if thread is still alive
40 if(thread->Status == THREAD_STAT_DEAD) {
41 SHORTREL( &thread->IsLocked );
46 msg = malloc( sizeof(tMsg)+Length );
48 msg->Source = Proc_GetCurThread()->TID;
50 memcpy(msg->Data, Data, Length);
52 // If there are already messages
53 if(thread->LastMessage) {
54 thread->LastMessage->Next = msg;
55 thread->LastMessage = msg;
57 thread->Messages = msg;
58 thread->LastMessage = msg;
61 SHORTREL(&thread->IsLocked);
63 Threads_Wake( thread );
69 * \fn int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
70 * \brief Gets a message
71 * \param Err Pointer to \a errno
72 * \param Source Where to put the source TID
73 * \param Buffer Buffer to place the message data (set to NULL to just get message length)
75 int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
79 tThread *cur = Proc_GetCurThread();
81 // Check if queue has any items
86 SHORTLOCK( &cur->IsLocked );
89 *Source = cur->Messages->Source;
93 ret = cur->Messages->Length;
94 SHORTREL( &cur->IsLocked );
99 if(Buffer != GETMSG_IGNORE)
101 if( !CheckMem( Buffer, cur->Messages->Length ) )
104 SHORTREL( &cur->IsLocked );
107 memcpy(Buffer, cur->Messages->Data, cur->Messages->Length);
109 ret = cur->Messages->Length;
113 cur->Messages = cur->Messages->Next;
115 SHORTREL( &cur->IsLocked );
117 free(tmp); // Free outside of lock