home *** CD-ROM | disk | FTP | other *** search
/ ftp.parl.clemson.edu / 2015-02-07.ftp.parl.clemson.edu.tar / ftp.parl.clemson.edu / pub / pvfs2 / orangefs-2.8.3-20110323.tar.gz / orangefs-2.8.3-20110323.tar / orangefs / test / io / buffer / mt_test2.c < prev    next >
C/C++ Source or Header  |  2006-10-18  |  4KB  |  145 lines

  1. /* In this test, multiple threads performs writes on the same file. */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <pthread.h>
  6.  
  7. #include "ncac-interface.h"
  8. #include "internal.h"
  9.  
  10. #include "trove.h"
  11.  
  12. #include "trove-init.c"
  13. #include "pvfs2-internal.h"
  14.  
  15. extern void   cache_dump_active_list(void);
  16. extern void   cache_dump_inactive_list(void);
  17.  
  18. TROVE_coll_id coll_id;
  19. TROVE_handle file_handle;
  20. TROVE_context_id trove_context;
  21.  
  22. void do_io_write(int *myid);
  23.  
  24. int main(int argc, char * argv[])
  25. {
  26.     NCAC_info_t info;
  27.  
  28.     int ret1, ret2, ret3;
  29.  
  30.     pthread_t thread1, thread2, thread3;
  31.  
  32.     trove_init( &coll_id, &file_handle, &trove_context );
  33.  
  34.     info.max_req_num = 1000;
  35.     info.extsize     = 32768;
  36.     info.cachesize   = 1048576;
  37.  
  38.  
  39.     cache_init(&info);
  40.    
  41.     if (pthread_create(&thread1,
  42.                  NULL,
  43.                  (void *) do_io_write,
  44.                  (void *) &ret1) != 0)
  45.         perror("pthread_create"), exit(1);
  46.  
  47.     if (pthread_create(&thread2,
  48.                  NULL,
  49.                  (void *) do_io_write,
  50.                  (void *) &ret2) != 0)
  51.         perror("pthread_create"), exit(1);
  52.  
  53.     if (pthread_create(&thread3,
  54.                  NULL,
  55.                  (void *) do_io_write,
  56.                  (void *) &ret3) != 0)
  57.         perror("pthread_create"), exit(1);
  58.  
  59.     if (pthread_join(thread1, NULL) != 0)
  60.         perror("pthread_join"),exit(1);
  61.  
  62.     if (pthread_join(thread2, NULL) != 0)
  63.         perror("pthread_join"),exit(1);
  64.  
  65.     if (pthread_join(thread3, NULL) != 0)
  66.         perror("pthread_join"),exit(1);
  67.  
  68.     trove_close_context(coll_id, trove_context);
  69.     trove_finalize(TROVE_METHOD_DBPF);
  70.  
  71.     cache_dump_active_list();
  72.     cache_dump_inactive_list();
  73.  
  74.     return 0;
  75. }
  76.  
  77. void do_io_write(int *result)
  78. {
  79.     PVFS_offset offarr[100];
  80.     PVFS_size sizearr[100];
  81.  
  82.     cache_write_desc_t desc;
  83.     cache_request_t request[100];
  84.     cache_reply_t reply[100];
  85.  
  86.     int flag;
  87.     int ret;
  88.     int i;
  89.     int loop=10;
  90.     int ncnt;
  91.  
  92.     desc.coll_id     = coll_id;
  93.     desc.handle     = file_handle;
  94.     desc.context_id     = trove_context;
  95.  
  96.     desc.buffer = 0;
  97.     desc.len    = 0;
  98.  
  99.     desc.stream_array_count=1;
  100.     desc.stream_offset_array = offarr;
  101.     desc.stream_size_array = sizearr;
  102.  
  103.     for ( i = 0; i< loop; i++ ) {
  104.         offarr[0] = i*65536+1024;
  105.         sizearr[0] = 32768;
  106.     
  107.         ret = cache_write_post(&desc, &request[0], &reply[0], NULL);
  108.         if (ret<0){
  109.             fprintf(stderr, "cache_write_post error\n");
  110.         }else{
  111.             fprintf(stderr, "cache_write_post ok: status: %d, cbufcnt=%d\n", request[0].status, reply[0].count);
  112.         }
  113.  
  114.  
  115.         while ( 1 ) {    
  116.                ret = cache_req_test(&request[0], &flag, &reply[0], NULL);
  117.             if (ret<0){
  118.                 fprintf(stderr, "cache_req_test error\n");
  119.             }else{
  120.                 if (flag){
  121.                     fprintf(stderr, "cache_req_test ok: flag=%d, status: %d, cbufcnt=%d\n", flag, request[0].status, reply[0].count);
  122.  
  123.                     for ( ncnt=0; ncnt < reply[0].count; ncnt ++ ) {
  124.                         fprintf(stderr, "[%d] %p len:%lld\n", ncnt,
  125.                                     reply[0].cbuf_offset_array[ncnt], 
  126.                                     lld(reply[0].cbuf_size_array[ncnt]));
  127.                     }
  128.                 }
  129.             }
  130.  
  131.             if (flag){
  132.                 ret = cache_req_done(&request[0]);
  133.                 if (ret<0){
  134.                        fprintf(stderr, "cache_req_done error\n");
  135.                 }else
  136.                     fprintf(stderr, "cache_req_done ok---\n");
  137.                 break;
  138.             }
  139.         }
  140.  
  141.     }
  142.  
  143.     *result = ret;
  144. }
  145.