/*
- * AcessOS Microkernel Version
+ * Acess2 Kernel
+ * - By John Hodge (thePowersGang)
+ *
* messages.c
+ * - IPC Messages
*/
-#define DEBUG 1
+#define DEBUG 0
#include <acess.h>
#include <threads.h>
#include <threads_int.h>
#include <errno.h>
-
-// === IMPORTS ===
-extern tShortSpinlock glThreadListLock;
+#include <events.h>
// === CODE ===
/**
LEAVE_RET('i', -1);
}
+ // TODO: Check message length against global/per-thread maximums
+ // TODO: Restrict queue length
+
// Get thread
thread = Threads_GetThread( Dest );
}
SHORTREL(&thread->IsLocked);
-
- SHORTLOCK(&glThreadListLock);
- Threads_Wake( thread );
- SHORTREL(&glThreadListLock);
+
+ // Wake the thread
+ LOG("Waking %p (%i %s)", thread, thread->TID, thread->ThreadName);
+ Threads_PostEvent( thread, THREAD_EVENT_IPCMSG );
LEAVE_RET('i', 0);
}
* \param Err Pointer to \a errno
* \param Source Where to put the source TID
* \param Buffer Buffer to place the message data (set to NULL to just get message length)
+ * \return Message length
*/
int Proc_GetMessage(Uint *Err, Uint *Source, void *Buffer)
{
int ret;
void *tmp;
tThread *cur = Proc_GetCurThread();
+
+ ENTER("pSource pBuffer", Source, Buffer);
// Check if queue has any items
if(!cur->Messages) {
+ LEAVE('i', 0);
return 0;
}
SHORTLOCK( &cur->IsLocked );
- if(Source)
+ if(Source) {
*Source = cur->Messages->Source;
+ LOG("*Source = %i", *Source);
+ }
// Get message length
if( !Buffer ) {
ret = cur->Messages->Length;
SHORTREL( &cur->IsLocked );
+ LEAVE('i', ret);
return ret;
}
{
if( !CheckMem( Buffer, cur->Messages->Length ) )
{
+ LOG("Invalid buffer");
*Err = -EINVAL;
SHORTREL( &cur->IsLocked );
+ LEAVE('i', -1);
return -1;
}
+ LOG("Copied to buffer");
memcpy(Buffer, cur->Messages->Data, cur->Messages->Length);
}
ret = cur->Messages->Length;
// Remove from list
tmp = cur->Messages;
cur->Messages = cur->Messages->Next;
+ if(cur->Messages == NULL) cur->LastMessage = NULL;
SHORTREL( &cur->IsLocked );
free(tmp); // Free outside of lock
-
+
+ LEAVE('i', ret);
return ret;
}