comparison VSs.c @ 37:c8d4f6d3c7d3

hide animating VP and entry point
author Nina Engelhardt <nengel@mailbox.tu-berlin.de>
date Wed, 15 May 2013 15:25:55 +0200
parents 227db52cbd93
children a951b38d2cfc
comparison
equal deleted inserted replaced
27:cf26c0bfa329 29:2a31d1f6f051
181 181
182 VSs__init_Helper(); 182 VSs__init_Helper();
183 } 183 }
184 184
185 185
186 void idle_fn(void* data, SlaveVP *animatingSlv){ 186 void idle_fn(void* data){
187 while(1){ 187 while(1){
188 VMS_int__suspend_slaveVP_and_send_req(animatingSlv); 188 VMS_int__suspend_slaveVP_and_send_req(currVP);
189 } 189 }
190 } 190 }
191 191
192 void 192 void
193 VSs__init_Helper() 193 VSs__init_Helper()
485 * this. 485 * this.
486 * 486 *
487 *It simply sends a dissipate request, which handles all the state cleanup. 487 *It simply sends a dissipate request, which handles all the state cleanup.
488 */ 488 */
489 void 489 void
490 VSs__end_thread( SlaveVP *thdToEnd ) 490 VSs__end_thread()
491 { 491 {
492 492
493 VMS_WL__send_dissipate_req( thdToEnd ); 493 VMS_WL__send_dissipate_req( currVP );
494 } 494 }
495 495
496 496
497 497
498 //=========================================================================== 498 //===========================================================================
500 500
501 //======================= task submit and end ============================== 501 //======================= task submit and end ==============================
502 /* 502 /*
503 */ 503 */
504 void 504 void
505 VSs__submit_task( VSsTaskType *taskType, void *args, SlaveVP *animSlv) 505 VSs__submit_task( VSsTaskType *taskType, void *args)
506 { VSsSemReq reqData; 506 { VSsSemReq reqData;
507 507
508 reqData.reqType = submit_task; 508 reqData.reqType = submit_task;
509 509
510 reqData.taskType = taskType; 510 reqData.taskType = taskType;
511 reqData.args = args; 511 reqData.args = args;
512 reqData.callingSlv = animSlv; 512 reqData.callingSlv = currVP;
513 513
514 reqData.taskID = NULL; 514 reqData.taskID = NULL;
515 515
516 VMS_WL__send_sem_request( &reqData, animSlv ); 516 VMS_WL__send_sem_request( &reqData, currVP );
517 } 517 }
518 518
519 int32 * 519 int32 *
520 VSs__create_taskID_of_size( int32 numInts, SlaveVP *animSlv ) 520 VSs__create_taskID_of_size( int32 numInts)
521 { int32 *taskID; 521 { int32 *taskID;
522 522
523 taskID = VMS_WL__malloc( sizeof(int32) + numInts * sizeof(int32) ); 523 taskID = VMS_WL__malloc( sizeof(int32) + numInts * sizeof(int32) );
524 taskID[0] = numInts; 524 taskID[0] = numInts;
525 return taskID; 525 return taskID;
526 } 526 }
527 527
528 void 528 void
529 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID, 529 VSs__submit_task_with_ID( VSsTaskType *taskType, void *args, int32 *taskID)
530 SlaveVP *animSlv)
531 { VSsSemReq reqData; 530 { VSsSemReq reqData;
532 531
533 reqData.reqType = submit_task; 532 reqData.reqType = submit_task;
534 533
535 reqData.taskType = taskType; 534 reqData.taskType = taskType;
536 reqData.args = args; 535 reqData.args = args;
537 reqData.taskID = taskID; 536 reqData.taskID = taskID;
538 reqData.callingSlv = animSlv; 537 reqData.callingSlv = currVP;
539 538
540 VMS_WL__send_sem_request( &reqData, animSlv ); 539 VMS_WL__send_sem_request( &reqData, currVP );
541 } 540 }
542 541
543 542
544 /*This call is the last to happen in every task. It causes the slave to 543 /*This call is the last to happen in every task. It causes the slave to
545 * suspend and get the next task out of the task-queue. Notice there is no 544 * suspend and get the next task out of the task-queue. Notice there is no
557 * slave from having the core number. 556 * slave from having the core number.
558 * 557 *
559 *But, to stay compatible with all the other VMS languages, leave it in.. 558 *But, to stay compatible with all the other VMS languages, leave it in..
560 */ 559 */
561 void 560 void
562 VSs__end_task( SlaveVP *animSlv ) 561 VSs__end_task()
563 { VSsSemReq reqData; 562 { VSsSemReq reqData;
564 563
565 reqData.reqType = end_task; 564 reqData.reqType = end_task;
566 reqData.callingSlv = animSlv; 565 reqData.callingSlv = currVP;
567 566
568 VMS_WL__send_sem_request( &reqData, animSlv ); 567 VMS_WL__send_sem_request( &reqData, currVP );
569 } 568 }
570 569
571 570 void plugin__end_VP(){
572 void 571 VSs__end_task();}
573 VSs__taskwait(SlaveVP *animSlv) 572
573 void
574 VSs__taskwait()
574 { 575 {
575 VSsSemReq reqData; 576 VSsSemReq reqData;
576 577
577 reqData.reqType = taskwait; 578 reqData.reqType = taskwait;
578 reqData.callingSlv = animSlv; 579 reqData.callingSlv = currVP;
579 580
580 VMS_WL__send_sem_request( &reqData, animSlv ); 581 VMS_WL__send_sem_request( &reqData, currVP );
581 } 582 }
582 583
583 void 584 void
584 VSs__taskwait_on(SlaveVP *animSlv,void* ptr){ 585 VSs__taskwait_on(void* ptr){
585 VSsSemReq reqData; 586 VSsSemReq reqData;
586 587
587 reqData.reqType = taskwait_on; 588 reqData.reqType = taskwait_on;
588 reqData.callingSlv = animSlv; 589 reqData.callingSlv = currVP;
589 590
590 reqData.args = ptr; 591 reqData.args = ptr;
591 592
592 VMS_WL__send_sem_request( &reqData, animSlv ); 593 VMS_WL__send_sem_request( &reqData, currVP );
593 } 594 }
594 595
595 void 596 void
596 VSs__start_critical(SlaveVP *animSlv,int32 name){ 597 VSs__start_critical(int32 name){
597 VSsSemReq reqData; 598 VSsSemReq reqData;
598 599
599 reqData.reqType = critical_start; 600 reqData.reqType = critical_start;
600 reqData.callingSlv = animSlv; 601 reqData.callingSlv = currVP;
601 602
602 reqData.criticalID = name; 603 reqData.criticalID = name;
603 604
604 VMS_WL__send_sem_request( &reqData, animSlv ); 605 VMS_WL__send_sem_request( &reqData, currVP );
605 } 606 }
606 607
607 void 608 void
608 VSs__end_critical(SlaveVP *animSlv,int32 name){ 609 VSs__end_critical(int32 name){
609 VSsSemReq reqData; 610 VSsSemReq reqData;
610 611
611 reqData.reqType = critical_end; 612 reqData.reqType = critical_end;
612 reqData.callingSlv = animSlv; 613 reqData.callingSlv = currVP;
613 614
614 reqData.criticalID = name; 615 reqData.criticalID = name;
615 616
616 VMS_WL__send_sem_request( &reqData, animSlv ); 617 VMS_WL__send_sem_request( &reqData, currVP );
617 } 618 }
618 619
619 //========================== send and receive ============================ 620 //========================== send and receive ============================
620 // 621 //
621 622
622 int32 * 623 int32 *
623 VSs__give_self_taskID( SlaveVP *animSlv ) 624 VSs__give_self_taskID()
624 { 625 {
625 return ((VSsSemData*)animSlv->semanticData)->taskStub->taskID; 626 return ((VSsSemData*)currVP->semanticData)->taskStub->taskID;
626 } 627 }
627 628
628 //================================ send =================================== 629 //================================ send ===================================
629 630
630 void 631 void
631 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID, 632 VSs__send_of_type_to( void *msg, const int32 type, int32 *receiverID)
632 SlaveVP *senderSlv )
633 { VSsSemReq reqData; 633 { VSsSemReq reqData;
634 634
635 reqData.reqType = send_type_to; 635 reqData.reqType = send_type_to;
636 636
637 reqData.msg = msg; 637 reqData.msg = msg;
638 reqData.msgType = type; 638 reqData.msgType = type;
639 reqData.receiverID = receiverID; 639 reqData.receiverID = receiverID;
640 reqData.senderSlv = senderSlv; 640 reqData.senderSlv = currVP;
641 641
642 reqData.nextReqInHashEntry = NULL; 642 reqData.nextReqInHashEntry = NULL;
643 643
644 VMS_WL__send_sem_request( &reqData, senderSlv ); 644 VMS_WL__send_sem_request( &reqData, currVP );
645 645
646 //When come back from suspend, no longer own data reachable from msg 646 //When come back from suspend, no longer own data reachable from msg
647 } 647 }
648 648
649 void 649 void
650 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID, SlaveVP *senderSlv ) 650 VSs__send_from_to( void *msg, int32 *senderID, int32 *receiverID)
651 { VSsSemReq reqData; 651 { VSsSemReq reqData;
652 652
653 reqData.reqType = send_from_to; 653 reqData.reqType = send_from_to;
654 654
655 reqData.msg = msg; 655 reqData.msg = msg;
656 reqData.senderID = senderID; 656 reqData.senderID = senderID;
657 reqData.receiverID = receiverID; 657 reqData.receiverID = receiverID;
658 reqData.senderSlv = senderSlv; 658 reqData.senderSlv = currVP;
659 659
660 reqData.nextReqInHashEntry = NULL; 660 reqData.nextReqInHashEntry = NULL;
661 661
662 VMS_WL__send_sem_request( &reqData, senderSlv ); 662 VMS_WL__send_sem_request( &reqData, currVP );
663 } 663 }
664 664
665 665
666 //================================ receive ================================ 666 //================================ receive ================================
667 667
670 * received. The same receiver can also have send from-to's 670 * received. The same receiver can also have send from-to's
671 * waiting for it, and those will be kept separate from the "type" 671 * waiting for it, and those will be kept separate from the "type"
672 * messages. 672 * messages.
673 */ 673 */
674 void * 674 void *
675 VSs__receive_type_to( const int32 type, int32* receiverID, SlaveVP *receiverSlv ) 675 VSs__receive_type_to( const int32 type, int32* receiverID )
676 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to %d",receiverID[1] ); 676 { DEBUG__printf1(dbgRqstHdlr,"WL: receive type to %d",receiverID[1] );
677 VSsSemReq reqData; 677 VSsSemReq reqData;
678 678
679 reqData.reqType = receive_type_to; 679 reqData.reqType = receive_type_to;
680 680
681 reqData.msgType = type; 681 reqData.msgType = type;
682 reqData.receiverID = receiverID; 682 reqData.receiverID = receiverID;
683 reqData.receiverSlv = receiverSlv; 683 reqData.receiverSlv = currVP;
684 684
685 reqData.nextReqInHashEntry = NULL; 685 reqData.nextReqInHashEntry = NULL;
686 686
687 VMS_WL__send_sem_request( &reqData, receiverSlv ); 687 VMS_WL__send_sem_request( &reqData, currVP );
688 688
689 return receiverSlv->dataRetFromReq; 689 return currVP->dataRetFromReq;
690 } 690 }
691 691
692 692
693 693
694 /*Call this at the point a receiving task wants in-coming data. 694 /*Call this at the point a receiving task wants in-coming data.
695 * Use this from-to form when know senderID -- it makes a direct channel 695 * Use this from-to form when know senderID -- it makes a direct channel
696 * between sender and receiver. 696 * between sender and receiver.
697 */ 697 */
698 void * 698 void *
699 VSs__receive_from_to( int32 *senderID, int32 *receiverID, SlaveVP *receiverSlv ) 699 VSs__receive_from_to( int32 *senderID, int32 *receiverID)
700 { 700 {
701 VSsSemReq reqData; 701 VSsSemReq reqData;
702 702
703 reqData.reqType = receive_from_to; 703 reqData.reqType = receive_from_to;
704 704
705 reqData.senderID = senderID; 705 reqData.senderID = senderID;
706 reqData.receiverID = receiverID; 706 reqData.receiverID = receiverID;
707 reqData.receiverSlv = receiverSlv; 707 reqData.receiverSlv = currVP;
708 708
709 reqData.nextReqInHashEntry = NULL; 709 reqData.nextReqInHashEntry = NULL;
710 DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", reqData.senderID[1], reqData.receiverID[1]); 710 DEBUG__printf2(dbgRqstHdlr,"WL: receive from %d to: %d", reqData.senderID[1], reqData.receiverID[1]);
711 711
712 VMS_WL__send_sem_request( &reqData, receiverSlv ); 712 VMS_WL__send_sem_request( &reqData, currVP );
713 713
714 return receiverSlv->dataRetFromReq; 714 return currVP->dataRetFromReq;
715 } 715 }
716 716
717 717
718 718
719 719
735 735
736 /*Fn singleton uses ID as index into array of singleton structs held in the 736 /*Fn singleton uses ID as index into array of singleton structs held in the
737 * semantic environment. 737 * semantic environment.
738 */ 738 */
739 void 739 void
740 VSs__start_fn_singleton( int32 singletonID, SlaveVP *animSlv ) 740 VSs__start_fn_singleton( int32 singletonID)
741 { 741 {
742 VSsSemReq reqData; 742 VSsSemReq reqData;
743 743
744 // 744 //
745 reqData.reqType = singleton_fn_start; 745 reqData.reqType = singleton_fn_start;
746 reqData.singletonID = singletonID; 746 reqData.singletonID = singletonID;
747 747
748 VMS_WL__send_sem_request( &reqData, animSlv ); 748 VMS_WL__send_sem_request( &reqData, currVP );
749 if( animSlv->dataRetFromReq ) //will be 0 or addr of label in end singleton 749 if( currVP->dataRetFromReq ) //will be 0 or addr of label in end singleton
750 { 750 {
751 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv ); 751 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( currVP );
752 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); 752 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
753 } 753 }
754 } 754 }
755 755
756 /*Data singleton hands addr of loc holding a pointer to a singleton struct. 756 /*Data singleton hands addr of loc holding a pointer to a singleton struct.
757 * The start_data_singleton makes the structure and puts its addr into the 757 * The start_data_singleton makes the structure and puts its addr into the
758 * location. 758 * location.
759 */ 759 */
760 void 760 void
761 VSs__start_data_singleton( VSsSingleton **singletonAddr, SlaveVP *animSlv ) 761 VSs__start_data_singleton( VSsSingleton **singletonAddr )
762 { 762 {
763 VSsSemReq reqData; 763 VSsSemReq reqData;
764 764
765 if( *singletonAddr && (*singletonAddr)->hasFinished ) 765 if( *singletonAddr && (*singletonAddr)->hasFinished )
766 goto JmpToEndSingleton; 766 goto JmpToEndSingleton;
767 767
768 reqData.reqType = singleton_data_start; 768 reqData.reqType = singleton_data_start;
769 reqData.singletonPtrAddr = singletonAddr; 769 reqData.singletonPtrAddr = singletonAddr;
770 770
771 VMS_WL__send_sem_request( &reqData, animSlv ); 771 VMS_WL__send_sem_request( &reqData, currVP );
772 if( animSlv->dataRetFromReq ) //either 0 or end singleton's return addr 772 if( currVP->dataRetFromReq ) //either 0 or end singleton's return addr
773 { //Assembly code changes the return addr on the stack to the one 773 { //Assembly code changes the return addr on the stack to the one
774 // saved into the singleton by the end-singleton-fn 774 // saved into the singleton by the end-singleton-fn
775 //The return addr is at 0x4(%%ebp) 775 //The return addr is at 0x4(%%ebp)
776 JmpToEndSingleton: 776 JmpToEndSingleton:
777 asm_write_ret_from_singleton(*singletonAddr); 777 asm_write_ret_from_singleton(*singletonAddr);
785 * 785 *
786 *Note, this call cannot be inlined because the instr addr at the label 786 *Note, this call cannot be inlined because the instr addr at the label
787 * inside is shared by all invocations of a given singleton ID. 787 * inside is shared by all invocations of a given singleton ID.
788 */ 788 */
789 void 789 void
790 VSs__end_fn_singleton( int32 singletonID, SlaveVP *animSlv ) 790 VSs__end_fn_singleton( int32 singletonID )
791 { 791 {
792 VSsSemReq reqData; 792 VSsSemReq reqData;
793 793
794 //don't need this addr until after at least one singleton has reached 794 //don't need this addr until after at least one singleton has reached
795 // this function 795 // this function
796 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( animSlv ); 796 VSsSemEnv *semEnv = VMS_int__give_sem_env_for( currVP );
797 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID])); 797 asm_write_ret_from_singleton(&(semEnv->fnSingletons[ singletonID]));
798 798
799 reqData.reqType = singleton_fn_end; 799 reqData.reqType = singleton_fn_end;
800 reqData.singletonID = singletonID; 800 reqData.singletonID = singletonID;
801 801
802 VMS_WL__send_sem_request( &reqData, animSlv ); 802 VMS_WL__send_sem_request( &reqData, currVP );
803 803
804 //EndSingletonInstrAddr: 804 //EndSingletonInstrAddr:
805 return; 805 return;
806 } 806 }
807 807
808 void 808 void
809 VSs__end_data_singleton( VSsSingleton **singletonPtrAddr, SlaveVP *animSlv ) 809 VSs__end_data_singleton( VSsSingleton **singletonPtrAddr )
810 { 810 {
811 VSsSemReq reqData; 811 VSsSemReq reqData;
812 812
813 //don't need this addr until after singleton struct has reached 813 //don't need this addr until after singleton struct has reached
814 // this function for first time 814 // this function for first time
822 asm_save_ret_to_singleton(*singletonPtrAddr); 822 asm_save_ret_to_singleton(*singletonPtrAddr);
823 823
824 reqData.reqType = singleton_data_end; 824 reqData.reqType = singleton_data_end;
825 reqData.singletonPtrAddr = singletonPtrAddr; 825 reqData.singletonPtrAddr = singletonPtrAddr;
826 826
827 VMS_WL__send_sem_request( &reqData, animSlv ); 827 VMS_WL__send_sem_request( &reqData, currVP );
828 } 828 }
829 829
830 /*This executes the function in the masterVP, so it executes in isolation 830 /*This executes the function in the masterVP, so it executes in isolation
831 * from any other copies -- only one copy of the function can ever execute 831 * from any other copies -- only one copy of the function can ever execute
832 * at a time. 832 * at a time.
837 * isolation, use transaction-start and transaction-end, which run the code 837 * isolation, use transaction-start and transaction-end, which run the code
838 * between as work-code. 838 * between as work-code.
839 */ 839 */
840 void 840 void
841 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster, 841 VSs__animate_short_fn_in_isolation( PtrToAtomicFn ptrToFnToExecInMaster,
842 void *data, SlaveVP *animSlv ) 842 void *data )
843 { 843 {
844 VSsSemReq reqData; 844 VSsSemReq reqData;
845 845
846 // 846 //
847 reqData.reqType = atomic; 847 reqData.reqType = atomic;
848 reqData.fnToExecInMaster = ptrToFnToExecInMaster; 848 reqData.fnToExecInMaster = ptrToFnToExecInMaster;
849 reqData.dataForFn = data; 849 reqData.dataForFn = data;
850 850
851 VMS_WL__send_sem_request( &reqData, animSlv ); 851 VMS_WL__send_sem_request( &reqData, currVP );
852 } 852 }
853 853
854 854
855 /*This suspends to the master. 855 /*This suspends to the master.
856 *First, it looks at the VP's data, to see the highest transactionID that VP 856 *First, it looks at the VP's data, to see the highest transactionID that VP
864 * into queue in the struct. (At some point a holder will request 864 * into queue in the struct. (At some point a holder will request
865 * end-transaction, which will take this VP from the queue and resume it.) 865 * end-transaction, which will take this VP from the queue and resume it.)
866 *If NULL, then write requesting into the field and resume. 866 *If NULL, then write requesting into the field and resume.
867 */ 867 */
868 void 868 void
869 VSs__start_transaction( int32 transactionID, SlaveVP *animSlv ) 869 VSs__start_transaction( int32 transactionID )
870 { 870 {
871 VSsSemReq reqData; 871 VSsSemReq reqData;
872 872
873 // 873 //
874 reqData.callingSlv = animSlv; 874 reqData.callingSlv = currVP;
875 reqData.reqType = trans_start; 875 reqData.reqType = trans_start;
876 reqData.transID = transactionID; 876 reqData.transID = transactionID;
877 877
878 VMS_WL__send_sem_request( &reqData, animSlv ); 878 VMS_WL__send_sem_request( &reqData, currVP );
879 } 879 }
880 880
881 /*This suspends to the master, then uses transactionID as index into an 881 /*This suspends to the master, then uses transactionID as index into an
882 * array of transaction structures. 882 * array of transaction structures.
883 *It looks at VP_currently_executing to be sure it's same as requesting VP. 883 *It looks at VP_currently_executing to be sure it's same as requesting VP.
886 *If it's empty, it sets VP_currently_executing field to NULL and resumes. 886 *If it's empty, it sets VP_currently_executing field to NULL and resumes.
887 *If something in, gets it, sets VP_currently_executing to that VP, then 887 *If something in, gets it, sets VP_currently_executing to that VP, then
888 * resumes both. 888 * resumes both.
889 */ 889 */
890 void 890 void
891 VSs__end_transaction( int32 transactionID, SlaveVP *animSlv ) 891 VSs__end_transaction( int32 transactionID )
892 { 892 {
893 VSsSemReq reqData; 893 VSsSemReq reqData;
894 894
895 // 895 //
896 reqData.callingSlv = animSlv; 896 reqData.callingSlv = currVP;
897 reqData.reqType = trans_end; 897 reqData.reqType = trans_end;
898 reqData.transID = transactionID; 898 reqData.transID = transactionID;
899 899
900 VMS_WL__send_sem_request( &reqData, animSlv ); 900 VMS_WL__send_sem_request( &reqData, currVP );
901 } 901 }
902 902
903 //======================== Internal ================================== 903 //======================== Internal ==================================
904 /* 904 /*
905 */ 905 */
939 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv ); 939 VMS_WL__send_create_slaveVP_req( &reqData, creatingSlv );
940 940
941 return creatingSlv->dataRetFromReq; 941 return creatingSlv->dataRetFromReq;
942 } 942 }
943 943
944 int __main_ret;
945
946 void __entry_point(void* _args) {
947 __main_args* args = (__main_args*) _args;
948 __main_ret = __program_main(args->argc, args->argv);
949 VSs__end_thread();
950 }
951
952 #undef main
953
954 int main(int argc, char** argv) {
955 __main_args args;
956 args.argc = argc;
957 args.argv = argv;
958 VSs__create_seed_slave_and_do_work(__entry_point, (void*) &args);
959 return __main_ret;
960 }