Novell Home

How to use ScheduleSleepAESProcessEvent() (NetWare)

From Developer Community

This is sample code for ScheduleSleepAESProcessEvent() function. Can be used as a starting point for a sample of ScheduleNoSleepAESProcessEvent() as well.

Sample Code

#include <nwadv.h>
#include <nwconio.h>
#ifdef __MWERKS__
#pragma ANSI_strict off
#endif
#include <nwtime.h>
#ifdef __MWERKS__
#pragma ANSI_strict reset
#endif
#include <nwthread.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>

static unsigned int NLM_ThreadCount;
static          int NLM_MainThreadID;
static          int NLM_MainThreadGroupID;

static void sigHandler( int sig_no) {
   int saved_thread_group_ID = SetThreadGroupID( NLM_MainThreadGroupID);
   signal( sig_no, sigHandler);
   ResumeThread( NLM_MainThreadID);
   while ( NLM_ThreadCount) ThreadSwitchWithDelay();
   SetThreadGroupID( saved_thread_group_ID);
}
static void processToBeScheduled( void* p) {
   int saved_thread_group_ID;
   ++NLM_ThreadCount;
   saved_thread_group_ID = SetThreadGroupID( NLM_MainThreadGroupID);
   ConsolePrintf( "Scheduled, p = %P\n", p);
   ScheduleSleepAESProcessEvent(( struct AESProcessStructure*) p);
   SetThreadGroupID( saved_thread_group_ID);
   --NLM_ThreadCount;
}
int main( void) {
   struct AESProcessStructure ps;
   ++NLM_ThreadCount;
   NLM_MainThreadID      = GetThreadID();
   NLM_MainThreadGroupID = GetThreadGroupID();
   signal( SIGTERM, sigHandler);
   if (( ps.ARTag = AllocateResourceTag( GetNLMHandle(),
                                         ( unsigned char*) "SleepAESProcess",
                                         AESProcessSignature)) == 0) {
      puts( "AllocateResourceTag failed");
      return EXIT_FAILURE;
   }
   SecondsToTicks( 1, 0, &ps.AWakeUpDelayAmount);
   ps.AProcessToCall = processToBeScheduled;
   ps.AOldLink       = NULL;
   ScheduleSleepAESProcessEvent( &ps);
   SuspendThread( NLM_MainThreadID);
   CancelSleepAESProcessEvent( &ps);
   while ( NLM_ThreadCount > 1) ThreadSwitchWithDelay();
   --NLM_ThreadCount;
   return EXIT_SUCCESS;
}

--Dmitry Mityugov

Novell® Making IT Work As One

© 2008 Novell, Inc. All Rights Reserved.