Code Monkey home page Code Monkey logo

Comments (6)

mu578 avatar mu578 commented on August 15, 2024 8

On top use that instead of forcing the _POSIX_C_SOURCE define :

#	if defined(__APPLE__)
#		include <AvailabilityMacros.h>
#	else
#		ifndef _POSIX_C_SOURCE
#			define _POSIX_C_SOURCE 200809L
#		endif
#	endif

c99-pedantic.patch
(Tested : compile without any warnings or errors (BTW you can't dereference func_ptr to void* : nada verboten): on Debian 7, iOS (min-version 6.0) and MacOS (min-version 10.7), Android (min-version lollipop) gcc, gcc-clang and clang toolchains)

--- thpool_original.c	2018-03-21 13:46:04.000000000 -0700
+++ thpool_pedantic.c	2018-03-21 13:45:05.000000000 -0700
@@ -8,7 +8,17 @@
  *
  ********************************/
 
-#define _POSIX_C_SOURCE 200809L
+
+#	if defined(__APPLE__)
+#		include <AvailabilityMacros.h>
+#	else
+#		ifndef _POSIX_C_SOURCE
+#			define _POSIX_C_SOURCE 200809L
+#		elif _POSIX_C_SOURCE < 200809L
+#			error "Valid _POSIX_C_SOURCE version required."
+#		endif
+#	endif
+
 #include <unistd.h>
 #include <signal.h>
 #include <stdio.h>
@@ -94,7 +104,7 @@
 
 
 static int  thread_init(thpool_* thpool_p, struct thread** thread_p, int id);
-static void* thread_do(struct thread* thread_p);
+static void* thread_do(void * arg);
 static void  thread_hold(int sig_id);
 static void  thread_destroy(struct thread* thread_p);
 
@@ -123,8 +133,8 @@
 	threads_on_hold   = 0;
 	threads_keepalive = 1;
 
-	if (num_threads < 0){
-		num_threads = 0;
+	if (num_threads < 1){
+		num_threads = 1;
 	}
 
 	/* Make new thread pool */
@@ -290,7 +300,7 @@
 	(*thread_p)->thpool_p = thpool_p;
 	(*thread_p)->id       = id;
 
-	pthread_create(&(*thread_p)->pthread, NULL, (void *)thread_do, (*thread_p));
+	pthread_create(&(*thread_p)->pthread, NULL, thread_do, (*thread_p));
 	pthread_detach((*thread_p)->pthread);
 	return 0;
 }
@@ -314,8 +324,13 @@
 * @param  thread        thread that will run this function
 * @return nothing
 */
-static void* thread_do(struct thread* thread_p){
+static void* thread_do(void * arg){
 
+	struct thread * thread_p = (struct thread *)arg;
+	if (thread_p == NULL){
+		err("thread_do(): Could not access cookie\n");
+		return NULL;
+	}
 	/* Set thread name for profiling and debuging */
 	char thread_name[128] = {0};
 	sprintf(thread_name, "thread-pool-%d", thread_p->id);

from c-thread-pool.

mnunberg avatar mnunberg commented on August 15, 2024 3

FWIW, this is what's on my system. All the _np decls are guarded by this. It seems you might have luck with _DARWIN_C_SOURCE.

#if (!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || defined(_DARWIN_C_SOURCE)

/* returns non-zero if pthread_create or cthread_fork have been called */
__OSX_AVAILABLE_STARTING(__MAC_10_4, __IPHONE_2_0)
int pthread_is_threaded_np(void);

from c-thread-pool.

Pithikos avatar Pithikos commented on August 15, 2024

I can't really recall exactly the reasoning behind it (my commit should probably be more informative).

However my gut feeling is that the macro is overriding existing information in your case. Do you think you can try the below on a Mac and see if it solves it?

#if ! defined(_POSIX_C_SOURCE)
#define _POSIX_C_SOURCE 200809L
#endif

from c-thread-pool.

dvirsky avatar dvirsky commented on August 15, 2024

@Pithikos nope, same results.

cc: @mnunberg

from c-thread-pool.

mnunberg avatar mnunberg commented on August 15, 2024

the way these macros normally work is that they make your compiler run in a specific 'mode'. According to the POSIX standard (http://pubs.opengroup.org/onlinepubs/007904975/functions/xsh_chap02_02.html):

Additional symbols not required or explicitly permitted by IEEE Std 1003.1-2001 to be in that header shall not be made visible, except when enabled by another feature test macro.

It might be the case that you need to include an os-x specific header (maybe *mach*.h) to get the _np functionality.

from c-thread-pool.

nil0x42 avatar nil0x42 commented on August 15, 2024

Hi ! I'm having the same warning

from c-thread-pool.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.