call.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #include "rpc/call.h"
  19. #include "rpc/proxy.h"
  20. #include <stdlib.h>
  21. #include <string.h>
  22. #include <uv.h>
  23. void hrpc_call_deliver_err(struct hrpc_call *call, struct hadoop_err *err)
  24. {
  25. hrpc_raw_cb_t cb = call->cb;
  26. void *cb_data = call->cb_data;
  27. free(call->payload.base);
  28. memset(call, 0, sizeof(*call));
  29. __sync_fetch_and_or(&call->active, 0);
  30. cb(NULL, err, cb_data);
  31. }
  32. void hrpc_call_deliver_resp(struct hrpc_call *call, struct hrpc_response *resp)
  33. {
  34. hrpc_raw_cb_t cb = call->cb;
  35. void *cb_data = call->cb_data;
  36. free(call->payload.base);
  37. memset(call, 0, sizeof(*call));
  38. __sync_fetch_and_or(&call->active, 0);
  39. cb(resp, NULL, cb_data);
  40. }
  41. int hrpc_call_activate(struct hrpc_call *call)
  42. {
  43. return !!__sync_bool_compare_and_swap(&call->active, 0, 1);
  44. }
  45. void hrpc_call_deactivate(struct hrpc_call *call)
  46. {
  47. __sync_fetch_and_and(&call->active, 0);
  48. }
  49. int hrpc_call_is_active(const struct hrpc_call *call)
  50. {
  51. return !!__sync_fetch_and_or((int*)&call->active, 0);
  52. }
  53. // vim: ts=4:sw=4:tw=79:et