va_start(args, ArgTypes);
- LogF("%012lli ", now());
+ LogF("%014lli ", now());
while(i--) Debug_Putchar(' ');
Debug_Puts(1, FuncName);
va_start(args, Fmt);
- LogF("%012lli ", now());
+ LogF("%014lli ", now());
while(i--) Debug_Putchar(' ');
Debug_Puts(1, FuncName);
gDebug_Level = 0;
i = 0;
}
- LogF("%012lli ", now());
+ LogF("%014lli ", now());
// Indenting
while(i--) Debug_Putchar(' ');
{
const Uint8 *cdat = Data;
Uint pos = 0;
+ LogF("%014lli ", now());
Debug_Puts(1, Header);
LogF(" (Hexdump of %p)\r\n", Data);
{
int i ;
- LogF("Log: %04x: ", pos);
+ LogF("%014lli Log: %04x: ", now(), pos);
for(i = 0; i < Length; i ++)
{
LogF("%02x ", cdat[i]);
break;
}
break;
+
+ // Erase in line
+ case 'K':
+ switch(args[0])
+ {
+ case 0: // Erase to right
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ int i, max;
+ max = Term->Width - Term->AltWritePos % Term->Width;
+ for( i = 0; i < max; i ++ )
+ Term->AltBuf[Term->AltWritePos+i].Ch = 0;
+ }
+ else
+ {
+ int i, max;
+ max = Term->Width - Term->WritePos % Term->Width;
+ for( i = 0; i < max; i ++ )
+ Term->Text[Term->WritePos+i].Ch = 0;
+ }
+ VT_int_UpdateScreen(Term, 0);
+ break;
+ case 1: // Erase to left
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ int i = Term->AltWritePos % Term->Width;
+ while( i -- )
+ Term->AltBuf[Term->AltWritePos++].Ch = 0;
+ }
+ else
+ {
+ int i = Term->WritePos % Term->Width;
+ while( i -- )
+ Term->Text[Term->WritePos++].Ch = 0;
+ }
+ VT_int_UpdateScreen(Term, 0);
+ break;
+ case 2: // Erase all
+ if( Term->Flags & VT_FLAG_ALTBUF )
+ {
+ VT_int_ClearLine(Term, Term->AltWritePos / Term->Width);
+ }
+ else
+ {
+ VT_int_ClearLine(Term, Term->WritePos / Term->Width);
+ }
+ VT_int_UpdateScreen(Term, 0);
+ break;
+ }
+ break;
+
// Set cursor position
case 'H':
if( Term->Flags & VT_FLAG_ALTBUF )
Term->Flags |= VT_FLAG_ALTBUF;
else
Term->Flags &= ~VT_FLAG_ALTBUF;
+ VT_int_UpdateScreen(Term, 1);
}
// ---
* \param Semaphore Semaphore structure to use
* \param MaxToTake Maximum number of items to take off the list (if zero, as much as possible is taken)
* \return Number of items fetched
- * \retval 0 Semaphore interrupted
+ * \retval 0 Semaphore interrupted (signal/message)
* \retval -1 Unspecified error
*/
extern int Semaphore_Wait(tSemaphore *Sem, int MaxToTake);
* AcessOS Microkernel Version
* messages.c
*/
+#define DEBUG 1
#include <acess.h>
#include <threads.h>
#include <threads_int.h>
tThread *thread;
tMsg *msg;
- Log("Proc_SendMessage: (Err=%p, Dest=%i, Length=%i, Data=%p)", Err, Dest, Length, Data);
+ ENTER("pErr iDest iLength pData", Err, Dest, Length, Data);
if(Length <= 0 || !Data) {
*Err = -EINVAL;
- return -1;
+ LEAVE_RET('i', -1);
}
// Get thread
thread = Threads_GetThread( Dest );
// Error check
- if(!thread) { return -1; }
+ if(!thread) LEAVE_RET('i', -1);
// Get Spinlock
SHORTLOCK( &thread->IsLocked );
// Check if thread is still alive
if(thread->Status == THREAD_STAT_DEAD) {
SHORTREL( &thread->IsLocked );
- return -1;
+ LEAVE_RET('i', -1);
}
// Create message
Threads_Wake( thread );
SHORTREL(&glThreadListLock);
- return 0;
+ LEAVE_RET('i', 0);
}
/**
SHORTREL( &glThreadListLock );
return -EOK;
+ case THREAD_STAT_SEMAPHORESLEEP: {
+ tSemaphore *sem;
+ tThread *th, *prev=NULL;
+
+ sem = Thread->WaitPointer;
+
+ SHORTLOCK( &sem->Protector );
+
+ // Remove from sleeping queue
+ for( th = sem->Waiting; th; prev = th, th = th->Next )
+ if( th == Thread ) break;
+ if( th )
+ {
+ if(prev)
+ prev->Next = Thread->Next;
+ else
+ sem->Waiting = Thread->Next;
+ if(sem->LastWaiting == Thread)
+ sem->LastWaiting = prev;
+ }
+ else
+ {
+ prev = NULL;
+ for( th = sem->Signaling; th; prev = th, th = th->Next )
+ if( th == Thread ) break;
+ if( !th ) {
+ Log_Warning("Threads", "Thread %p(%i %s) is not on semaphore %p(%s:%s)",
+ Thread, Thread->TID, Thread->ThreadName,
+ sem, sem->ModName, sem->Name);
+ return -EINTERNAL;
+ }
+
+ if(prev)
+ prev->Next = Thread->Next;
+ else
+ sem->Signaling = Thread->Next;
+ if(sem->LastSignaling == Thread)
+ sem->LastSignaling = prev;
+ }
+
+ SHORTLOCK( &glThreadListLock );
+ Threads_AddActive( Thread );
+ SHORTREL( &glThreadListLock );
+
+ #if DEBUG_TRACE_STATE
+ Log("Threads_Sleep: %p(%i %s) woken from semaphore", Thread, Thread->TID, Thread->ThreadName);
+ #endif
+ SHORTREL( &sem->Protector );
+ } return -EOK;
+
case THREAD_STAT_WAITING:
Warning("Threads_Wake - Waiting threads are not currently supported");
return -ENOTIMPL;
#endif
{
SHORTREL( &glThreadListLock );
+ Log_Warning("Threads", "Current thread %p(%i %s) is not on active queue",
+ ret, ret->TID, ret->ThreadName
+ );
return NULL;
}
SHORTREL( &Sem->Protector ); // Release first to make sure it is released
SHORTREL( &glThreadListLock );
while(us->Status == THREAD_STAT_SEMAPHORESLEEP) Threads_Yield();
- // We're only woken when there's something avaliable
+ // We're only woken when there's something avaliable (or a signal arrives)
us->WaitPointer = NULL;
taken = us->RetStatus;
}
thread_info = malloc(sizeof(tVFS_SelectThread));
- if(!thread_info) return -1;
+ if(!thread_info) LEAVE_RET('i', -1);
Semaphore_Init(&thread_info->SleepHandle, 0, 0, "VFS_SelectNode()", Name);
if( !Timeout || *Timeout > 0 )
{
ret = Semaphore_Wait(&thread_info->SleepHandle, 1);
- // TODO: Do something with ret
+ // TODO: Do something with ret?
}
// Fill output (modify *Handles)
{
for( i = 0; i < NUM_THREADS_PER_ALLOC; i ++ )
{
- LOG("block->Threads[i] = %p", block->Threads[i]);
if( block->Threads[i] )
{
+ LOG("block(%p)->Threads[%i] = %p", block, i, block->Threads[i]);
Semaphore_Signal( &block->Threads[i]->SleepHandle, 1 );
}
}
hdr->ID = i;
hdr->Sequence = ~i;
hdr->Checksum = htons( IPv4_Checksum(hdr, sizeof(buf)) );
- IPv4_SendPacket(Interface, Addr, 1, i, sizeof(buf), buf);
ts = now();
+
+ IPv4_SendPacket(Interface, Addr, 1, i, sizeof(buf), buf);
+
end = ts + Interface->TimeoutDelay;
while( !gICMP_PingSlots[i].bArrived && now() < end) Threads_Yield();
ret = VFS_Read(Adapter->DeviceFD, MAX_PACKET_SIZE, buf);
if(ret == -1) break;
- if(ret <= (int)sizeof(tEthernetHeader)) {
- Log_Log("Net Link", "Recieved an undersized packet");
+ if(ret < sizeof(tEthernetHeader)) {
+ Log_Log("Net Link", "Recieved an undersized packet (%i < %i)",
+ ret, sizeof(tEthernetHeader));
continue;
}
ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
+ // TODO: Lock
+
// Sanity Check Length
if(Length > TX_BUF_SIZE*256) {
Log_Warning(
ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
// Wait for packets
- Semaphore_Wait( &Card->Semaphore, 1 );
+ if( Semaphore_Wait( &Card->Semaphore, 1 ) != 1 )
+ {
+ // Error or interrupted
+ LEAVE_RET('i', 0);
+ }
outb(Card->IOBase, 0x22 | (1 << 6)); // Page 6
LOG("CURR : 0x%02x", inb(Card->IOBase + CURR));
LOG("pktHdr->Length (%i) > 256 - 4, allocated buffer %p", pktHdr->Length, buf);
- if(!buf) {
- LEAVE('i', -1);
- return -1;
- }
+ if(!buf) LEAVE_RET('i', -1);
// Copy the already read data
memcpy(buf, data, 256);
{
//if( gpNe2k_Cards[i].NumWaitingPackets > MAX_PACKET_QUEUE )
// gpNe2k_Cards[i].NumWaitingPackets = MAX_PACKET_QUEUE;
- Semaphore_Signal( &gpNe2k_Cards[i].Semaphore, 1 );
+ if( Semaphore_Signal( &gpNe2k_Cards[i].Semaphore, 1 ) != 1 ) {
+ // Oops?
+ }
}
// 1: Packet sent (no error)
// 2: Recieved with error
ENTER("pNode XOffset XLength pBuffer", Node, Offset, Length, Buffer);
retry:
- Semaphore_Wait( &card->ReadSemaphore, 1 );
+ if( Semaphore_Wait( &card->ReadSemaphore, 1 ) != 1 )
+ {
+ LEAVE_RET('i', 0);
+ }
Mutex_Acquire( &card->ReadMutex );
LOG("packet_count = %i, read_ofs = 0x%x", packet_count, read_ofs);
- Semaphore_Signal( &card->ReadSemaphore, packet_count );
if( packet_count )
+ {
+ if( Semaphore_Signal( &card->ReadSemaphore, packet_count ) != packet_count ) {
+ // Oops?
+ }
VFS_MarkAvaliable( &card->Node, 1 );
+ }
outw(card->IOBase + ISR, FLAG_ISR_ROK);
}
while( gaATA_IRQs[cont] == 0 && now() < timeoutTime)
{
HALT();
-// Threads_Yield();
}
// Complete Transfer
timeoutTime = now() + ATA_TIMEOUT;
while( gaATA_IRQs[cont] == 0 && now() < timeoutTime)
{
-// Threads_Yield();
HALT();
}