[openbeos] Re: odd code in expander

  • From: "Jonas Sundstrom" <kirilla@xxxxxxxxx>
  • To: openbeos@xxxxxxxxxxxxx
  • Date: Tue, 20 Apr 2004 17:25:53 +0200 CEST

Alan Westbrook <alan@xxxxxxxxxxxxxx> wrote:
> ok, explain why you are getting the thread_info, nothing is done with 
> it.
> 
> and what about the other stuff?
> 
> =)

I can only speak for ZipOMatic, which I'm guilty of creating. :)

Snippets from my ZipperThread class:
(FWIW.. :)

status_t
ZipperThread::SuspendExternalZip (void) 
{ 
        PRINT(("ZipperThread::SuspendExternalZip()\n"));

        status_t  status  =  B_OK;
        thread_info  zip_thread_info;
        status  =  get_thread_info (m_zip_process_thread_id, & 
zip_thread_info);
        BString thread_name  =  zip_thread_info.name;
        
        if (status == B_OK && thread_name == "zip")
                return suspend_thread (m_zip_process_thread_id);
        else
                return status;
}

status_t
ZipperThread::ResumeExternalZip (void) 
{ 
        PRINT(("ZipperThread::ResumeExternalZip()\n"));

        status_t  status  =  B_OK;
        thread_info  zip_thread_info;
        status  =  get_thread_info (m_zip_process_thread_id, & 
zip_thread_info);
        BString thread_name  =  zip_thread_info.name;
        
        if (status == B_OK && thread_name == "zip")
                return resume_thread (m_zip_process_thread_id);
        else
                return status;
}

status_t
ZipperThread::InterruptExternalZip (void) 
{ 
        PRINT(("ZipperThread::InterruptExternalZip()\n"));
        
        status_t  status  =  B_OK;
        thread_info  zip_thread_info;
        status  =  get_thread_info (m_zip_process_thread_id, & 
zip_thread_info);
        BString thread_name  =  zip_thread_info.name;
        
        if (status == B_OK && thread_name == "zip")
        {
                status  =  B_OK;
                status  =  send_signal (m_zip_process_thread_id, SIGINT);
                WaitOnExternalZip();
                return status;
        }
        else
                return status;
}

status_t
ZipperThread::WaitOnExternalZip (void) 
{ 
        PRINT(("ZipperThread::WaitOnExternalZip()\n"));
        
        status_t  status  =  B_OK;
        thread_info  zip_thread_info;
        status  =  get_thread_info (m_zip_process_thread_id, & 
zip_thread_info);
        BString thread_name  =  zip_thread_info.name;
        
        if (status == B_OK && thread_name == "zip")
                return wait_for_thread (m_zip_process_thread_id, & status);
        else
                return status;
}


One could argue that the use of BString is redundant, and I'm sure it 
is, but it makes the 'if' statement a lot easier to read:

if (status == B_OK && thread_name == "zip")
if (status == B_OK && (! strcmp(zip_thread_info.name, "zip"))) 

To be honest I don't recall why I test the thread name at all, but it 
works, AFAIK, so I'll leave that as an exercise for future cvs 
Livingstones. :}

/Jonas Sundström.             www.kirilla.com


Other related posts: