diff options
| author | Vasilii Chernov <vchernov@inr.ru> | 2016-02-24 18:24:22 +0100 | 
|---|---|---|
| committer | Vasilii Chernov <vchernov@inr.ru> | 2016-02-24 18:24:22 +0100 | 
| commit | b0a034e6ef4a958235a56ebde0831c0f30a84d30 (patch) | |
| tree | a1f46d2d536c692edd6b17efc61ac9fefef2796b /apps | |
| parent | da842568b94b0e00c1709ae01f441a7424c15b87 (diff) | |
| parent | 3ea1907f3169e0233d3a32a7d470af3c34b6f967 (diff) | |
| download | pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.gz pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.bz2 pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.tar.xz pcitool-b0a034e6ef4a958235a56ebde0831c0f30a84d30.zip | |
Merge with Suren branch. Fix memory leaks.
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/CMakeLists.txt | 7 | ||||
| -rw-r--r-- | apps/test_multithread.c | 136 | 
2 files changed, 71 insertions, 72 deletions
| diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 2a1471c..45d627b 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -7,10 +7,6 @@ link_directories(      ${CMAKE_BINARY_DIR}/pcilib  ) -find_package (Threads) -add_executable(test_multithread test_multithread.c) -target_link_libraries (test_multithread pcilib ${CMAKE_THREAD_LIBS_INIT}) -  add_executable(xilinx xilinx.c)  target_link_libraries(xilinx pcilib rt) @@ -21,3 +17,6 @@ add_executable(compare_to_value compare_to_value.c)  add_executable(heb_strip_bad_values heb_strip_bad_values.c)  add_executable(check_counter check_counter.c) + +add_executable(test_multithread test_multithread.c) +target_link_libraries (test_multithread pcilib ${CMAKE_THREAD_LIBS_INIT}) diff --git a/apps/test_multithread.c b/apps/test_multithread.c index 19026cc..4d0e8f2 100644 --- a/apps/test_multithread.c +++ b/apps/test_multithread.c @@ -9,84 +9,84 @@ int stop = 0;  void *get_prop(void *arg)  { -	pcilib_t *ctx = (pcilib_t*)arg; +    pcilib_t *ctx = (pcilib_t*)arg; -	while(!stop) -	{ -		int err; -		pcilib_value_t val = {0}; -		err = pcilib_get_property(ctx, prop, &val); -		if(err) -		{ -			printf("err pcilib_read_register\n"); -			return NULL; -		} -		long value = pcilib_get_value_as_int(ctx, &val, &err); -		pcilib_clean_value(ctx, &val); -		if(err) -		{ -			printf("err pcilib_get_value_as_int\n"); -			return NULL; -		} -		printf("reg = %lu\n", value); -	} -	return NULL; +    while(!stop) +    { +        int err; +        pcilib_value_t val = {0}; +        err = pcilib_get_property(ctx, prop, &val); +        if(err) +        { +            printf("err pcilib_read_register\n"); +            return NULL; +        } +        long value = pcilib_get_value_as_int(ctx, &val, &err); +        pcilib_clean_value(ctx, &val); +        if(err) +        { +            printf("err pcilib_get_value_as_int\n"); +            return NULL; +        } +        printf("reg = %li\n", value); +    } +    return NULL;  }  void *read_reg(void *arg)  { -	pcilib_t *ctx = (pcilib_t*)arg; +    pcilib_t *ctx = (pcilib_t*)arg; + +    while(!stop) +    { +        int err; +        pcilib_register_value_t reg_val = {0}; +        pcilib_value_t val = {0}; -	while(!stop) -	{ -		int err; -		pcilib_register_value_t reg_val = {0}; -		pcilib_value_t val = {0}; -		 -		err = pcilib_read_register(ctx, NULL, reg, ®_val); -		 -		if(err) -		{ -			printf("err pcilib_read_register\n"); -			return NULL; -		} -		err = pcilib_set_value_from_register_value(ctx, &val, reg_val); -		if(err) -		{ -			printf("err pcilib_set_value_from_register_value\n"); -			return NULL; -		} -		long value = pcilib_get_value_as_int(ctx, &val, &err); -		pcilib_clean_value(ctx, &val); -		if(err) -		{ -			printf("err pcilib_get_value_as_int\n"); -			return NULL; -		} -		printf("reg = %lu\n", value); -	} -	return NULL; +        err = pcilib_read_register(ctx, NULL, reg, ®_val); + +        if(err) +        { +            printf("err pcilib_read_register\n"); +            return NULL; +        } +        err = pcilib_set_value_from_register_value(ctx, &val, reg_val); +        if(err) +        { +            printf("err pcilib_set_value_from_register_value\n"); +            return NULL; +        } +        long value = pcilib_get_value_as_int(ctx, &val, &err); +        pcilib_clean_value(ctx, &val); +        if(err) +        { +            printf("err pcilib_get_value_as_int\n"); +            return NULL; +        } +        printf("reg = %li\n", value); +    } +    return NULL;  }  int main(int argc, char *argv[])  { -	if (argc < 5) { -		printf("Usage:\n\t\t%s <device> <model> <register> <num_threads>\n", argv[0]); -		exit(0); +    if (argc < 5) { +        printf("Usage:\n\t\t%s <device> <model> <register> <num_threads>\n", argv[0]); +        exit(0); +    } + +    reg = argv[3]; +    int threads = atoi( argv[4] ); + +    pcilib_t *ctx = pcilib_open(argv[1], argv[2]); + +    for(int i = 0; i < threads; i++) +    { +        pthread_t pth; +        pthread_create(&pth, NULL, read_reg, ctx);      } -	reg = argv[3]; -	int threads = atoi( argv[4] ); -	 -	pcilib_t *ctx = pcilib_open(argv[1], argv[2]); -	 -	for(int i = 0; i < threads; i++) -	{ -		pthread_t pth; -		pthread_create(&pth, NULL, read_reg, ctx); -	} -    -   getchar(); -   stop = 1; -   return 0; +    getchar(); +    stop = 1; +    return 0;  } | 
