Loading lib/share.c +79 −98 Original line number Diff line number Diff line Loading @@ -24,142 +24,123 @@ #include "setup.h" #include <stdlib.h> #include <curl/curl.h> #include "share.h" #include "urldata.h" #include "share.h" /* The last #include file should be: */ #ifdef MALLOCDEBUG #include "memdebug.h" #endif #define CURL_SHARE_SET_LOCKED(__share, __type) ((__share)->locked += (__type)) #define CURL_SHARE_SET_UNLOCKED(__share, __type) ((__share)->locked -= (__type)) #define CURL_SHARE_SET_USED(__share, __type) ((__share)->specifier += (__type)) #define CURL_SHARE_SET_UNUSED(__share, __type) ((__share)->specifier -= (__type)) #define CURL_SHARE_IS_USED(__share, __type) ((__share)->specifier & (__type)) #define CURL_SHARE_IS_LOCKED(__share, __type) ((__share)->locked & (__type)) #define CURL_SHARE_IS_DIRTY(__share) ((__share)->dirty) #define CURL_SHARE_GET(__handle) (((struct SessionHandle *) (__handle))->share) CURLSH * curl_share_init(void) { curl_share *share = (curl_share *) malloc (sizeof (curl_share)); if (share) { memset (share, 0, sizeof (curl_share)); } struct Curl_share *share = (struct Curl_share *)malloc(sizeof(struct Curl_share)); if (share) memset (share, 0, sizeof(struct Curl_share)); return share; } CURLcode curl_share_setopt (curl_share *share, curl_lock_type option, int enable) CURLSHcode curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; } struct Curl_share *share = (struct Curl_share *)sh; va_list param; int type; curl_lock_function lockfunc; curl_unlock_function unlockfunc; void *ptr; if (enable) { CURL_SHARE_SET_USED (share, option); } else { CURL_SHARE_SET_UNUSED (share, option); } if (share->dirty) /* don't allow setting options while one or more handles are already using this share */ return CURLSHE_IN_USE; return CURLE_OK; } va_start(param, option); CURLcode curl_share_set_lock_function (curl_share *share, curl_lock_function lock) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; } switch(option) { case CURLSHOPT_SHARE: /* this is a type this share will share */ type = va_arg(param, int); share->specifier |= (1<<type); break; share->lockfunc = lock; return CURLE_OK; } case CURLSHOPT_UNSHARE: /* this is a type this share will no longer share */ type = va_arg(param, int); share->specifier &= ~(1<<type); break; CURLcode curl_share_set_unlock_function (curl_share *share, curl_unlock_function unlock) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; } case CURLSHOPT_LOCKFUNC: lockfunc = va_arg(param, curl_lock_function); share->lockfunc = lockfunc; break; share->unlockfunc = unlock; return CURLE_OK; } case CURLSHOPT_UNLOCKFUNC: unlockfunc = va_arg(param, curl_unlock_function); share->unlockfunc = unlockfunc; break; CURLcode curl_share_set_lock_data (curl_share *share, void *data) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; case CURLSHOPT_USERDATA: ptr = va_arg(param, void *); share->clientdata = ptr; break; default: return CURLSHE_BAD_OPTION; } share->clientdata = data; return CURLE_OK; return CURLSHE_OK; } Curl_share_error Curl_share_acquire_lock (CURL *handle, curl_lock_type type) CURLSHcode curl_share_cleanup(CURLSH *sh) { curl_share *share = CURL_SHARE_GET (handle); if (share == NULL) { return SHARE_ERROR_INVALID; } struct Curl_share *share = (struct Curl_share *)sh; if (share->dirty) return CURLSHE_IN_USE; if (! (share->specifier & type)) { return SHARE_ERROR_NOT_REGISTERED; } free (share); if (CURL_SHARE_IS_LOCKED (share, type)) { return SHARE_ERROR_OK; return CURLSHE_OK; } share->lockfunc (handle, type, share->clientdata); CURL_SHARE_SET_LOCKED (share, type); return SHARE_ERROR_OK; } Curl_share_error Curl_share_release_lock (CURL *handle, curl_lock_type type) CURLSHcode Curl_share_acquire_lock(struct SessionHandle *data, curl_lock_data type) { curl_share *share = CURL_SHARE_GET(handle); if (share == NULL) { return SHARE_ERROR_INVALID; } struct Curl_share *share = data->share; if (! (share->specifier & type)) { return SHARE_ERROR_NOT_REGISTERED; } if (share == NULL) return CURLSHE_INVALID; if (!CURL_SHARE_IS_LOCKED (share, type)) { return SHARE_ERROR_OK; if(share->specifier & (1<<type)) { share->lockfunc (data, type, CURL_LOCK_ACCESS_SINGLE, share->clientdata); share->locked |= (1<<type); } /* else if we don't share this, pretend successful lock */ share->unlockfunc (handle, type, share->clientdata); CURL_SHARE_SET_UNLOCKED (share, type); return SHARE_ERROR_OK; return CURLSHE_OK; } CURLcode curl_share_destroy (curl_share *share) CURLSHcode Curl_share_release_lock(struct SessionHandle *data, curl_lock_data type) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; } struct Curl_share *share = data->share; free (share); if (share == NULL) return CURLSHE_INVALID; if(share->specifier & (1<<type)) { share->unlockfunc (data, type, share->clientdata); share->locked &= ~(1<<type); } return CURLE_OK; return CURLSHE_OK; } /* * local variables: * eval: (load-file "../curl-mode.el") Loading lib/share.h +2 −9 Original line number Diff line number Diff line Loading @@ -27,13 +27,6 @@ #include "setup.h" #include <curl/curl.h> typedef enum { SHARE_ERROR_OK = 0, SHARE_ERROR_INVALID, SHARE_ERROR_NOT_REGISTERED, SHARE_ERROR_LAST } Curl_share_error; /* this struct is libcurl-private, don't export details */ struct Curl_share { unsigned int specifier; Loading @@ -45,8 +38,8 @@ struct Curl_share { void *clientdata; }; Curl_share_error Curl_share_aquire_lock (CURL *, curl_lock_data); Curl_share_error Curl_share_release_lock (CURL *, curl_lock_data); CURLSHcode Curl_share_aquire_lock (struct SessionHandle *, curl_lock_data); CURLSHcode Curl_share_release_lock (struct SessionHandle *, curl_lock_data); #endif /* __CURL_SHARE_H */ Loading Loading
lib/share.c +79 −98 Original line number Diff line number Diff line Loading @@ -24,142 +24,123 @@ #include "setup.h" #include <stdlib.h> #include <curl/curl.h> #include "share.h" #include "urldata.h" #include "share.h" /* The last #include file should be: */ #ifdef MALLOCDEBUG #include "memdebug.h" #endif #define CURL_SHARE_SET_LOCKED(__share, __type) ((__share)->locked += (__type)) #define CURL_SHARE_SET_UNLOCKED(__share, __type) ((__share)->locked -= (__type)) #define CURL_SHARE_SET_USED(__share, __type) ((__share)->specifier += (__type)) #define CURL_SHARE_SET_UNUSED(__share, __type) ((__share)->specifier -= (__type)) #define CURL_SHARE_IS_USED(__share, __type) ((__share)->specifier & (__type)) #define CURL_SHARE_IS_LOCKED(__share, __type) ((__share)->locked & (__type)) #define CURL_SHARE_IS_DIRTY(__share) ((__share)->dirty) #define CURL_SHARE_GET(__handle) (((struct SessionHandle *) (__handle))->share) CURLSH * curl_share_init(void) { curl_share *share = (curl_share *) malloc (sizeof (curl_share)); if (share) { memset (share, 0, sizeof (curl_share)); } struct Curl_share *share = (struct Curl_share *)malloc(sizeof(struct Curl_share)); if (share) memset (share, 0, sizeof(struct Curl_share)); return share; } CURLcode curl_share_setopt (curl_share *share, curl_lock_type option, int enable) CURLSHcode curl_share_setopt(CURLSH *sh, CURLSHoption option, ...) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; } struct Curl_share *share = (struct Curl_share *)sh; va_list param; int type; curl_lock_function lockfunc; curl_unlock_function unlockfunc; void *ptr; if (enable) { CURL_SHARE_SET_USED (share, option); } else { CURL_SHARE_SET_UNUSED (share, option); } if (share->dirty) /* don't allow setting options while one or more handles are already using this share */ return CURLSHE_IN_USE; return CURLE_OK; } va_start(param, option); CURLcode curl_share_set_lock_function (curl_share *share, curl_lock_function lock) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; } switch(option) { case CURLSHOPT_SHARE: /* this is a type this share will share */ type = va_arg(param, int); share->specifier |= (1<<type); break; share->lockfunc = lock; return CURLE_OK; } case CURLSHOPT_UNSHARE: /* this is a type this share will no longer share */ type = va_arg(param, int); share->specifier &= ~(1<<type); break; CURLcode curl_share_set_unlock_function (curl_share *share, curl_unlock_function unlock) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; } case CURLSHOPT_LOCKFUNC: lockfunc = va_arg(param, curl_lock_function); share->lockfunc = lockfunc; break; share->unlockfunc = unlock; return CURLE_OK; } case CURLSHOPT_UNLOCKFUNC: unlockfunc = va_arg(param, curl_unlock_function); share->unlockfunc = unlockfunc; break; CURLcode curl_share_set_lock_data (curl_share *share, void *data) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; case CURLSHOPT_USERDATA: ptr = va_arg(param, void *); share->clientdata = ptr; break; default: return CURLSHE_BAD_OPTION; } share->clientdata = data; return CURLE_OK; return CURLSHE_OK; } Curl_share_error Curl_share_acquire_lock (CURL *handle, curl_lock_type type) CURLSHcode curl_share_cleanup(CURLSH *sh) { curl_share *share = CURL_SHARE_GET (handle); if (share == NULL) { return SHARE_ERROR_INVALID; } struct Curl_share *share = (struct Curl_share *)sh; if (share->dirty) return CURLSHE_IN_USE; if (! (share->specifier & type)) { return SHARE_ERROR_NOT_REGISTERED; } free (share); if (CURL_SHARE_IS_LOCKED (share, type)) { return SHARE_ERROR_OK; return CURLSHE_OK; } share->lockfunc (handle, type, share->clientdata); CURL_SHARE_SET_LOCKED (share, type); return SHARE_ERROR_OK; } Curl_share_error Curl_share_release_lock (CURL *handle, curl_lock_type type) CURLSHcode Curl_share_acquire_lock(struct SessionHandle *data, curl_lock_data type) { curl_share *share = CURL_SHARE_GET(handle); if (share == NULL) { return SHARE_ERROR_INVALID; } struct Curl_share *share = data->share; if (! (share->specifier & type)) { return SHARE_ERROR_NOT_REGISTERED; } if (share == NULL) return CURLSHE_INVALID; if (!CURL_SHARE_IS_LOCKED (share, type)) { return SHARE_ERROR_OK; if(share->specifier & (1<<type)) { share->lockfunc (data, type, CURL_LOCK_ACCESS_SINGLE, share->clientdata); share->locked |= (1<<type); } /* else if we don't share this, pretend successful lock */ share->unlockfunc (handle, type, share->clientdata); CURL_SHARE_SET_UNLOCKED (share, type); return SHARE_ERROR_OK; return CURLSHE_OK; } CURLcode curl_share_destroy (curl_share *share) CURLSHcode Curl_share_release_lock(struct SessionHandle *data, curl_lock_data type) { if (CURL_SHARE_IS_DIRTY(share)) { return CURLE_SHARE_IN_USE; } struct Curl_share *share = data->share; free (share); if (share == NULL) return CURLSHE_INVALID; if(share->specifier & (1<<type)) { share->unlockfunc (data, type, share->clientdata); share->locked &= ~(1<<type); } return CURLE_OK; return CURLSHE_OK; } /* * local variables: * eval: (load-file "../curl-mode.el") Loading
lib/share.h +2 −9 Original line number Diff line number Diff line Loading @@ -27,13 +27,6 @@ #include "setup.h" #include <curl/curl.h> typedef enum { SHARE_ERROR_OK = 0, SHARE_ERROR_INVALID, SHARE_ERROR_NOT_REGISTERED, SHARE_ERROR_LAST } Curl_share_error; /* this struct is libcurl-private, don't export details */ struct Curl_share { unsigned int specifier; Loading @@ -45,8 +38,8 @@ struct Curl_share { void *clientdata; }; Curl_share_error Curl_share_aquire_lock (CURL *, curl_lock_data); Curl_share_error Curl_share_release_lock (CURL *, curl_lock_data); CURLSHcode Curl_share_aquire_lock (struct SessionHandle *, curl_lock_data); CURLSHcode Curl_share_release_lock (struct SessionHandle *, curl_lock_data); #endif /* __CURL_SHARE_H */ Loading