2 * AcessOS Microkernel Version
10 extern tShortSpinlock glThreadListLock;
14 * \fn int Proc_SendMessage(Uint *Err, Uint Dest, int Length, void *Data)
15 * \brief Send an IPC message
16 * \param Err Pointer to the errno variable
17 * \param Dest Destination Thread
18 * \param Length Length of the message
19 * \param Data Message data
21 int Proc_SendMessage(Uint *Err, Uint Dest, int Length, void *Data)
26 Log("Proc_SendMessage: (Err=%p, Dest=%i, Length=%i, Data=%p)", Err, Dest, Length, Data);
28 if(Length <= 0 || !Data) {
34 thread = Threads_GetThread( Dest );
37 if(!thread) { return -1; }
40 SHORTLOCK( &thread->IsLocked );
42 // Check if thread is still alive
43 if(thread->Status == THREAD_STAT_DEAD) {
44 SHORTREL( &thread->IsLocked );
49 msg = malloc( sizeof(tMsg)+Length );
51 msg->Source = Proc_GetCurThread()->TID;
53 memcpy(msg->Data, Data, Length);
55 // If there are already messages
56 if(thread->LastMessage) {
57 thread->LastMessage->Next = msg;
58 thread->LastMessage = msg;
60 thread->Messages = msg;
61 thread->LastMessage = msg;
64 SHORTREL(&thread->IsLocked);
66 SHORTLOCK(&glThreadListLock);
67 Threads_Wake( thread );
68 SHORTREL(&glThreadListLock);
74 * \fn int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
75 * \brief Gets a message
76 * \param Err Pointer to \a errno
77 * \param Source Where to put the source TID
78 * \param Buffer Buffer to place the message data (set to NULL to just get message length)
80 int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
84 tThread *cur = Proc_GetCurThread();
86 // Check if queue has any items
91 SHORTLOCK( &cur->IsLocked );
94 *Source = cur->Messages->Source;
98 ret = cur->Messages->Length;
99 SHORTREL( &cur->IsLocked );
104 if(Buffer != GETMSG_IGNORE)
106 if( !CheckMem( Buffer, cur->Messages->Length ) )
109 SHORTREL( &cur->IsLocked );
112 memcpy(Buffer, cur->Messages->Data, cur->Messages->Length);
114 ret = cur->Messages->Length;
118 cur->Messages = cur->Messages->Next;
120 SHORTREL( &cur->IsLocked );
122 free(tmp); // Free outside of lock