This repository has been archived by the owner on Aug 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from mapbox/threaded-curl
add threading for libcurl
- Loading branch information
Showing
11 changed files
with
365 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#ifndef LLMR_UTIL_THREADPOOL | ||
#define LLMR_UTIL_THREADPOOL | ||
|
||
#include <pthread.h> | ||
#include <forward_list> | ||
#include <queue> | ||
|
||
namespace llmr { | ||
namespace util { | ||
|
||
class Threadpool { | ||
private: | ||
class Worker { | ||
public: | ||
Worker(Threadpool& pool); | ||
~Worker(); | ||
static void *loop(void *ptr); | ||
|
||
private: | ||
Threadpool& pool; | ||
pthread_t thread; | ||
}; | ||
|
||
public: | ||
Threadpool(int max_workers = 4); | ||
typedef void (*Callback)(void *); | ||
void add(Callback callback, void *data); | ||
|
||
private: | ||
typedef std::pair<Callback, void *> Task; | ||
const int max_workers; | ||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; | ||
pthread_cond_t condition = PTHREAD_COND_INITIALIZER; | ||
std::forward_list<Worker> workers; | ||
int worker_count = 0; | ||
std::queue<Task> tasks; | ||
}; | ||
|
||
extern std::unique_ptr<Threadpool> threadpool; | ||
|
||
} | ||
} | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.