~cv_cancellation_guard() { if (!_registered || RETHREAD_LIKELY(try_unregister(_token, _handler))) return; // We need to unlock mutex before unregistering, because canceller thread // can get stuck at mutex in cv_cancellation_handler::cancel(). // When unregister returns, we are sure that canceller has left cancel(), so it is safe to lock mutex back. reverse_lock<typename Handler::lock_type> ul(_handler.get_lock()); unregister(_token, _handler); }
/////////////////////////////////////////////////////////////////////////////// // // FUNCTION NAME: main // // PROCESSING: // // This function tests the register, unregister, and yield functions from // user space. // // INPUTS: // // argc - the number of arguments passed to the program // argv - the command line vector that contains the arguments passed to the program // // RETURN: // // int - (0) default with no errors // (-1) unable to register the PID // // IMPLEMENTATION NOTES // // The main function tests all the functions that were implemented in kernel // space that the user-space application will use in order to register and // unregister with the kernel module, and to change it status using yield. // /////////////////////////////////////////////////////////////////////////////// int main(int argc, char* argv[]) { pid_t mypid; int j; long period = 250; // in milliseconds long processTime = 10; // in milliseconds // get our PID so that we can register mypid= syscall(__NR_gettid); // register with the module if(!try_register(mypid, period, processTime)){ printf("Unable to register this PID %ld\n", mypid); return -1; } struct timeval tv; gettimeofday(&tv, NULL); printf("Current time %d\n", tv.tv_sec); // writes yield to proc/mp2/status file for this pid try_yielding(mypid); gettimeofday(&tv, NULL); printf("Current time %d\n", tv.tv_sec); for(j=1; j<100; j++) { printf("Factorial %u: %llu\n",j, factorial(10)); try_yielding(mypid); gettimeofday(&tv, NULL); printf("Current time %d\n", tv.tv_sec); } // unregister from the module if(try_unregister(mypid)){ printf("We successfully unregistered from the module!\n"); }else{ printf("We are still registered...\n"); } }